Network security

How to Install an SSL Certificate on Apache: Step-by-Step Guide

Installing an SSL certificate on Apache takes about 15 minutes with Certbot, or a few manual steps with a purchased certificate. This guide covers both routes.

Cysoro Security TeamPublished · 8 min read
https://example.com<VirtualHost *:443> SSLEngine on SSLCertificateFile SSLCertificateKeyFile</VirtualHost>Syntax OK NETWORK SECURITY SSL onApache Certbot or manual, in 15 minutes.
Quick answer

To install an SSL certificate on Apache, enable mod_ssl with a2enmod ssl on Debian or Ubuntu (or install mod_ssl on RHEL), place your certificate, chain and private key files on the server, add SSLEngine on and the SSLCertificateFile, SSLCertificateKeyFile and SSLCertificateChainFile directives to a VirtualHost on port 443, test with apachectl configtest, reload Apache, and redirect HTTP to HTTPS.

Key takeaways

  • Certbot with Let's Encrypt is the fastest route: one command obtains, installs and renews a free certificate.
  • A manual install needs three files — certificate, private key and chain — pointed at by three mod_ssl directives in a port 443 VirtualHost.
  • Always test with apachectl configtest, keep port 443 open, and check the result with an SSL checker after reloading.

An SSL certificate turns your Apache site from plain HTTP into encrypted HTTPS — and without it, browsers warn visitors away. The good news is that installing one on Apache 2.4 takes about fifteen minutes with Certbot, or a handful of manual steps if you bought a certificate from a commercial authority.

What do you need before you install an SSL certificate on Apache?

You need Apache 2.4 running, a domain name pointed at the server, root or sudo access, and ports 80 and 443 open in the firewall. You also need a certificate, either free from Let's Encrypt or purchased from a commercial certificate authority.

Check your Apache version first. On Debian and Ubuntu run apache2 -v; on RHEL, CentOS, AlmaLinux or Rocky Linux run httpd -v. The steps below assume Apache 2.4, the current stable line.

Confirm the domain resolves to the server before you start. If DNS still points elsewhere, domain validation will fail and the certificate will not be issued. A quick dig +short example.com should return your server's IP address.

Finally, decide which certificate type you need. A single-domain certificate covers one name, a wildcard covers every subdomain, and a multi-domain certificate covers a list of names. Let's Encrypt issues free domain-validated certificates; commercial authorities also sell organization-validated and extended-validation certificates, which add identity checks.

How do I enable mod_ssl on Apache?

Enable mod_ssl before anything else, because without it Apache cannot serve HTTPS at all. On Debian and Ubuntu, run sudo a2enmod ssl and then restart Apache. On RHEL and CentOS, install the package with sudo dnf install mod_ssl.

Verify the module loaded by running apachectl -M | grep ssl. You should see ssl_module (shared) in the output. If it is missing, Apache will fail with an error about an unknown SSLEngine directive when you add the HTTPS configuration.

While you are here, enable the headers module too, because you will want it later for the HSTS header: sudo a2enmod headers on Debian and Ubuntu. On RHEL systems it is loaded by default.

Open port 443 in the firewall. With UFW, run sudo ufw allow 'Apache Full'. With firewalld, run sudo firewall-cmd --permanent --add-service=https followed by sudo firewall-cmd --reload. Cloud firewalls and security groups need the same rule.

How do I install an SSL certificate on Apache with Certbot?

Certbot is the fastest route for most sites. It obtains a free Let's Encrypt certificate, proves you control the domain, edits your Apache configuration, and sets up automatic renewal — usually in a single command.

First, make sure Apache already serves the domain over HTTP with a VirtualHost that has the correct ServerName. Certbot finds that VirtualHost and adds the HTTPS version to it.

Install Certbot and the Apache plugin. On Ubuntu, the Certbot team recommends the snap package: sudo snap install --classic certbot, then sudo ln -s /snap/bin/certbot /usr/bin/certbot. On older setups, sudo apt install certbot python3-certbot-apache also works.

Then run:

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

Certbot asks for an email address for renewal notices, proves domain control over port 80, installs the certificate, and offers to redirect all HTTP traffic to HTTPS. Say yes to the redirect.

Let's Encrypt certificates are valid for 90 days, and Certbot renews them automatically, usually through a systemd timer that runs twice a day. Test renewal with sudo certbot renew --dry-run and check the timer with systemctl list-timers | grep certbot.

Install SSL on Apache with Certbot — five steps1Enable mod_ssla2enmod sslopen port 4432Install Certbotsnap or apt,Apache plugin3Run Certbotcertbot --apache-d example.com4Redirect HTTPport 80 toport 4435Test and renewSSL checker,renew --dry-runLet's Encrypt certificates last 90 days and renew automatically.
The Certbot route: enable mod_ssl, install Certbot, run it, redirect HTTP, then test renewal. Illustration by Cysoro.

How do I install a purchased SSL certificate on Apache manually?

A manual install is needed when you buy a certificate from a commercial authority or your organization issues one internally. You will receive three files: the certificate, the intermediate chain, and the private key you generated with the certificate signing request.

First, generate a private key and a certificate signing request (CSR) if you have not already. OpenSSL does both:

openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr

Send the CSR to the certificate authority. When it returns the certificate, copy all three files to the server, for example into /etc/apache2/ssl/ on Debian and Ubuntu or /etc/pki/tls/certs/ on RHEL. Lock the key down with sudo chmod 600 /etc/apache2/ssl/example.com.key.

On Apache 2.4.8 and later, combine the certificate and the chain into one file, because the old SSLCertificateChainFile directive is deprecated:

cat example.com.crt example.com_chain.crt > example.com_fullchain.pem

Then point the VirtualHost at the files, as shown in the next section. Keep the private key off the web root and out of backups that leave your control — anyone with the key can impersonate your site.

How do I configure the Apache VirtualHost for SSL?

The VirtualHost is where the certificate meets the site. Create or edit the HTTPS VirtualHost so it listens on port 443, enables SSL, and names the certificate, key and chain files.

On Debian and Ubuntu, the file usually lives at /etc/apache2/sites-available/example-ssl.conf. On RHEL and CentOS, it is /etc/httpd/conf.d/ssl.conf. A working example looks like this:

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/example.com_fullchain.pem
    SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLHonorCipherOrder on
</VirtualHost>

The three directives that matter most are SSLCertificateFile (your certificate, or the combined full chain), SSLCertificateKeyFile (your private key) and SSLEngine on. If your authority gave you a separate chain file and you run Apache older than 2.4.8, add SSLCertificateChainFile as well.

Enable the site on Debian and Ubuntu with sudo a2ensite example-ssl.conf. Then test the syntax before reloading, because a typo here takes the site down:

sudo apachectl configtest
sudo systemctl reload apache2

On RHEL systems the reload command is sudo systemctl reload httpd. A reload, rather than a full restart, keeps existing connections alive while the new configuration takes effect.

How do I redirect HTTP to HTTPS on Apache?

Add a redirect so every plain HTTP request lands on HTTPS. The cleanest place is the port 80 VirtualHost for the same domain.

Add this inside the <VirtualHost *:80> block:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/
</VirtualHost>

Certbot can add this redirect for you when it asks during setup. If you prefer mod_rewrite, that works too, but the simple Redirect directive is easier to read and less error-prone.

After the redirect, test it in a browser or with curl: curl -I http://example.com should return a 301 response pointing at the HTTPS address. Also check that the redirect keeps the path, so http://example.com/pricing reaches https://example.com/pricing rather than the homepage.

How do I harden TLS and add HSTS after installing the certificate?

Installing the certificate is only half the job. Hardening the TLS settings closes off old, weak protocols that attackers can exploit, and HSTS tells browsers to always use HTTPS for your domain.

Limit protocols to TLS 1.2 and 1.3 with SSLProtocol -all +TLSv1.2 +TLSv1.3. Mozilla publishes tested intermediate and modern configuration profiles through its SSL Configuration Generator, which generates the exact cipher settings for your Apache version — copy those rather than inventing your own.

Add HSTS with mod_headers, which sends a header telling browsers to refuse plain HTTP for your site:

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

Only enable HSTS once HTTPS works reliably on every subdomain, because browsers will remember the instruction for a year and refuse HTTP even if your certificate later breaks. Start with a short max-age such as 300 seconds while testing, then raise it.

Enable OCSP stapling if your setup supports it. It lets Apache attach the certificate's revocation status to the handshake, so browsers do not need a separate slow check. The Apache mod_ssl documentation covers the SSLUseStapling directive and its cache settings.

Verify the install: five checks1apachectl configtest returns Syntax OK2https://example.com loads with a padlock, no warnings3SSL checker shows the full chain and TLS 1.2 or 1.34http://example.com redirects to HTTPS with a 301Run check 5 too: certbot renew --dry-run proves renewal works.
Five verification checks to run after any Apache SSL install. Illustration by Cysoro.

How do I verify the SSL certificate is working?

Verification takes two minutes and catches most mistakes. Start in a browser: visit the HTTPS address and look for the padlock with no warning. Then run an independent check, because browsers sometimes hide chain problems.

Run Cysoro's free SSL checker against your domain. It shows the certificate chain, expiry date and TLS versions, which is exactly what you need to spot a missing intermediate certificate.

Also run the security headers checker to confirm HSTS and other headers are present.

From the command line, openssl s_client -connect example.com:443 -servername example.com shows the certificate Apache actually serves, including its expiry date and issuer. Add -tls1_3 to confirm TLS 1.3 negotiates.

Check the certificate expiry and set a reminder or a monitoring alert. Expired certificates are one of the most common causes of site outages, and a monitoring tool catches them weeks before visitors do. If you used Certbot, confirm the renewal timer is active so the 90-day cycle never lapses.

What are the most common Apache SSL installation mistakes?

Most failed installs come from a short list of mistakes, and each has a clear fix. Work through them in order before changing anything else.

ProblemLikely causeFix
Site still shows "not secure"Missing intermediate chainCombine certificate and chain into one fullchain file
Apache fails to startTypo in the VirtualHost or wrong file pathRun apachectl configtest and read the error line
Connection refused on port 443Firewall blocking 443 or VirtualHost not listeningOpen port 443 and check Listen 443 is set
Certificate name mismatchCertificate is for a different domainReissue for the exact domain, including www if needed
Mixed content warningsImages or scripts loaded over HTTPUpdate links to HTTPS or use relative URLs
Renewal failsPort 80 closed or web root changedKeep port 80 open and test certbot renew --dry-run

The single most common error is the missing chain. Browsers on some devices will still load the site, while others show a warning, which makes it easy to miss. An SSL checker that validates the full chain catches it immediately.

Another frequent mistake is editing the wrong configuration file. Debian and Ubuntu split sites across sites-available, while RHEL systems use conf.d/ssl.conf. Check which file Apache actually loads with apachectl -S, which lists every VirtualHost and the file it came from.

Never share your private keyAnyone with the .key file can impersonate your site. Keep it at 600 permissions, out of the web root, and out of version control.

If Apache will not start at all, check the error log before anything else: sudo tail -50 /var/log/apache2/error.log on Debian and Ubuntu, or /var/log/httpd/error_log on RHEL. The log usually names the exact directive and line number.

The bottom line

For most Apache sites, Certbot is the right answer: one command installs a free certificate, configures the VirtualHost, adds the redirect and sets up renewal. A manual install is only a few steps more — copy the three files, point the VirtualHost at them, test, and reload.

Whichever route you take, finish the job by verifying with an independent check. Run the free SSL checker on your domain, confirm the redirect works, and make sure renewal is scheduled.

For a broader look at keeping a site safe, see our guide to securing your Wi-Fi.

The small-business cybersecurity checklist covers the other basics worth fixing in the same session.

Frequently asked questions

How do I install an SSL certificate on Apache step by step?

Enable mod_ssl, get a certificate from Let's Encrypt or a commercial CA, copy the certificate, chain and private key to the server, add them to a VirtualHost on port 443 with SSLEngine on, run apachectl configtest, reload Apache, and redirect HTTP traffic to HTTPS.

What is mod_ssl in Apache?

mod_ssl is the Apache module that adds SSL and TLS support. It relies on OpenSSL for cryptography and provides directives such as SSLEngine, SSLCertificateFile and SSLProtocol. On Debian and Ubuntu it ships with Apache and is enabled with a2enmod ssl; on RHEL and CentOS it is a separate package installed with dnf install mod_ssl.

Where do I put the SSL certificate files on Apache?

Common locations are /etc/ssl/certs/ and /etc/apache2/ssl/ on Debian and Ubuntu, and /etc/pki/tls/certs/ on RHEL and CentOS. The private key must be readable only by root, so set its permissions to 600. Never place the key inside the public web root.

How long does a Let's Encrypt certificate last?

Let's Encrypt certificates are valid for 90 days. Certbot sets up automatic renewal, usually through a systemd timer that checks twice a day and renews certificates within 30 days of expiry. Test renewal with sudo certbot renew --dry-run.

Why is my Apache site still showing not secure after installing the certificate?

The usual causes are a missing or wrong intermediate chain, the VirtualHost listening on the wrong port, mixed content loading over HTTP, or Apache not being reloaded after the change. Check the chain with an SSL checker, confirm the VirtualHost uses port 443, and reload Apache.

Do I need to redirect HTTP to HTTPS on Apache?

Yes, for most sites. Without a redirect, visitors who type the plain HTTP address stay on an unencrypted connection. Add a redirect in the port 80 VirtualHost or use Certbot's redirect option, then test that the plain address lands on the secure address.

Which TLS versions should Apache use?

Allow only TLS 1.2 and TLS 1.3, for example with SSLProtocol -all +TLSv1.2 +TLSv1.3. TLS 1.0 and 1.1 are obsolete and should be disabled. Mozilla's SSL configuration generator publishes tested intermediate and modern profiles you can copy.

Sources

  1. Apache HTTP Server — mod_ssl documentation
  2. DigitalOcean — How To Secure Apache with Let's Encrypt on Ubuntu
  3. SSL Dragon — How to Install an SSL Certificate on Apache
  4. Mozilla — SSL Configuration Generator
  5. Let's Encrypt — How It Works
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the Apache mod_ssl documentation, DigitalOcean's Let's Encrypt guide for Apache, and Mozilla's SSL configuration guidance.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free