Issue and renew a web server certificate from letsencrypt on AWS EC2

Published by Tobias Hofmann on

4 min read

I’ll show how to obtain a valid letsencrypt certificate for Apache on AWS EC2 Linux AMI and Namecheap as DNS provider.

Running a private web server on AWS EC2 is easy. Managing it is not so easy. Having a valid TLS web server certificate from letsencrypt is one of the managing jobs that could be easier. I was told that this part is easier on Azure, maybe I should take a look at that option. Letsencrypt for an AWS Linux AMI isn’t as easy as it normally is to manage your web certificates with letsencrypt as the standard letsencrypt client certbot is not fully working and supported. It works, but you have to run it in debug mode, and sometimes it won’t work. See google for how many people got into problems because certbot stopped working on AMI Linux.

As letsencrypt is following a protocol for issuing a certificate (ACME), you can choose from a wide range of alternatives. One that is working with the AWS Linux AMI is It supports ACME v2. This is important when you want to have wildcard certificates and still getting normal certificates, as the v1 protocol is EOL. can do everything automatically once configured, making it really easy to always have a valid certificate.


My setup is an exception from the rule. My DNS is hosted by Namecheap. They do not allow to script the DNS configuration if you are not a meeting some minimum requirements. As the ACME protocol validates if you are the owner of a DNS by setting a TXT entry: I have to do this manually (thanks for nothing Namecheap). Therefore, my setup is a little bit different.


Follow the installation detailed at the wiki.

curl | sh

Get certificate for given FQDN

You run the program and inform the fqdn (parameter -d) and the document root of your web server (parameter -w). takes care of the rest.

./ --issue -d -w /var/www/wordpress/

Activate certificate

Above step obtained the certificate from letsencrypt CA. To activate them, you have to copy them to Apache directory and restart the http server.

./ --install-cert -d --cert-file /etc/letsencrypt/live/ --key-file /etc/letsencrypt/live/ --fullchain-file /etc/letsencrypt/live/

Get wildcard certificate

In case you want a wildcard certificate, the procedure is a little bit different. Normally can handle the extra validation work needed for a wildcard certificate. With namecheap, you have to do set the DNS entries to validate that you are the owner of the domain manually. The wildcard process contains of two steps:

  1. Get a TXT challenge that you add to your DNS and
  2. Validate the TXT challenge and get the certificate

Run program to get the TXT challenge

./ --issue -d -d '*' -w /var/www/wordpress/ --force --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please

In the output you can see that you have to create a TXT record for _acme-challenge.<yourdomain>.<tld> and assign the provided text value to it. Letsencrypt will check for that value to validate that you are the owner of the domain. If you can change the DNS entry, you are the owner. Make sure to know how add a TXT record to your DNS.

Set DNS value.

Domain: ''
TXT value: 'DvHx946wm_jdipMIA88hll3Z11JM62kp7nWpKQiYhZQ'

Check if new TXT value is available.

dig -t txt

Only if this command shows that the TXT value is updated, you can continue with the next step!

Validate the TXT challenge and get the certificate

When the new TXT record is available, the wildcard certificate can be requested. Run the same command as before, but use –renew instead of –issue.

./ --renew -d -d '*' -w /var/www/wordpress/ --force --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please

To activate the new certificate, you have to restart the httpd server.

Let the world know
Categories: Technology

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.