How to install HTTPS on Ubuntu server for free
HTTPS is the secure version of HTTP. While HTTP transmits data in plaintext, HTTPS adds a secure layer that guarantees data privacy in case of interception by malicious actors. This tutorial teaches you how to install HTTPS on your site on the Ubuntu server for free.
Why install an HTTPS certificate on your website
Modern web browsers, such as Google Chrome, mark websites without an HTTPS certificate as insecure. This damages your online presence and may raise suspicious thoughts on the visitor’s side.
The key reason you should install an HTTPS certificate on your WordPress site is data integrity. Any user should be able to communicate through a secure channel with your website, particularly if you store their confidential credentials such as usernames, email addresses, and passwords.
With an HTTPS certificate on your website, you can avoid data interception in case of man-in-the-middle attacks.
Free HTTPS certificate for your website
Let’s Encrypt is a nonprofit Certificate Authority provider that offers free HTTPS certificates to the public. Although there are many paid options, Let’s Encrypt counts more than 500 million websites using their HTTPS certificates.
Major sponsors and funders of Let’s Encrypt include Google Chrome, AWS, Mozilla, Cisco, IBM, Shopify, and many others.
Prerequisites
To install the Let’s Encrypt HTTPS certificate on your website you need shell access and sudo privileges on the Ubuntu server.
How to install HTTPS on your website on Ubuntu server for free
This tutorial uses the Certbot agent to download, install, and renew the HTTPS certificate for your website on the Ubuntu server. Certbot automatically retrieves and installs the HTTPS certificate from Let’s Encrypt.
Step 1: Install system dependencies
There are many ways to install and run Certbot on the Ubuntu server. This tutorial installs and runs Certbot using a Python virtual environment. Another required package is Auegas for the Apache plugin.
Update your Ubuntu server:
sudo apt update
To install Python 3, venv, pip, and Auegas on Ubuntu type:
sudo apt install python3 python3-venv python3-pip libaugeas0
Step 2: Setup a virtual environment in Python
To create the Python virtual environment for Certbot on your Ubuntu server type:
sudo python3 -m venv /opt/certbot
The /opt is a Linux directory intended for the installation of additional software packages. Feel free to use any path you want for the Python virtual environment.
To activate the Python virtual environment you created for Certbot type:
sudo source /opt/certbot/bin/activate
The result of the above command is shown below. The (certbot) on the left shows that the Python virtual environment is currently running. Every package you install now is installed inside the virtual environment.
Step 3: Install the Certbot agent on your Ubuntu server
Now that you have a Python virtual environment you can install the Certbot agent. To install the Certbot agent on your Ubuntu server with the help of the Python virtual environment type:
sudo pip install certbot certbot-apache
To verify the presence of the Certbot binary inside the virtual environment type:
ls /opt/certbot/bin
As you can see below the Certbot binary is present in the Python virtual environment binaries subdirectory.
Step 4: Put Certbot on your global PATH
In case you want to use Certbot without activating the virtual environment you can create a symbolic link to its binary that is present inside the /opt/certbot/bin/ subdirectory.
To be able to use Certbot directly from the console type:
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
Step 5: Install Let’s Encrypt HTTPS certificate with Certbot on your Ubuntu server
To install the Let’s Encrypt HTTPS certificate with Certbot while inside your Python virtual environment type:
sudo certbot --apache
Once the above command is executed Certbot asks for your permission and also for an email to register an account.
Type Y and hit Enter.
Later you have to specify the domain/s on which you want to install the HTTPS certificate. Specify the domain or domains separated by a comma and hit Enter.
On success, you should get a message that the HTTPS certificate was successfully installed on your website. Visit your website to verify it.
Step 6: Setup automatic HTTPS renewal with Certbot
Certbot can automatically renew the HTTPS certificate once it expires. A cron job should be created for that.
To do so type:
echo "0 1 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
To verify the presence of the cron job type:
cat /etc/crontab
The cron job you just added runs at 1 AM every day of each month and executes the automatic renewal of the HTTPS certificate through the Certbot agent.
Final thoughts
Through this tutorial, you learned how to install HTTPS to your website on Ubuntu for free. You also learned how to create a cron job to update your website’s HTTPS certificate.