Apache: setting up a free SSL certificate with Let’s Encrypt and certbot

In the past, getting an SSL certificate meant generating a private key and a certificate signing request with OpenSSL, submitting it to a certificate authority and renewing the certificate by hand every year. Today Let’s Encrypt does this for free and fully automatically – with the certbot program in a few minutes.

Requirements

  • Apache is running and the website is reachable via HTTP under its domain name.
  • The domain’s DNS record points to the server.
  • Port 80 is reachable from the internet – Let’s Encrypt uses it to verify that the domain really belongs to you.
  • For every domain there is a VirtualHost with a matching ServerName or ServerAlias.

Installing certbot

sudo apt install certbot python3-certbot-apache

Requesting a certificate

sudo certbot --apache -d example.org -d www.example.org

The first time, certbot asks for an e-mail address and for your consent to the terms of service. It then requests the certificate, automatically creates an HTTPS VirtualHost (…-le-ssl.conf) and, if you wish, sets up the redirect from HTTP to HTTPS. For further websites on the same server simply repeat the command with the other domains – thanks to SNI, any number of HTTPS sites can run on a single IP address.

To fetch only the certificate without certbot changing the Apache configuration:

sudo certbot certonly --apache -d example.org

The files are then located in /etc/letsencrypt/live/example.org/ (fullchain.pem and privkey.pem).

Automatic renewal

Let’s Encrypt certificates are only valid for a few weeks to months, and lifetimes will be shortened further over the coming years. Renewal is handled by a systemd timer that the package sets up automatically. To check that everything works:

systemctl list-timers certbot.timer
sudo certbot renew --dry-run
sudo certbot certificates          # all certificates with their expiry dates

Important: since 2025 Let’s Encrypt no longer sends reminder e-mails before expiry. You should therefore test once after the setup, using --dry-run, that automatic renewal works.

Wildcard certificates

A certificate for *.example.org can only be issued through DNS validation: certbot has to create a TXT record in the DNS for this. That works automatically with a suitable DNS plugin (e.g. python3-certbot-dns-cloudflare) or by hand with --manual --preferred-challenges dns – but then without automatic renewal.

Behind a reverse proxy

If a reverse proxy such as Caddy, Traefik or Nginx Proxy Manager runs in front of Apache, the proxy usually takes care of the certificates. Caddy, for example, obtains and renews Let’s Encrypt certificates without any additional program. Apache then needs no certificate of its own.

Originally published in 2012 with certificates from StartCom – that certificate authority has not existed since 2018. Completely revised in November 2026.