Securing Apache with an SSL certificate from Let's Encrypt

Let's Encrypt issues free SSL certificates. By using certbot, you can automate the entire process of issuing and renewing certificates.


In this guide, we'll demonstrate how to set up Let's Encrypt with Apache in Debian 13 and Ubuntu 24.04.

Prerequisite

Before issuing an SSL certificate, you need to have set up a basic virtual host for your domain in Apache. Such a virtual host file can look like this:

/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/example.com

        <Directory /var/www/example.com>
            Options Indexes FollowSymLinks
            AllowOverride AuthConfig
            Require all granted
        </Directory>
</VirtualHost>

The virtual host also needs to be enabled if it hasn't been so already:

Command
sudo a2ensite example.com

Setting up an SSL certificate

Generating an SSL certificate for Apache with Certbot is straightforward. The client automatically retrieves and installs new certificates that are valid for the domains specified as parameters.

Certbot also creates a new virtual host that listens on HTTPS (port 443) for the domain. And as a final piece of the puzzle, Certbot also sets up a cron job to renew the certificate before it expires.

Let's start by installing Certbot:

Next, you can issue a certificate for the domain in the virtual host using certbot. Make sure to include the --apache option, as this creates all the necessary configurations for Apache, including redirection from HTTP to HTTPS.

Enter all domains and subdomains that you wish to be included in the certificate using the -d option. Enter the main certificate first, as the certificate files will be named after this. Once you execute the command, you'll be prompted to enter your email address and to accept Let's Encrypt's terms of service.

It will look similar to this:

Everything is now set up for you. Verify that the site is working by visiting both its http:// and https:// URL. Any requests to http:// will be redirected to the https:// URL, and is secured by the new Let's Encrypt SSL certificate.

Last updated

Was this helpful?