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

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 acme.sh and then reconnect to ssh

wget -O - https://get.acme.sh | sh
exit

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

mkdir /etc/letsencrypt/live/

Step 3. Register acme account and upgrade

acme.sh --upgrade
acme.sh --register-account -m stefan@pcx3.com

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/.acme.sh/acme.sh --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

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

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

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

#2 Change VirtualHost file

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

add the path to the fullchain and privkey files:

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

#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: https://mydomain.com

whoami
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.