How To Secure Apache with Let's Encrypt on Ubuntu 14.04

How To Secure Apache with Let's Encrypt on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04


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.

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.


In order to complete this guide, you will need:

When you are ready to move on, log into your server using your sudo-enabled account.

##Step 1 — Download the Let’s Encrypt Client

The first step to using Let’s Encrypt to obtain an SSL certificate is to install the certbot software on your server. The Certbot developers maintain their own Ubuntu software repository with up-to-date versions of the software. Because Certbot is in such active development it’s worth using this repository to install a newer Certbot than provided by Ubuntu.

First, add the repository:

  1. sudo add-apt-repository ppa:certbot/certbot

You’ll need to press ENTER to accept. Afterwards, update the package list to pick up the new repository’s package information:

  1. sudo apt-get update

And finally, install Certbot from the new repository with apt-get:

  1. sudo apt-get install python-certbot-apache

The certbot Let’s Encrypt client is now ready to use.

##Step 2 — Set Up the SSL Certificate

Generating the SSL Certificate for Apache using the certbot 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.

To execute the interactive installation and obtain a certificate that covers only a single domain, run the certbot command with:

  1. sudo certbot --apache -d example.com

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 the base 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:

  1. sudo certbot --apache -d example.com -d www.example.com

For this example, the base domain will be example.com.

You will be prompted to provide an email address for lost key recovery and notices, and you will be need to agree to the Let’s Encrypt terms of service. You’ll then be asked to choose between enabling both http and https access or force all requests to redirect to https.

When the installation is finished, you should be able to find the generated certificate files at /etc/letsencrypt/live. You can verify the status of your SSL certificate with the following link (don’t forget to replace example.com with your base domain):


You should now be able to access your website using a https prefix.

Step 3 — Verifying Certbot Auto-Renewal

Let’s Encrypt certificates only last for 90 days. However, the certbot package we installed takes care of this for us by running certbot renew twice a day via a systemd timer. On non-systemd distributions this functionality is provided by a cron script placed in /etc/cron.d. The task runs twice daily and will renew any certificate that’s within thirty days of expiration.

To test the renewal process, you can do a dry run with certbot:

  1. sudo certbot renew --dry-run

If you see no errors, you’re all set. When necessary, Certbot will renew your certificates and reload Apache to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.


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. We recommend that you check the official Let’s Encrypt blog for important updates from time to time, and read the Certbot documentation for more details about the Certbot client.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Thanks for the tutorial. Very helpful.

Seems the default version of python supplied with Ubuntu 14.04 may need some extra updates to run letsencrypt. I needed to update python’s ssl libraries:

apt-get install python-dev libffi-dev libssl-dev
apt-get install python-pip
pip install 'requests[security]'
pip install pyopenssl ndg-httpsclient pyasn1

Then I needed to import ssl into python.

import ssl

Also, I found my domain name example.com must have an A record on the DNS server and it must be the same IP address as the A record for www.example.com A CNAME DNS record for www.example.com is not sufficient – it must be an A record.


"I tried following these instructions but seem to get an error that says


  • The following ‘urn:acme:error:connection’ errors were reported by the server:

    Domains: mydomain.com Error: The server could not connect to the client to verify the domain"

I had to unblock port 443 in ufw

Thanks for the tutorial.

hi, although i haven’t find time to try it, thanks for this great tutorial. one think I should like to ask is that whether it is possible to add more subdomains later or not.

for example, I begin with example.com and www.example.com and then after a while I want to add newsubdomain.example.com.

Is it possible?


Is it possible to modify the let’s encrypt script to cover all name virtual host you might have on a Apache instance? I host about 10 sites on one moderate sized server.

le-renew script depends on bc (not installed on Debian 8.2 Jessie). You need to apt-get install bc before running the script. Otherwise it seems to renew the certificate even if it’s not expired.

Thanks for the article. Although the script will generate an error if you have multiple vhosts, it does generate the certificate even though it does not update the apache configuration. This is easily fixed by manually adding the statements to the vhost file for each site and restarting apache.

Hi @erikaheidi, thanks for this article and renewal script! I recently made a blog post describing how to set it up with nginx, in this post I’ve added a link to this post, and a link to an edited le-renew script which I’ve made to run with nginx, based on the script you provide in this post. I hope you don’t mind :)

The blog post can be read here

Prakash Jha
DigitalOcean Employee
DigitalOcean Employee badge
April 5, 2019


enable ssl port if disabled:

$ sudo ufw allow https

I’ve done this and it all seemed to work. When using the testing site I’m getting “A” for all but when I go to the site I’m getting “This page isn’t working redirected you too many times.” which suggests an issue with the forcing http to http. When I clicked 1 to redirect, where was changed to cause that to happen as I want to undo that but can’t find it.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel