Last updated: 22 November 2026. Tested with Certbot 2.9.0 (the Ubuntu 24.04 apt package) and Apache 2.4.58, against a local Let's Encrypt test CA (Pebble), because the real Let's Encrypt servers were not reachable from my environment. Certificates, domains and output below come from that setup. SeeHow this was checked.
Getting an HTTPS certificate onto Apache takes one command. Keeping it renewed without surprises takes a little more: you need to know what Certbot changes in your config, what schedules the renewal, and what makes renewal fail quietly. This article covers the install, the issue and redirect step, the renewal setup, and the two failures I reproduced: Apache serving an old certificate after a successful renewal, and renewal breaking because of a blocked challenge path.
Prerequisites
- A domain whose DNS A (and AAAA, if you use IPv6) record points to this server.
- Ports 80 and 443 open on the firewall and any cloud security group. Let's Encrypt validates over port 80 with the default HTTP-01 challenge.
- An Apache virtual host on port 80 with a correct
ServerName(andServerAliasforwww). Certbot uses these to know which domains to ask for.
My starting virtual host, the file /etc/apache2/sites-available/blog.example.test.conf:
<VirtualHost *:80>
ServerName blog.example.test
ServerAlias www.blog.example.test
DocumentRoot /var/www/blog
ErrorLog ${APACHE_LOG_DIR}/blog-error.log
CustomLog ${APACHE_LOG_DIR}/blog-access.log combined
</VirtualHost>
Install Certbot
The Certbot project recommends the snap package, which stays current: the snap store lists version 5.8.0 as stable, while the Ubuntu 24.04 apt package is 2.9.0. If you use snap, follow the instructions at certbot.eff.org. I tested the apt package, which works and is easier to automate, but it will lag behind:
sudo apt update
sudo apt install certbot python3-certbot-apache
certbot --version
certbot 2.9.0
Do not mix the two. If you move to the snap, remove the apt package first so you do not end up with two certbot binaries and two renewal schedules.
Issue the certificate and enable HTTPS
The Apache plugin handles the challenge, edits your virtual host and reloads Apache:
sudo certbot --apache -d blog.example.test -d www.blog.example.test \
--non-interactive --agree-tos -m admin@example.test --redirect
Use a real email address for -m. Output, trimmed:
Account registered.
Requesting a certificate for blog.example.test and www.blog.example.test
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/blog.example.test/fullchain.pem
Key is saved at: /etc/letsencrypt/live/blog.example.test/privkey.pem
This certificate expires on 2027-02-19.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for blog.example.test to /etc/apache2/sites-available/blog.example.test-le-ssl.conf
What Certbot changed in Apache
Two things, and it is worth knowing both because they are the files you will edit later. First, it added a redirect to your port 80 virtual host (this is the diff against my original file):
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.blog.example.test [OR]
RewriteCond %{SERVER_NAME} =blog.example.test
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Second, it created blog.example.test-le-ssl.conf, a copy of your virtual host on port 443 with the certificate paths, and enabled it:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName blog.example.test
ServerAlias www.blog.example.test
DocumentRoot /var/www/blog
ErrorLog ${APACHE_LOG_DIR}/blog-error.log
CustomLog ${APACHE_LOG_DIR}/blog-access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/blog.example.test/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.example.test/privkey.pem
</VirtualHost>
</IfModule>
The shared TLS settings are in /etc/letsencrypt/options-ssl-apache.conf. In my run it set SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 and a list of ECDHE and DHE GCM and ChaCha20 ciphers. Certbot may update that file in later releases, so do not hand-edit it. Put your own overrides in your virtual host.
If you later change the document root or add directives to the port 80 host, remember that you now have two virtual hosts for one site. Edit both, or the HTTPS site and the HTTP redirect will drift apart.
Verify
curl -sI http://blog.example.test/
curl -sI https://blog.example.test/
openssl s_client -connect blog.example.test:443 -servername blog.example.test </dev/null 2>/dev/null \
| openssl x509 -noout -subject -dates -ext subjectAltName
In my test, plain HTTP returned 301 to the HTTPS URL, with the path and query string preserved (/a/b?x=1 redirected intact), HTTPS returned 200 over TLS 1.3, and a TLS 1.2 handshake also worked. I could not test TLS 1.0 and 1.1 because my local OpenSSL client refuses to offer them, so I am relying on the SSLProtocol line below for that. The certificate listed both names in its subject alternative names. Because my certificate came from a test CA, I had to give curl that CA's root. With a real Let's Encrypt certificate you will not.
How renewal is scheduled
The Debian and Ubuntu package ships both a systemd timer and a cron file. On a systemd host the timer runs and the cron entry does nothing; the cron job only runs where /run/systemd/system does not exist. The timer unit in my install:
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true
It runs certbot -q renew --no-random-sleep-on-renew twice a day. Certbot only renews certificates that are close to expiry (the cron file comment says within 30 days), so most runs do nothing. On a normal server, check that the timer is active:
systemctl list-timers certbot.timer
My test environment had no systemd, so I could not watch the timer fire. I checked the unit and cron files and ran the exact command they run (certbot -q renew --no-random-sleep-on-renew): with a certificate not due, it printed nothing and exited 0. If you use the snap, the timer is named snap.certbot.renew.timer instead.
The two ways to test renewal
sudo certbot renew --dry-run
sudo certbot certificates
--dry-run goes through the whole renewal against the Let's Encrypt staging server without replacing your certificate, and is what you should run after any Apache change. In my environment it failed at first, because a dry run switches to the staging server even when the certificate came from somewhere else, and that server was not reachable from my sandbox. Once I pointed it at my test CA with --server, the simulated renewal succeeded. If your dry run fails with a connection error to acme-staging-v02.api.letsencrypt.org, that is an outbound network problem, not a certificate problem.
One more gotcha when you run renewal by hand from a script or an SSH command without a terminal: Certbot waits a random time before doing anything. My non-interactive runs logged random delays of 277 and 358 seconds. Add --no-random-sleep-on-renew to avoid sitting through it. The timer already passes that flag.
Failure 1: the certificate renews, Apache keeps serving the old one
When you issue with --apache, Certbot uses the Apache plugin for both challenge and install, and renewal reloads Apache for you. I saw this line on a forced renewal:
Reloading apache server after certificate renewal
A lot of setups do not look like that. If you issued with certonly --webroot, --standalone or a DNS plugin and wrote the SSLCertificateFile paths yourself, Certbot replaces the files and does not tell Apache. I reproduced it with a second site:
sudo certbot certonly --webroot -w /var/www/api -d api.example.test
sudo certbot renew --cert-name api.example.test --force-renewal
after renew, no hook:
on disk: serial=4D883AF7B930567D
served: serial=745B470CDFE5253D
The new certificate was on disk and the old one was still being served. The old one stays valid until it expires, so this looks fine for weeks and then your site shows an expired certificate. The fix is a deploy hook, which Certbot runs after each successful renewal. Any executable in /etc/letsencrypt/renewal-hooks/deploy/ is run:
#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/reload-apache.sh
# RENEWED_LINEAGE and RENEWED_DOMAINS are set by Certbot.
echo "$(date -u +%FT%TZ) renewed: $RENEWED_DOMAINS ($RENEWED_LINEAGE)" >> /var/log/certbot-deploy.log
apache2ctl configtest && apache2ctl graceful
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-apache.sh
After adding it, a forced renewal left the disk and the server on the same serial, and the log file had a line for the renewal. On a systemd server, use systemctl reload apache2 in place of apache2ctl graceful; my sandbox had no systemd, so I tested apache2ctl. A reload is a graceful restart, so open connections are not dropped.
Two details from testing. Certbot printed Hook 'deploy-hook' ran with error output because apache2ctl configtest writes "Syntax OK" and the AH00558 server-name warning to stderr. That is harmless, but it can produce cron or timer emails. Set a global ServerName in Apache to silence the warning. And a hook that exits non-zero is reported (Hook 'deploy-hook' reported error code 1) but the renewal still counted as a success and Certbot exited 0, so a failing hook will not fail your monitoring. Check the hook's own log.
Failure 2: renewal breaks because the challenge path is blocked
Renewal repeats the same validation as issuance. If something changes what port 80 serves for /.well-known/acme-challenge/, renewal fails weeks later, long after you changed the config. I reproduced two cases with the webroot method.
A blanket HTTP to HTTPS redirect is fine. With every request on port 80 redirected to HTTPS, renewal still succeeded in my test, so you do not need an exception for the challenge path in that case.
Blocking the path is not. I denied the challenge directory on port 80:
<Location "/.well-known/acme-challenge">
Require all denied
</Location>
Certbot failed to authenticate some domains (authenticator: webroot).
Domain: api.example.test
Type: unauthorized
Detail: Non-200 status code from HTTP: http://api.example.test:80/.well-known/acme-challenge/... returned 403
Failed to renew certificate api.example.test with error: Some challenges have failed.
All renewals failed.
The exit code was 1. The same thing happens with a firewall rule that drops port 80, a WAF rule, a RewriteRule that sends the path to your application, or a CDN in front of the site. Run certbot renew --dry-run after any change to the web server or the firewall.
Reading what renewal did
Certbot's log is /var/log/letsencrypt/letsencrypt.log. On a systemd host, the timer runs the certbot.service unit, so the journal has its output:
journalctl -u certbot.service --since "7 days ago"
For the time and unit filters used there, see the journalctl article linked below. I could not run that command on my test host since it had no journal.
Per-certificate settings are in /etc/letsencrypt/renewal/<name>.conf. For my certificate it recorded the server, authenticator = apache, installer = apache and key_type = ecdsa. That file is why a bare certbot renew knows how to renew everything. If you change the method (for example from standalone to webroot), edit it with certbot reconfigure or reissue, not by hand if you can avoid it.
Certificate lifetimes are getting shorter
Let's Encrypt certificates are currently valid for 90 days, which is why the schedule above works comfortably. According to Let's Encrypt's announcements, the default will drop to 64 days on 10 February 2027 and to 45 days on 16 February 2028, and they recommend clients that support ACME Renewal Info (ARI). I did not test whether Certbot 2.9.0 supports ARI. What you can do today is the part you control: make sure renewal runs automatically at least twice a day, that a failed renewal alerts someone, and that nothing in your process assumes a 90-day calendar. A monitor that checks the expiry of the certificate your site actually serves catches both failures above.
Common problems
| Symptom | Cause and fix |
|---|---|
| Challenge fails with a timeout or connection error | Port 80 is blocked by a firewall or security group, or DNS points elsewhere. Check from outside the server. |
| Challenge fails with 403 or 404 | Something is blocking or rewriting /.well-known/acme-challenge/. Check .htaccess, Location blocks and your WAF. |
| Certbot cannot find a matching virtual host | No ServerName or ServerAlias match the domain you passed with -d. Fix the port 80 virtual host first. |
| Site shows an expired certificate after renewal | Apache was not reloaded. Add a deploy hook. |
--dry-run fails with a connection error |
The server cannot reach the Let's Encrypt staging host. Check outbound HTTPS. |
Manual certbot renew seems to hang |
The non-interactive random delay. Add --no-random-sleep-on-renew. |
| Renewal is not running at all | Check systemctl list-timers certbot.timer, or the snap timer name if you installed the snap. |
Related Dev Talk articles
- journalctl: Filter Logs by Service and Time
- Apache mod_http2 CVE-2026-119618
- Secure Laravel Applications Before Production
Frequently asked questions
How do I get a free HTTPS certificate for Apache?
Install Certbot and its Apache plugin, then run sudo certbot --apache -d example.com -d www.example.com. Certbot gets a certificate from Let's Encrypt, adds a port 443 virtual host and, with --redirect, redirects HTTP to HTTPS.
Does Certbot renew certificates automatically?
The Ubuntu package installs a systemd timer that runs twice a day and renews certificates that are near expiry. Confirm it with systemctl list-timers certbot.timer and test with sudo certbot renew --dry-run.
Do I need to restart Apache after renewal?
If you issued with --apache, Certbot reloads it. If you used webroot, standalone or DNS validation with your own SSL paths, add a deploy hook that reloads Apache, or it keeps serving the old certificate.
Why did my renewal fail when issuance worked?
Something changed after issuance: a blocked challenge path, a closed port 80, a DNS change, or a proxy in front of the site. Run sudo certbot renew --dry-run and read the error.
Should I use the snap or the apt package?
The Certbot project recommends the snap because it stays current. The apt package works but is an older version. Do not install both.
update log
- 22 November 2026: first version.
- To recheck on each update: the Let's Encrypt default lifetime and dates, the Certbot version in Ubuntu's repositories and the snap, and whether the Apache plugin's generated config has changed.
Sources
- Let's Encrypt: 64-Day Certificate Lifetimes Coming Feb 2027
- Let's Encrypt: Upcoming Features
- Certbot documentation: Get Certbot
- Snap Store: certbot
- Pebble, the Let's Encrypt test ACME server
Originally published on DEV Talk.
Top comments (0)