Tutorial

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

Published on April 21, 2016

Developer Advocate

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

Introduction

This tutorial will show you how to set up a TLS/SSL certificate from Let’s Encrypt on an Ubuntu 16.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.

Prerequisites

In order to complete this guide, you will need:

  • An Ubuntu 16.04 server with a non-root sudo-enabled user, which you can set up by following our Initial Server Setup guide
  • The Apache web server installed with one or more domain names properly configured through Virtual Hosts that specify ServerName.

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

Step 1 — Install the Let’s Encrypt Client

Let’s Encrypt certificates are fetched via client software running on your server. The official client is called Certbot, and its developers maintain their own Ubuntu software repository with up-to-date versions. Because Certbot is in such active development it’s worth using this repository to install a newer version than Ubuntu provides by default.

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 Certbot 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 like so, where example.com is your domain:

  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.

If you have multiple virtual hosts, you should run certbot once for each to generate a new certificate for each. You can distribute multiple domains and subdomains across your virtual hosts in any way.

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 http and https access or forcing all requests to redirect to https. It is usually safest to require https, unless you have a specific need for unencrypted http traffic.

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):

https://www.ssllabs.com/ssltest/analyze.html?d=example.com&latest

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.

Conclusion

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.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
50 Comments
Leave a comment...

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!

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

Unfortunately, it doesn’t seem to work like this.

I did it on mine as follows:

./letsencrypt-auto --apache -d example.com -d www.example.com -d foo.example.com -d bar.example.com -d baz.example.com

And when I test my server by going to ssllabs.com/ssltest/analyze.html?d=example.com, it says

Subject baz.example.com

Common names baz.example.com

Alternative names bar.example.com example.com foo.example.com www.example.com

It seems like it took the last parameter given, and is displaying the alternative names in alphabetical order, although with my sample size of one I can’t say that for certain.

But other than that (and it really doesn’t matter all that much, anyway – all the domains are encrypted just fine), I was really impressed with the whole process. Both with how easy Let’s Encrypt is to use, and with the succinctness of this tutorial. It gets an A on SSL Labs, and I was only able to get to a B using other SSL providers, and that after a hell of a lot of work.

Thanks a heap for providing this.

I get the following error on a fresh installed ubuntu 16.04 server:

Checking for new version...
Creating virtual environment...
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /home/christian/.loc...ncrypt/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 1

Any suggestions on that? Thanks.

The same here…

Hi there… try this in your server export LC_ALL=“en_US.UTF-8” export LC_CTYPE=“en_US.UTF-8”

at least it work for me this that problem :)

Hi,

After I enter this step:

./letsencrypt-auto --apache -d example.com -d www.example.com

I get this error:

Requesting root privileges to run letsencrypt...
   /root/.local/share/letsencrypt/bin/letsencrypt --apache -d example.com -d www.example.com
The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError()

Note - I was literally testing this out, and used the example.com domain.

Any idea what the issue might be?

Thank you for a great post!

Any chance you are using ServerPilot? I am, and I got the same error you did. I ended up following this tutorial instead, and it worked perfectly:

https://bjoernfranzen.com/how-to-set-up-a-letsencrypt-ssl-certificate-for-your-wordpress-website-on-a-digital-ocean-server-managed-with-a-serverpilot-free-account/

In the Let’s Encrypt tutorial for nginx, there was a section on adding the Diffie-Hellman Group cert as well, resulting in a A+ grading from ssllabs. How would one go about doing the same with the apache server? (This, as well as the tutorials for older versions of Ubuntu skip this section)

I believe you need to enable HSTS response headers to get an A+ rating from SSL Labs.

Please, for the sake of the letsencrypt servers, don’t just copy the crontab config from this article, but rather put in some other arbitrary numbers (another weekday & time)! Otherwise thousands of clients will renew exactly at the same time every Monday at 2:30 am, which will potentially DDoS the servers.

This should be put in the article itself as a heads up!

Came to to make sure someone mentioned this. Please pick a random time and day, it doesn’t matter when, but I suspect the Let’s Encrypt server admins dread 2:30AM on Mondays by this point.

HI, thanks for the tutorial. i’m not sure why the https://www domain got 403 forbidden error You don’t have permission to access / on this server. , the rest is perfect. so i can access https://domain.com , but again the problem 403 shows in https://www.domain.com

thanks

Guys, solved the problem by adding the conf file @ etc/apache2/sites-available/000-default-le-ssl.conf

i added this both ServerName domain.com ServerAlias www.domain.com

cheers

does this work also for ubuntu 32bit 14.04 ?

just a heads up that this generates an additional config file for your virtual host, with -le-ssl.conf appended on the end. I didn’t realise and spent ages editing my virtualhosts config file to allow htaccess override and it wasn’t working. I was editing:

/etc/apache2/sites-enabled/website.com.conf

when i should’ve edited:

/etc/apache2/sites-enabled/website.com-le-ssl.conf

Hopefully that’ll save someone else a headache!

I was wondering how you’d go about adding another domain to the base domain so that a single certificate is valid for multiple domains. I set up a base domain already, but wasn’t sure exactly how I’d go about adding additional domains in the future. If the base domain I already created and added is myfirstdomain.com (I also added www.myfirstdomain.com when setting this up), is the following command correct? Not sure if I need to just basically add all domains all over again.

./letsencrypt-auto --apache -d myfirstdomain.com -d www.myfirstdomain.com -d seconddomain.com -d www.seconddomain.com

Thanks!

I am getting an error message. Kindly help Creating virtual environment… Traceback (most recent call last): File “/usr/lib/python3/dist-packages/virtualenv.py”, line 2363, in <module> main() File “/usr/lib/python3/dist-packages/virtualenv.py”, line 719, in main symlink=options.symlink) File “/usr/lib/python3/dist-packages/virtualenv.py”, line 988, in create_environment download=download, File “/usr/lib/python3/dist-packages/virtualenv.py”, line 918, in install_wheel call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT) File “/usr/lib/python3/dist-packages/virtualenv.py”, line 812, in call_subprocess % (cmd_desc, proc.returncode)) OSError: Command /root/.local/share/letsencrypt/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 1 root@misg:/opt/letsencrypt# cd root@misg:~# cd /etc/letsencrypt/live -bash: cd: /etc/letsencrypt/live: No such file or directory

i am getting this error ```Creating virtual environment… Traceback (most recent call last): File “/usr/lib/python3/dist-packages/virtualenv.py”, line 2363, in <module> main() File “/usr/lib/python3/dist-packages/virtualenv.py”, line 719, in main symlink=options.symlink) File “/usr/lib/python3/dist-packages/virtualenv.py”, line 988, in create_environment download=download, File “/usr/lib/python3/dist-packages/virtualenv.py”, line 918, in install_wheel call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT) File “/usr/lib/python3/dist-packages/virtualenv.py”, line 812, in call_subprocess % (cmd_desc, proc.returncode)) OSError: Command /root/.local/share/letsencrypt/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 1

I had the same problem and I solved this by doing the following:

~ # apt-get install python-pip ~ # pip install setuptools Traceback (most recent call last): File “/usr/bin/pip”, line 11, in <module> sys.exit(main()) File “/usr/lib/python2.7/dist-packages/pip/init.py”, line 215, in main locale.setlocale(locale.LC_ALL, ‘’) File “/usr/lib/python2.7/locale.py”, line 581, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting

… then …

~ # export LC_ALL=“en_US.UTF-8” -bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or directory

~ # export LC_CTYPE=“en_US.UTF-8” ~ # pip install setuptools Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.7/dist-packages You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the ‘pip install --upgrade pip’ command.

… then …

~ # pip install --upgrade setuptools Collecting setuptools Downloading setuptools-29.0.1-py2.py3-none-any.whl (472kB) 100% |████████████████████████████████| 481kB 3.0MB/s Installing collected packages: setuptools Found existing installation: setuptools 20.7.0 Not uninstalling setuptools at /usr/lib/python2.7/dist-packages, outside environment /usr Successfully installed setuptools-29.0.1 You are using pip version 8.1.1, however version 9.0.1 is available. You should consider upgrading via the ‘pip install --upgrade pip’ command. now it works. So I assume “setuptools” in Ubuntu 16.04 LTS are just too old.

And all that worked for me!

Thanks for the great article! I have a Ubuntu 12.04 server, and these instructions mostly worked for it. I found that I first had to stop the Apache server, then edit /etc/letsencrypt/options-ssl-apache.conf to comment out the “SSLCompression” line therein. Hope this helps someone.

I get the error :

Failed authorization procedure. MYDOMAIN.com (tls-sni-01): urn:acme:error:connection :: The server could not connect to the client to verify the domain :: Failed to connect to MY_IP:443 for TLS-SNI-01 challenge

IMPORTANT NOTES:

  • The following errors were reported by the server:

    Domain: MYDOMAIN.com Type: connection Detail: Failed to connect to MY_IP:443 for TLS-SNI-01 challenge

    To fix these errors, please make sure that your domain name was entered correctly and the DNS A record(s) for that domain contain(s) the right IP address. Additionally, please check that your computer has a publicly routable IP address and that no firewalls are preventing the server from communicating with the client. If you’re using the webroot plugin, you should also verify that you are serving files from the webroot path you provided.

I had this problem and resolved it. The connexion was stopped by the UFW firewall :

Make a $ sudo ufw status

My UFW config was :

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere
123/tcp                    ALLOW       Anywhere
80/tcp (v6)                ALLOW       Anywhere (v6)
123/tcp (v6)               ALLOW       Anywhere (v6)

So I resolved it by enlarging the HTTP ports allowed :

$ sudo ufw delete allow '80/tcp'
$ sudo ufw allow 'Apache Full'

Now :

To                         Action      From
--                         ------      ----
123/tcp                    ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
123/tcp (v6)               ALLOW       Anywhere (v6)
Apache Full (v6)           ALLOW       Anywhere (v6)

WARNING do not do this TUTO after the other one about SSL, to create a Self-Signed SSL certificate: https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04

I didi it and it completely broke my Apache config, I had crazy infinite redirect loops, and impossible to understand what was going on.

So I had to reinstall completely my droplet with a snapshot (happy to have done one before SSL tuto).

Whenever I try to run the command “./letsencrypt-auto --apache -d mydomain.com” I get this error.

The following errors were reported by the server:

   Domain: joelarce.com
   Type:   connection
   Detail: Failed to connect to 73.164.1.67:443 for TLS-SNI-01
   challenge

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address. Additionally, please check that
   your computer has a publicly routable IP address and that no
   firewalls are preventing the server from communicating with the
   client. If you're using the webroot plugin, you should also verify
   that you are serving files from the webroot path you provided.```

Firewall issue ? See just above my answer to previous problem on connection.

Nop thats not my problem. I did try the link you suggested and I actually did it with no issues except that I cannot access my owncloud which is why I am trying to do all this. It acts as is loading but then it just stops.

Same here. have you found a solution? ---- update— Found the solution, you just have to add your domain in config.php

I had a working web app but after following this tutorial I get “Index of /” (which has my project files) when I use https. and when I use plain HTTP I get a blank “Index of /”

Same here. Nathan, did you manage to figure it out? Mind sharing?

@nathanjseeley or @jakewashere having the same problem. did you fix it? I’m hoping the original files will pop it in an hour or two, as it’s been only 10 minutes since this setup.

Hello,

It’s a great tutorial. Thanks a lot. I have a problem that, after I use the following command:

./letsencrypt-auto --apache -d example.com -d www.example.com

and choose “forcing all requests to redirect to https”,

when i input the “example.com” in the browser, it redirect to HTTPS form like “https://example.com” and works fine. but when I input the “www.example.com” in the browser, it still using the HTTP form “http://www.example.com”, instead of HTTPS form, and I can access “http://www.example.com” successfully.

Could you please help? Thanks in advance.

Tutorial works perfectly on Debian Jessie 8.5.

Thank you!

I followed this guide a few months back and everything is working correctly. However, I’m unable to update the Let’s Encrypt client using the command sudo git pull. Here is the output from my SSH session when running the command.

johners@JohnersBlogIPV6:/opt/letsencrypt$ sudo git pull
remote: Counting objects: 597, done.
remote: Compressing objects: 100% (98/98), done.
remote: Total 597 (delta 423), reused 358 (delta 358), pack-reused 141
Receiving objects: 100% (597/597), 218.72 KiB | 0 bytes/s, done.
Resolving deltas: 100% (453/453), completed with 126 local objects.
From https://github.com/letsencrypt/letsencrypt
   d05f53b..f544b03  master     -> origin/master
 * [new branch]      2558-test-fix -> origin/2558-test-fix
 * [new branch]      all-together-now -> origin/all-together-now
 * [new branch]      dedupe     -> origin/dedupe
 * [new branch]      doc-plugins-anchor -> origin/doc-plugins-anchor
   65605f7..44cf404  documentation_cleanup -> origin/documentation_cleanup
 * [new branch]      issue_2558 -> origin/issue_2558
 * [new branch]      issue_3282 -> origin/issue_3282
   e4f963d..5bf9b3a  multiple_vhosts -> origin/multiple_vhosts
 * [new branch]      nginx-space-preservation2 -> origin/nginx-space-preservation2
 * [new branch]      revert-3268-dialog-autosize -> origin/revert-3268-dialog-autosize
Updating 45e47f6..f544b03
error: Your local changes to the following files would be overwritten by merge:
        letsencrypt-auto
Please, commit your changes or stash them before you can merge.
Aborting

Any idea on what I should do to get my client to update without it losing my configuration (if that even happens)?

When I head to my domain name it won’t let me prepend www to my https:// URI. Netflix is https://www.netflix.com, where mine is still https://example.com rather than https://www.example.com.

In my VirtualHost I have the ServerName as www.example.com & ServerAlias as example.com. I’ve added certificates to both www.example.com & example.com. with the delimiter being -d. What could the issue be?(I’m using my actual domain name not example.com …). Thanks for any help in advance!

you need to redirect the domain in your virtual host to your https

<VirtualHost *:80>
    ServerName example.com
    Redirect / https://example.com/
</VirtualHost>

couldnt you just do:

<VirtualHost *:443> ServerName example.com </VirtualHost>

?

source: https://wiki.apache.org/httpd/ExampleVhosts

After running into renewal errors I’ve been advised that sudo apt-get install python-letsencrypt-apache is outdated and that I should update to certbot. See this nginx-specific post

The short summary of what I did is:

sudo apt-get purge --auto-remove letsencrypt

sudo apt update
sudo apt install git

sudo git clone https://github.com/certbot/certbot /opt/certbot
sudo ln -s /opt/certbot/certbot-auto /usr/bin/certbot

sudo certbot certonly -d example.com -d www.example.com

NB: my apache sites were already configured to look in /etc/letsencrypt/live/example/fullchain.pem

But I had to remove the line from my /etc/apache2/sites-available/default-ssl.conf

Include /etc/letsencrypt/options-ssl-apache.conf

since that not longer exists, and trying to include it prevents apache from starting.

I’m still working on automating the renewal process as that seems to fail if apache is running… which is normally should be if the droplet is serving the site.

How can I use this with CloudFlare? Currently I have to have my site on ‘Pause’ in order for the certificate to show.

How do you add another domain to the certificate after you have allredy set it up? How do you delete cirtificate?

Worked perfectly for me!

Thanks.

First paragraph says “… on an Ubuntu 14.04 server …” I think it’s a typo and should be 16.04

Im trying to create a clean installation with Wordpress and LAMP After the Cert is setup and wordpress is almost ready to install.

I go to my Https website and i get “error to many redirects”

I add to my .htaccess

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

how Should i fix this?

Excellent! Thank you for taking the time to write this out, very helpful and easy to understand.

As a note, for the contab, Certbot seems to recommend certbot-auto renew --quiet --no-self-upgrade

so I assume the same params would apply to letsencrypt or what not…

Auto renewal is not working. Perhaps something is missing in the tutorial?

Try 30 2 * * 1 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin && /usr/bin/letsencrypt renew >> /var/log/le-renew.log

Source: https://community.letsencrypt.org/t/letsencrypt-renew-not-working-with-cronjob-manually-it-works/16738/9

https://github.com/certbot/certbot/issues/1833

Yes, auto-renewal is not working with this tutorial. You have to add the export path. I’m wait for another renewal period to see if this is fixed, but it should look like this, please let me know if this worked for anyone else.

30 2 * * 1 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin && /usr/bin/letsencrypt renew >> /var/log/le-renew.log

Source: https://community.letsencrypt.org/t/letsencrypt-renew-not-working-with-cronjob-manually-it-works/16738/9

https://github.com/certbot/certbot/issues/1833

As a newbie to all things Ubuntu/Wordpress, I really appreciate the above article but hoped to ask the community to clarify a few things. I already have a functioning Wordpress site running on ubuntu 16.04 server with Wordpress installed using the really helpful DO one click install. I also have 5 domains all re-directing to my primary domain using CNAME aliases activated within the DO control panel. It all works well but I hope to make use of LetsEncrypt to enforce secure only access. Having (unsuccessfully) played around with activating LetsEncrypt on one of the subdomains, I hoped someone could help me with the following queries:

  1. As things stand if anyone types any of my subdomains into browser (for instance, www.mycompany.us, www.my company.co) the alias kicks in and takes you to www.mycompany.com. Also, both www.mycompany.com and http://mycompany.com resolve to mycompany.com in a browser, it all works well. I presume I only need to apply LetsEncrypt to my primary domain as the re-directs will push all requests (http or otherwise) to the https primary domain?
  2. I have went through the server setup guide and started to work through the ‘how to setup apache virtual hosts guide’. Do I need to create a new virtual hosts file for www.mycompany.com or can I amend the already existing 000-default.conf file to include server name, server alias and update serveradmin with my proper email address?
  3. The guide talks about creating a directory for new content and pointing Document Root to this, given i already have Wordpress content stored in the default location, presume I can keep DocumentRoot pointed to /var/www/html??
  4. Now onto this guide, once LetsEncrypt is installed, following running ‘sudo letsencrypt --apache -d mycompany.com -d www.mycompany.com’ - do I need to do anything within Wordpress to ‘tell’ Wordpress the certificate is available and web requests should be resolved as https??

Apols for the queries, hoping to get some nudges in the right direction:)

  1. Correct on the redirect on the primary domain, but as shown on point 4 of your question you have to add the www.xxx.com and the xxx.com.

  2. Best practice to use a virtual hosts file for your domain. I think this is used by lets enrypt, if you have more than one domain added on the file, you can add another domain to with letsencrypt and manage multiple hosts / sites, which i’m sure you will do at some point.

3 ) I cant remember the bit about creating new directories but i’m sure your content stays where it should be in the wordpress install on the root you specified.

  1. In wordpress you may want to use a plugin of some sort that forces the use of https scripts. You’ll find that a whole bunch of scripts are unsecure (http) and your site will show a nasty red line through a https instead of lovely trustworthy green,

External scripts can make this difficult to do. Like I said, a plugin might be the quickest way of solving it, but it depends on how many external scripts, where from and how easy/difficult it is to change them to be https.

Set up the lets encrypt certificate and then remedy the scripts that are not secure. There is a tool to help check this. https://www.sslshopper.com/ssl-checker.html

Thanks for the great tutorial again.

Generating certificates this way is great, but it leaves you open to your cron accidentally breaking or your renewal script not working as you expected. To get around this you should check your SSL certificate regularly to ensure that it’s been renewed using a service like TrackSSL that notifies you if your certificate is close to expiration.

A good recommendation. I had renewal fail on a client’s site. Not good. Seems like less of a hassle to set a calendar reminder to do it manually every 2 months, rather than wait for it to fail and have your client call you in 90 days.

Hi, I’m having problems using Crontab for Auto Renewal (NoInstallationError)

Using this cron command

# 30 2 * * 1 /usr/bin/letsencrypt renew >> /var/log/le-renew.log

Produces this error:

2017-04-10 02:30:02,656:DEBUG:letsencrypt.cli:Requested authenticator apache and installer apache 2017-04-10 02:30:02,657:DEBUG:letsencrypt.plugins.disco:No installation (PluginEntryPoint#apache): Traceback (most recent call last): File “/usr/lib/python2.7/dist-packages/letsencrypt/plugins/disco.py”, line 103, in prepare self._initialized.prepare() File “/usr/lib/python2.7/dist-packages/letsencrypt_apache/configurator.py”, line 152, in prepare raise errors.NoInstallationError NoInstallationError 2017-04-10 02:30:02,660:DEBUG:letsencrypt.display.ops:No candidate plugin 2017-04-10 02:30:02,660:DEBUG:letsencrypt.display.ops:No candidate plugin 2017-04-10 02:30:02,660:DEBUG:letsencrypt.cli:Selected authenticator None and installer None 2017-04-10 02:30:02,660:INFO:letsencrypt.cli:Could not choose appropriate plugin: The apache plugin is not working; there may be problems with your existing configuration. The error was: NoInstallationError()

Could anyone shed any light on this problem?

This is not working for me. Any suggestions?

is this applicable to the servers with multiple domains? or only single domain? For example im hosting multiple WP on my VPS using multiple domains. each one has its own domain. How can i apply this to all of the websites and domains?

Step 1 is missing the update of the distribution: sudo apt-get dist-upgrade

otherwise will always show there are n packages that can be updated when logging in…

And nearly 3 months after initial success, I am back!:) Or should i say :(

My certs created a few months ago are up for renewal. I’ve tried running the standard sudo letsencrypt renew to no avail. I get the following error message:

2017-05-11 12:28:52,393:WARNING:letsencrypt.cli:Attempting to renew cert from /etc/letsencrypt/renewal/<mydomain>.com.conf produced an unexpected error: Failed to run Apache plugin non-interactively
Missing command line flag or config entry for this setting:
We were unable to find a vhost with a ServerName or Address of www.wealth-hack.co.
Which virtual host would you like to choose?
Choices: ['000-default.conf               | Multiple Names        |       | Enabled', 'default-ssl.conf.save          | Multiple Names        | HTTPS |        ', 'default-ssl.conf               | Multiple Names        | HTTPS | Enabled', '000-default.conf.backup        | Multiple Names        |       |        ']
(The best solution is to add ServerName or ServerAlias entries to the VirtualHost directives of your apache configuration files.). Skipping.

Hoping someone else has seen that and can help advise?

Do I need to run this in ‘interactive mode’ and point the update utility to my ‘000-default.conf’ file (which does contain the multiple domains covered under the initial cert)? Or do I need to update the letsencrypt conf file. On examination, the apache_vhost_root looks to be pointing to the correct folder…

Yes! For the first time, I managed to get this working myself. I’ll share the outcome with the community in case it helps someone else.

My issue was, I was assuming my multi-domain setup was built around the following file which contained all my aliases correctly 000-default.conf. However, I added the multiple aliases to default-ssl.conf and renew worked a treat.

Incidentally, while researching this, I found the following command which helped me test my changes before committing (and therefore, build confidence before hitting the ‘scary red button)’!. The following allows for a dry run: sudo letsencrypt renew --agree-tos --dry-run

Hope this helps a newbie like me in the future…

Beautiful tutorial. Thanks! :)

Where does the crontab file belong?

When I typed “sudo crontab -e”, I got this:

no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/vim.basic
  4. /usr/bin/vim.tiny

Choose 1-4 [2]: 2
crontab: installing new crontab

I chose nano, but the file was saved at this location: /tmp/crontab.1BwnQ0/crontab

My understanding is that will disappear upon reboot, correct? So where does the crontab file belong? Thanks in advance!

I found that this one works best for me. https://www.wordpresstutorialsadvanced.in/setup-ssl-certificates-amazon-lightsail/ It also has a video tutorials

Hello

Why do you explicitly define the path as “/usr/bin/certbot” with crontab?

Here it uses “certboot renew” only… https://certbot.eff.org/#ubuntuxenial-apache

Thank you for the great document! c3y

I have a problem in the auto renew step, after adding the following code:

. . .
15 3 * * * /usr/bin/certbot renew --quiet

I got this error message :

root@alddade:~
```# sudo crontab -e
no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/jmacs
  4. /usr/bin/joe
  5. /usr/bin/jpico
  6. /usr/bin/jstar
  7. /usr/bin/mcedit
  8. /usr/bin/rjoe
  9. /usr/bin/vim.basic
  10. /usr/bin/vim.tiny

Choose 1-10 [2]: 2
No modification made
root@alddade:~# sudo crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
"/tmp/crontab.ghZX4B/crontab":22: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n) n

hi

i was using this tutorial and got the following error: Failed authorization procedure. topladylingerie.co.ke (tls-sni-01): urn:acme:err or:connection :: The server could not connect to the client to verify the domain :: Connection refused, www.topladylingerie.co.ke (tls-sni-01): urn:acme:error:c onnection :: The server could not connect to the client to verify the domain :: Connection refused

IMPORTANT NOTES:

  • The following errors were reported by the server:

    Domain: topladylingerie.co.ke Type: connection Detail: Connection refused

    Domain: www.topladylingerie.co.ke Type: connection Detail: Connection refused

    To fix these errors, please make sure that your domain name was entered correctly and the DNS A record(s) for that domain contain(s) the right IP address. Additionally, please check that your computer has a publicly routable IP address and that no firewalls are preventing the server from communicating with the client. If you’re using the webroot plugin, you should also verify that you are serving files from the webroot path you provided. ==============

And here is the ufw status: Status: active

To Action From


Apache Full ALLOW Anywhere OpenSSH ALLOW Anywhere 80 ALLOW Anywhere 443 ALLOW Anywhere Apache Full (v6) ALLOW Anywhere (v6) OpenSSH (v6) ALLOW Anywhere (v6) 80 (v6) ALLOW Anywhere (v6) 443 (v6) ALLOW Anywhere (v6) ==============

I don’t think so that this has anything to do with DNS A record… I am doing this first time and had googled it but no result. and event tried the cases on this page. still error…

Can anyone help?

Hello everyone

i’m just a newbie and i really don’t understant what you are saying :) i just open my blog with one click wordpress thing. i read your tutorial and i skip the Prerequisites part of your tutorial and now i have ssl certificate i dont have any problem for now but i wonder could it be problem in the future? i really waiting your answer Sorry for bad english:(

This comment has been deleted

    I chosed not to force the redirect ( to see if it was really working ), and it is working great. Thanks for the tuto!

    The thing is now I really Do want to force the redirect.

    Shall I run the config command again to force de redirect or is any other command to do so? ( maybe editing some file ? )

    Thanks in advance :)

    I followed the tutorial with no problems, yet it still shows says people are connecting to an unsecure site. How would I go about fixing this?

    Thanks a lot, Erika!

    Hi, i’m sorry but the first command :

    sudo add-apt-repository ppa:certbot/certbot

    didn’t work :

    sudo: add-apt-repository: command not found

    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!

    Become a contributor for community

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

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.