Live Chat Software by NetForChoice
How To Secure Apache with Let's Encrypt on Ubuntu 14.04
Posted by Helpdesk System on 18 March 2016 07:16 PM
This tutorial will show you how to set up a TLS/SSL certificate from Let’s Encrypt on an Ubuntu 14.04 server running Apache as a web server. We will also cover how to automate the certificate renewal process using a cron job.
SSL certificates are used within web servers to encrypt the traffic between the server and client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.
Step 1 — Install the Server Dependencies
The first thing we need to do is to update the package manager cache with:
We will need
Step 2 — Download the Let’s Encrypt Client
Next, we will download the Let’s Encrypt client from its official repository, placing its files in a special location on the server. We will do this to facilitate the process of updating the repository files when a new release is available. Because the Let’s Encrypt client is still in beta, frequent updates might be necessary to correct bugs and implement new functionality.
We will clone the Let’s Encrypt repository under
This will create a local copy of the official Let’s Encrypt repository under
Step 3 — Set Up the SSL Certificate
Generating the SSL Certificate for Apache using the Let’s Encrypt client is quite straightforward. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.
Access the letsencrypt directory:
To execute the interactive installation and obtain a certificate that covers only a single domain, run the
If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be thebase domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases:
For this example, the base domain will be
After the dependencies are installed, you will be presented with a step-by-step guide to customize your certificate options. You will be asked to provide an email address for lost key recovery and notices, and you will be able to choose between enabling both
When the installation is finished, you should be able to find the generated certificate files at
You should now be able to access your website using a
Step 4 — Set Up Auto Renewal
Let’s Encrypt certificates are valid for 90 days, but it’s recommended that you renew the certificates every 60 days to allow a margin of error. At the time of this writing, automatic renewal is still not available as a feature of the client itself, but you can manually renew your certificates by running the Let’s Encrypt client again with the same parameters previously used.
To manually renew a Let’s Encrypt certificate for Apache with no interaction in the command line, you can run:
If you provided multiple domain names when first installing the certificate, you’ll need to pass the same list of domains again for the renewal command, otherwise the Let’s Encrypt client will generate a new certificate instead of renewing the existing one.
A practical way to ensure your certificates won’t get outdated is to create a cron job that will automatically handle the renewal requests for you.
To facilitate this process, we will use a shell script that will verify the certificate expiration date for the provided domain and request a renewal when the expiration is less than 30 days away. The script will be scheduled to run once a week. This way, even if a cron job fails, there’s a 30-day window to try again every week.
First, download the script and make it executable. Feel free to review the contents of the script before downloading it.
You can run the script manually with:
Since we just created the certificate and there is no need for renewal just yet, the script will simply output how many days are left until the certificate expiration:
Next, we will edit the crontab to create a new job that will run this command every week. To edit the crontab for the root user, run:
Include the following content, all in one line:
Save and exit. This will create a new cron job that will execute the
For more information on how to create and schedule cron jobs, you can check our How to Use Cron to Automate Tasks in a VPS guide.
Step 5 — Updating the Let’s Encrypt Client (optional)
Whenever new updates are available for the client, you can update your local copy by running a
This will download all recent changes to the repository, updating your client.
In this guide, we saw how to install a free SSL certificate from Let’s Encrypt in order to secure a website hosted with Apache. Because the Let’s Encrypt client is still in beta, we recommend that you check the official Let’s Encrypt blog for important updates from time to time.