HTTPS with Let's Encrypt
Your site loads, but the browser calls it "not secure". Let's get a free Let's Encrypt certificate with certbot, switch to HTTPS and let the renewal run by itself.
- Course
- Tutorial 18 of 35
- Time
- 30 min to read
- Tested with
- Debian 13.7, certbot 4.0.0, Apache 2.4.69. Issuing the certificate is not tested (no public domain).
What you will be able to do
- Understand what HTTPS changes and what a certificate is.
- Get and install a certificate with certbot --apache.
- Redirect HTTP to HTTPS and check it with curl -I.
- Check the automatic renewal with certbot renew --dry-run.
Before you start: Your first website with Apache, Domain name and DNS.
Contents
How do you install a free HTTPS certificate with Let's Encrypt? The site from Your first website with Apache works, but it travels in the clear, and browsers flag it as "not secure". We'll install certbot, get a certificate for exemple.fr, redirect visitors to the secure version and check that the renewal will run without you. Plan on half an hour.
Why switch to HTTPS
HTTPS is HTTP in an envelope: the conversation between the browser and your server is encrypted, so nobody along the way can read it. Without it, a password typed on your site travels like a postcard, readable by every mail carrier. With it, it's a letter in a sealed envelope.
The envelope isn't enough: you also need to be sure you're talking to the right recipient. That's the job of the certificate, a digital ID card for your site, issued by an organization that every browser knows. Let's Encrypt is one of those organizations, and it's free. A certificate says "this site really is exemple.fr", and the browser's padlock shows that it checked. All that's left is to ask for yours, after a few checks.
1Check the basics
Let's Encrypt checks that you really control the domain by knocking on your port 80 from the Internet. So two things must be true before you start:
- The domain points at your server. That's the job of the DNS, the Internet's directory, covered in Domain name and DNS.
- Port 80 is open and Apache answers, as in Your first website with Apache.
For the first one, the getent command asks Debian which address matches your domain name. The first word on the line must be your server's IP address, the number that identifies a machine on the network, here 203.0.113.10; the rest doesn't matter.
getent ahostsv4 exemple.fr | head -1203.0.113.10 STREAM exemple.frIf the address is different, or nothing shows up, stop here: the DNS isn't ready, and Let's Encrypt would refuse. A DNS change can take a few hours to spread. If it's the right address, move on to the installation.
2Open port 443 and install certbot
HTTPS uses port 443, as HTTP uses 80. Let's open it in ufw, without closing 80: certbot needs it to check, then to redirect.
sudo ufw allow 443/tcpRule added
Rule added (v6)Next, let's install certbot, the program that requests the certificate from Let's Encrypt. The python3-certbot-apache package teaches it to talk to Apache: it edits your configuration itself.
sudo apt install -y certbot python3-certbot-apacheLet's check the installation with the program's version.
certbot --versioncertbot 4.0.0Everything is ready for the real request.
3Get the certificate
One command requests the certificate, stores it and configures Apache. Since certbot edits your configuration, first keep a copy with sudo cp -r /etc/apache2 ~/apache2-avant. In the command, --apache picks the Apache method, -d names each domain to cover, and --redirect sends visitors from HTTP to HTTPS.
sudo certbot --apache --redirect -d exemple.fr -d www.exemple.frOn its first run, certbot asks three questions:
- Your email address: Let's Encrypt uses it to warn you if the renewal fails.
- The terms of service: read them, then accept.
- The newsletter of the organization behind certbot: you can say no.
During the request, certbot has Apache serve a small file, and Let's Encrypt comes to read it from the Internet: that's the proof that the domain is yours. When everything works, a congratulations message gives the expiry date and the certificate's folder, /etc/letsencrypt/live/exemple.fr/.
On the Apache side, certbot wrote a second VirtualHost for port 443, in a file whose name ends in -le-ssl.conf, and added the redirect to the old one. You have nothing to edit. Let's check that everything works.
4Check the redirect with curl
Two tests are enough: the old address must send you to the new one, and the new one must answer. Let's start with HTTP. The -I option of curl prints only the headers, the ID card of the response.
curl -sI http://exemple.fr/ | head -4HTTP/1.1 301 Moved Permanently
Date: Thu, 05 Nov 2026 01:45:28 GMT
Server: Apache/2.4.69 (Debian)
Location: https://exemple.fr/The code 301 means "moved for good", and the Location line gives the new address. The date will be your own. Now let's test HTTPS.
curl -sI https://exemple.fr/ | head -1The first line must end with 200: HTTP/1.1 200 or HTTP/2 200, depending on the protocol version. If the certificate had a problem, curl would refuse with a certificate error instead of showing the page. In a browser, open http://exemple.fr: the address must switch to https:// by itself, with the padlock. One more thing: a certificate doesn't last forever.
5Automatic renewal
A Let's Encrypt certificate is valid for 90 days, and the organization recommends renewing it every 60 days. Debian's certbot package takes care of it: it installs a scheduled task, called a timer, that wakes up twice a day and renews only the certificates close to expiry. The systemctl command lists the system's timers.
systemctl list-timers certbot.timerThe certbot.timer line must show up, with the date of the next run. But a task that has never run proves nothing. Let's do a dress rehearsal: the --dry-run option simulates the whole renewal against a Let's Encrypt test server, without touching your real certificate.
sudo certbot renew --dry-runThe command must end with a message saying all simulated renewals succeeded. Better a failure today than an expired certificate in three months. If it succeeds, your site is on HTTPS and will renew itself. If not, the cause is almost always the same as for the first request: let's look at the common cases.
If it fails
Three certbot messages come up often:
no valid A records found for exemple.fr. The DNS doesn't point (yet) at your server. Go back to step 1, wait a bit, then run it again.Timeout during connect (likely firewall problem). Let's Encrypt couldn't reach your port 80. Checksudo ufw status: the80/tcprule must be there. Also check that no firewall at your hosting provider is blocking it.No simulated renewals were attempted, instead of the expected success. Nothing is broken: certbot has no certificate to renew, because the command from step 3 didn't go through.
Let's Encrypt rate limits
Let's Encrypt caps the number of requests so that nobody can overload it. Three limits concern you:
| Limit | Threshold | What triggers it |
|---|---|---|
Certificates for exemple.fr and its subdomains | 50 every 7 days | many certificates requested for that same domain |
| Certificates for the same list of names | 5 every 7 days | repeating the same request in a loop |
| Validation failures | 5 per hour and per name | a misconfigured DNS or port 80, retried without fixing it |
The trap is the third line: one configuration mistake, repeated five times, locks you out for an hour. Fix the cause before each new try. To test safely, use --dry-run: it goes through the test server, not the real one.
Certificates will get shorter
Let's Encrypt has announced shorter certificates: 64 days from February 10, 2027, then 45 days in 2028. Certbot's automatic renewal handles this with no change on your side, as long as you keep the timer active.
Frequently asked questions
Is Let's Encrypt really free?
Yes, Let's Encrypt is a free certificate authority whose certificates every browser trusts. Certbot requests and installs the certificate for you.
How long does a Let's Encrypt certificate last, and do I renew it by hand?
A certificate is valid for 90 days. Debian's certbot package installs a timer that renews it by itself, and certbot renew --dry-run checks that it will work.
Why does certbot refuse my certificate?
Most often, the DNS doesn't point at your server yet or port 80 is closed. Fix the cause before trying again: five failures in one hour block the next request.
What's next
Your site is secure, but it's still a fixed page: the same text for everyone. To show data that changes, like accounts or articles, it needs a language and a database. The next article, A dynamic site: PHP and MariaDB, installs them behind this same Apache.