How to generate SSL and enable HTTPS protocol with Apache 2 on Ubuntu 21

In this article We will generate SSL and then enable HTTPS on Apache with Ubuntu 20.04.

#1 Generate SSL Certificate

Step 1. Install and then reconnect to ssh

wget -O - | sh

Step 2. Create a folder where SSL files will be stored

mkdir /etc/letsencrypt/live/

Step 3. Register acme account and upgrade --upgrade --register-account -m [email protected]

Step 4. Run the following command to generate SSL, but make sure to change the following first:

DOMAINyour domain name
/var/www/html/public/path to your website directory
/root/ --issue -d DOMAIN -d www.DOMAIN --cert-file /etc/letsencrypt/live/DOMAIN/cert.pem --key-file /etc/letsencrypt/live/DOMAIN/privkey.pem --fullchain-file /etc/letsencrypt/live/DOMAIN/fullchain.pem -w /var/www/html/public/ --force --debug

The SSL will be output to the screen

and stored in the specified location: /etc/letsencrypt/live/DOMAIN/

#2 Change VirtualHost file

nano /etc/apache2/sites-available/default-ssl.conf

add the path to the fullchain and privkey files:

#3 Configure Apache modules

Enable the mod_ssl and mod_headers modules, then check for syntax errors in Apache configuration files and finally restart Apache.

a2enmod ssl
a2enmod headers
a2ensite default-ssl
apache2ctl configtest
service apache2 restart

That’s it, now check the secure connection:

Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.