LinuxPublished on July 13, 20267 min read

Certbot: install a Let's Encrypt SSL certificate on a VPS (Nginx/Apache)

Certbot installs a free Let's Encrypt SSL certificate on your VPS, whether the site runs on Nginx or Apache. This guide shows how to install Certbot on Debian 13, Debian 12 or Ubuntu, get the certificate and check its automatic renewal. It also covers wildcard certificates and the most common errors.

Understand Let's Encrypt and Certbot

Let's Encrypt is a non-profit certificate authority. It issues free SSL/TLS certificates through the ACME protocol. Certbot, developed by the EFF, is the reference ACME client. It proves that you control the domain, fetches the certificate and configures your web server.

The proof goes through a challenge. The most common one, HTTP-01, works in three steps.

  1. Certbot, on your VPS, requests a certificate for your domain.

  2. Let's Encrypt starts the HTTP-01 challenge. It reads a temporary file that Certbot placed on your domain, through port 80.

  3. If it can read the file from the Internet, the domain is validated and the certificate issued. The site switches to HTTPS, and Certbot handles renewals.

The encryption is the same as with a paid certificate. Paid offers mainly add organisation validation (OV or EV) and a contractual warranty.

A Let's Encrypt certificate lasts 90 days, against one year for most paid certificates. A stolen key is useful for less time, and renewal has to be automatic. Let's Encrypt has announced 64 days from 10 February 2027, then 45 days in February 2028.


Prepare the server

Most failures come from one of these four points. Check them before running Certbot.

  1. The VPS runs Debian 12 or 13, or Ubuntu 22.04 or 24.04, and you have root or sudo access.

  2. The domain's A record points to the VPS IPv4 address, and its AAAA record to the IPv6 address if you have one. Propagation must be complete.

  3. A web server already answers over HTTP. If not, follow Install Nginx and PHP-FPM on a Linux VPS first.

  4. Ports 80 and 443 are open. With UFW, run sudo ufw allow 'Nginx Full', or sudo ufw allow 'WWW Full' for Apache. The guide How to set up the UFW firewall on Ubuntu or Debian covers the rest.

If your domain is with OuiHeberg, create the record in the domain's DNS zone tab, with the Add button. In the Add a record window, pick Type A (or AAAA), then fill in Name and Value. The guide How to edit the DNS records of your domain explains each field.

Add a record window with the Type, Name, Value and TTL fields

Is your site on a cPanel plan rather than a VPS? SSL is handled in cPanel there, as shown in the SSL part of the guide How to add a domain on cPanel.


Install Certbot

The EFF recommends the snap package. It keeps Certbot up to date and sets up automatic renewal. First remove the repository Certbot if it is already installed.

# First remove the repository Certbot, if installed
sudo apt remove certbot

# Install snapd, then Certbot
sudo apt update && sudo apt install snapd -y
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# Check
certbot --version

The last command shows the installed version. The Debian and Ubuntu repository package also works, with an older version.

# Nginx
sudo apt install certbot python3-certbot-nginx

# Apache
sudo apt install certbot python3-certbot-apache

Get and install the certificate

With Nginx

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

The --nginx plugin validates the domain, gets the certificate and edits the site's server block. It also offers to redirect HTTP to HTTPS. Accept, or add --redirect to the command to skip the question.

Certbot confirms with "Successfully received certificate", then "Successfully deployed certificate" and the site's HTTPS address.

With Apache

The command is the same with the --apache plugin.

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

Without a web server (standalone mode)

A mail server, a panel or an app that handles its own TLS does not need Nginx. Certbot then starts a temporary web server on port 80.

# Free port 80 if a web server is using it
sudo systemctl stop nginx
sudo certbot certonly --standalone -d example.com
sudo systemctl start nginx

Where the files are

In every case, the certificate is stored in /etc/letsencrypt/live/example.com/.

  • fullchain.pem holds the certificate and the intermediate chain. It is almost always the file your applications expect.

  • privkey.pem is the private key. It must never leave the server.


Check automatic renewal

This is the step people skip most often, and the main cause of expired certificates. Certbot installs a systemd timer that runs certbot renew twice a day. A certificate is renewed when about 30 days are left.

DayStep
0The certificate is issued.
60The renewal window opens. The timer renews the certificate on its next run.
90Expiry date, never reached when renewal works.

Check that the timer is active, then simulate a renewal. The simulation uses the Let's Encrypt staging server and does not use up your quota.

systemctl list-timers | grep certbot
sudo certbot renew --dry-run

If the simulation ends with "Congratulations, all simulated renewals succeeded", renewal is set up.

Reload a service after renewal

Nginx and Apache are reloaded by their plugin. Another service, such as a mail server, needs a deploy hook. Passed to certbot renew, it applies to that run only. Placed in /etc/letsencrypt/renewal-hooks/deploy/, it runs on every renewal.

# For this renewal only
sudo certbot renew --deploy-hook "systemctl reload postfix"

# For every future renewal
sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-postfix.sh > /dev/null << 'EOF'
#!/bin/sh
systemctl reload postfix
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-postfix.sh

Get a wildcard certificate

A wildcard certificate, such as *.example.com, covers every subdomain at once. It is handy when app., api. and blog. run on the same VPS. Let's Encrypt only issues it through the DNS-01 challenge. You prove control of the domain by creating a TXT record named _acme-challenge.

sudo certbot certonly --manual --preferred-challenges dns \
  -d "example.com" -d "*.example.com"

The --manual mode means creating the TXT record again at each renewal. In production, use a DNS plugin instead, such as certbot-dns-cloudflare or certbot-dns-ovh. It creates the record through your DNS provider's API.

The DNS-01 challenge also works for a server with no public IP address, since Let's Encrypt never contacts the server.


Fix the most common errors

# Does the firewall allow ports 80 and 443?
sudo ufw status

# Does the domain point to the VPS (IPv4, then IPv6)?
dig +short example.com
dig +short AAAA example.com

"Connection refused" or "Timeout during connect"

Port 80 is closed or filtered. Check sudo ufw status. The HTTP-01 challenge needs port 80 open, even if the site only serves HTTPS.

NXDOMAIN DNS error

Certbot shows DNS problem: NXDOMAIN. The A record does not exist yet or has not finished propagating. Until dig +short returns the VPS address, there is no point running Certbot again.

An AAAA record pointing elsewhere

Let's Encrypt prefers IPv6 when an AAAA record exists. If it points to an address where the web server does not listen, validation fails even though the site works over IPv4. Fix the AAAA record, or make Nginx listen on IPv6 with listen [::]:80;.

"too many certificates already issued"

You have hit a Let's Encrypt limit. It allows 50 certificates per domain per week, and only 5 identical certificates per week. This often happens when you rerun the command to test. Run your tests with --dry-run, which uses the staging server without these limits.

Renewal fails although issuance worked

The configuration changed in the meantime, for example a removed server block, port 80 redirected elsewhere or a stricter firewall. Run sudo certbot renew --dry-run after every major change. You will avoid a bad surprise two months later.


Strengthen your HTTPS setup

The certificate is only half the job. Redirect all HTTP traffic to HTTPS with a 301 redirect, which Certbot offers. Then enable HSTS, so browsers never try HTTP again. With Nginx, add this line to the HTTPS server block.

add_header Strict-Transport-Security "max-age=31536000" always;

Finally, check your site's grade on SSL Labs and aim for A or A+. The TLS settings that Certbot writes in options-ssl-nginx.conf follow Mozilla's recommendations and usually already give an A.

HTTPS only protects the transport. The guides Install and secure phpMyAdmin with Nginx and Install Laravel on a Linux VPS fit the certificate into a full stack. The guide How to secure a Linux VPS reviews the rest of the configuration.


What about a Windows VPS?

Certbot is built for Linux. On Windows Server with IIS, an ACME client such as win-acme does the same job. The guide Install Let's Encrypt on IIS sets it up.


Need help?

Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. You can also ask your question on the OuiHeberg Discord.

Was this article helpful?

425 views
Share this article
VPS Linux
Need a Linux VPS?

Root access, your choice of distribution and management from the OuiHeberg client area.

View plans →

Related Articles