How to Install Let’s Encrypt on Ubuntu 16.04/18.04 with Apache2

Introduction

Securing your website with SSL is essential for data protection, trust, and SEO ranking. Let’s Encrypt provides a free, automated, and open Certificate Authority (CA) that allows you to install and configure SSL certificates easily.

In this guide, we’ll walk you through setting up Let’s Encrypt SSL on Ubuntu 16.04/18.04 with Apache2 step by step.

Prerequisites

Before you begin, make sure you have:

  • A server running Ubuntu 16.04 or Ubuntu 18.04.
  • A registered domain name pointing to your server’s public IP.
  • Apache2 installed and running:
  • Sudo/root privileges on the server

Steps to Install Let’s Encrypt on Ubuntu 16.04/18.04 with Apache2

Step 1: Update the system

Log in to your Ubuntu 16.04/18.04 Server via SSH as user root

ssh root@IP_Address -p Port_Number

Make sure that your system is fully up to date.

apt-get update && apt-get upgrade

Step 2: Install Certbot client

Certbot is a free, open-source ACME client that automates obtaining, installing, and renewing SSL/TLS certificates from Let’s Encrypt, making it easy to enable HTTPS on your server.

Run the following command to add the Certbot repository.

sudo add-apt-repository ppa:certbot/certbot

Accept the installation, update the package list, and install Certbot for apache.

apt-get update
apt-get install python-certbot-apache

At this step, Certbot is installed, and you are ready to obtain your free Let’s Encrypt SSL certificate.

Step 3: Obtain a Let’s Encrypt Certificate

Let’s Encrypt certificates can be installed using different Certbot plugins. In this guide, we’ll use the Nginx plugin, which automatically handles configuration updates and reloads Nginx for you.

Run the following command and replace ‘domain.com’ with your actual domain name.

certbot --apache -d domain.com -d www.domain.com

When you generate a certificate for the first time, you will be asked to enter your email address and agree to Certbot’s terms of service.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

If you want all your website visitors to be redirected to HTTP, which is the recommended option, select number 2 and hit the ‘Enter’ key.

If the Let’s Encrypt SSL certificate is successfully installed, you will get the following output.

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/domain.com/fullchain.pem. Your cert will
expire on 2017-10-23. To obtain a new or tweaked version of this
certificate in the future, simply run certbot again with the
"certonly" option. To non-interactively renew *all* of your
certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

Step 4: Verify SSL Installation

Now you should have successfully installed and configured the Let’s Encrypt SSL certificate on your ‘domain.com’ domain name. You can check this by visiting https://domain.com.

Let’s Encrypt SSL certificates are valid for 90 days, and we will configure them to be automatically renewed by creating a cron job. Let’s Encrypt recommends the automatic renewal cron job to run twice a day. So, edit the crontab.

crontab -e

and add the following line.

* */12 * * * /usr/bin/certbot renew >/dev/null 2>&1
Outline