Sunday, November 22, 2026
TR
LinuxOpen Source

Securing Apache with Let's Encrypt on Ubuntu 18.04

Securing Apache with Let's Encrypt on Ubuntu 18.04
Contents
  1. Prerequisites
  2. Step 1 – Download the Let’s Encrypt Client
  3. Step 2 – Set Up the SSL Certificate
  4. Step 3 – Verify Certbot Auto-Renewal
  5. Conclusion

This tutorial will show you how to set up a TLS / SSL certificate from Let’s Encrypt on an Ubuntu 14.04 server running Apache as a web server.

SSL certificates are used on web servers to encrypt traffic between the server and the client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.

Prerequisites

To complete this guide, you will need:

When you are ready to continue, log in to your server using your sudo-enabled account.

Step 1 – Download the Let’s Encrypt Client

The first step to using Let’s Encrypt to obtain an SSL certificate is to install the certbotsoftware on your server. The Certbot developers maintain their own Ubuntu software repository with up-to-date versions of the software. Because Certbot is under such active development, it is worth using this repository to install a newer Certbot than the one provided by Ubuntu.

First, add the repository:

sudo add-apt-repository ppa:certbot/certbot

You will need to press ENTERto accept. Then, update the package list to pick up the new repository's package information:

sudo apt-get update

And finally, install Certbot from the new repository with apt-get:

sudo apt-get install python-certbot-apache

The certbotLet’s Encrypt client is now ready to use.

Step 2 – Set Up the SSL Certificate

Generating an SSL certificate for Apache using the certbotLet’s Encrypt client is quite simple. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

To execute the interactive installation and obtain a certificate that covers only a single domain, run the certbotcommand like this:

sudo certbot --apache -d example.com

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the parameter list will be the base domain used by Let’s Encrypt to create the certificate, so we recommend that you pass the bare top-level domain name first in the list, followed by any additional subdomains or aliases:

sudo certbot --apache -d example.com -d www.example.com

For this example, the base domain will be example.com.

You will be asked to provide an email address for lost key recovery and notifications, and you will need to agree to the Let’s Encrypt terms of service. Next, you will be asked to choose between enabling both httpand httpsaccess or forcing all requests to redirect to https.

When the installation is complete, you should be able to find the generated certificate files at /etc/letsencrypt/live. You can verify the status of your SSL certificate with the following link (don't forget to replace example.com with your base domain):

https://www.ssllabs.com/ssltest/analyze.html?d=example.com&latest

You should now be able to access your website using the httpsprefix.

Step 3 – Verify Certbot Auto-Renewal

Let’s Encrypt certificates are only valid for 90 days. However, the certbot package we installed takes care of this for us by running certbot renewtwice a day via a systemd timer. On non-systemd distributions, this functionality is provided by a cron script placed in /etc/cron.d. The task runs twice a day and renews any certificate that is within thirty days of expiration.

To test the renewal process, you can do a dry run with certbot:

sudo certbot renew --dry-run

If you see no errors, you are all set. When necessary, Certbot will renew your certificates and reload Apache to pick up the changes. If the automatic renewal process fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.

Conclusion

In this guide, we saw how to install a free SSL certificate from Let’s Encrypt to secure a website hosted with Apache. We recommend that you check the official Let’s Encrypt blog from time to time for important updates, and read the Certbot documentation for more details about the Certbot client.

Kerim Koç

Systems and infrastructure engineer. I write about Linux, open source, high availability and security.