Skip to content

Apache HTTP Server has served websites for a very long time, and many hosting accounts and company servers still run it. Installing an SSL certificate on it follows the same logic as on any other web server: Apache needs the certificate, any intermediate certificates and the matching private key, and it needs to be told to listen on port 443 with TLS switched on.

The details differ from the Nginx process in file layout and directive names, and they differ a little between Debian-style and Red Hat-style systems. This guide covers the common case, explains what each part does, and lists the mistakes that most often cause browser warnings after the work is finished. If you manage your server through a control panel instead of editing files, the companion article on installing SSL via Plesk shows the same job done through a web interface.

What you need before you start

Gather and check the following before editing any configuration:

  1. The server certificate, issued for the exact hostnames visitors use. Open it with openssl x509 -in cert.crt -noout -text and read the Subject Alternative Name list to confirm which names it covers.
  2. The intermediate certificates, usually supplied by the issuer as a "CA bundle". Without them some browsers and many non-browser clients cannot build a path from your certificate to a trusted root.
  3. The private key created with your certificate request. It must match the certificate; if you have lost it, the certificate cannot be used and you need to request a new one.
  4. Administrator access to the server, and port 443 open in the firewall and any cloud security group.

It also helps to know which Apache version you have. Run apache2 -v or httpd -v. Behaviour around the chain directive changed in Apache 2.4.8, which is why many tutorials contradict each other.

Step 1: Enable the SSL module

Apache handles TLS through mod_ssl. Check whether it is loaded:

  • On Debian and Ubuntu, run sudo a2enmod ssl. This enables the module and its default settings; the service must be reloaded afterwards.
  • On Red Hat style systems such as AlmaLinux or Rocky Linux, install the package with sudo dnf install mod_ssl. It adds a file named ssl.conf under /etc/httpd/conf.d/ that already contains a sample HTTPS virtual host.

You can confirm the module is active with apachectl -M | grep ssl, which should list ssl_module.

Step 2: Place the certificate files safely

Copy the files to the server with scp or sftp. Do not send private keys by email or chat. Good locations are:

  • Debian and Ubuntu: certificates in /etc/ssl/certs/ and keys in /etc/ssl/private/.
  • Red Hat style: certificates in /etc/pki/tls/certs/ and keys in /etc/pki/tls/private/.

Set permissions so the key is readable only by root (mode 600). The certificate files are public and can be readable by everyone (mode 644). Apache reads them as root when it starts or reloads, before worker processes drop privileges, so this arrangement works on a normal installation.

If your issuer gave the certificate and intermediates as separate files, you have two choices. In current Apache (2.4.8 and later) you can append the intermediates to the certificate file, server certificate first:

cat example.com.crt intermediate.crt > example.com-fullchain.crt

On older versions you keep the files separate and use SSLCertificateChainFile. That directive is deprecated in newer releases, so avoid mixing the two approaches in one configuration.

A frequent point of confusion: SSLCACertificateFile and SSLCACertificatePath exist for verifying client certificates. They are not the place to put your issuer's intermediate bundle for normal website HTTPS.

Step 3: Configure the HTTPS virtual host

Create or edit the virtual host that handles port 443. On Debian-style systems, the default file is /etc/apache2/sites-available/default-ssl.conf or one you create for your domain. On Red Hat style systems, add a block to a file in /etc/httpd/conf.d/.

A minimal example:

# Opening line: VirtualHost for *:443 (angle brackets omitted in this article)
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

    SSLEngine on
    SSLCertificateFile    /etc/ssl/certs/example.com-fullchain.crt
    SSLCertificateKeyFile /etc/ssl/private/example.com.key

    SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
# Closing line: end of the VirtualHost block

The role of each line:

Directive Purpose
VirtualHost block for *:443 Applies the settings to HTTPS connections on port 443.
ServerName / ServerAlias The hostnames this site answers; they should match the certificate.
SSLEngine on Switches TLS on for this virtual host. Forgetting it is a classic mistake.
SSLCertificateFile Your server certificate, with intermediates appended on current versions.
SSLCertificateKeyFile The matching private key.
SSLProtocol Which protocol versions are allowed; older insecure ones are excluded.

On Debian-style systems, after saving a new site file, enable it with sudo a2ensite default-ssl (or your file name). Cipher suites can usually stay at the defaults of a current Apache and OpenSSL. If you want to understand what modern protocol versions require, the TLS 1.3 specification is the authoritative text.

Step 4: Redirect HTTP to HTTPS

Visitors who type the bare domain, or follow an old link, arrive at port 80. Add or edit the port 80 virtual host so it sends them to the secure address:

# Opening line: VirtualHost for *:80 (angle brackets omitted in this article)
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/
# Closing line: end of the VirtualHost block

The Redirect permanent directive sends a 301 response and appends the requested path automatically. If you prefer rewrite rules, enable mod_rewrite and use a rule that preserves the request URI. For a simple site the plain Redirect is easier to read and less likely to loop.

If you also redirect www to the bare domain or the reverse, decide on one canonical address and keep the redirect to a single hop. Chains of redirects slow pages down and confuse some tools.

Step 5: Test, reload and verify

Before touching the running service, test the configuration:

sudo apachectl configtest

On Debian-style systems the command may be apache2ctl configtest. You want to see Syntax OK. Common problems and what they usually mean:

Message Likely cause
Invalid command 'SSLEngine' mod_ssl is not loaded.
AH02565: Certificate and private key ... do not match The key does not belong to the certificate.
unable to load certificate or No such file Wrong path or unreadable file.
Address already in use Another service uses port 443, or a duplicate Listen 443 line exists.

When the test passes, apply the change with sudo systemctl reload apache2 (Debian style) or sudo systemctl reload httpd (Red Hat style). A reload applies new settings gracefully, so active requests can finish.

Now verify from outside. Open the site in a browser and inspect the padlock details for issuer and validity dates. From another computer run:

openssl s_client -connect example.com:443 -servername example.com

Look at the chain in the output. You should see your certificate and then the intermediate, and a verification result that reports success. Also test the redirect with curl -I http://example.com/, which should show a 301 response and a Location header pointing at https.

A plain example

Consider a small association website on a shared company server, domain club.example.org, running Apache on Debian.

  1. The administrator receives club.example.org.crt and ca-bundle.crt. The private key has been kept since the request.
  2. They join the two certificate files with the server certificate first, and save the result in /etc/ssl/certs/. The key goes into /etc/ssl/private/ with mode 600.
  3. They run a2enmod ssl, create the port 443 virtual host with the three SSL directives, and enable it with a2ensite.
  4. They add the port 80 virtual host with Redirect permanent.
  5. apache2ctl configtest prints Syntax OK; they reload Apache.
  6. From a phone on mobile data, they open the site, check the padlock, and follow a deep link to confirm the redirect keeps the path.

Doing the final check from a different network matters because it removes the chance that the server's own caches or hosts file hide a problem.

Limits and what to watch for

Name mismatch. If the certificate does not list the hostname the visitor typed, the browser will warn even though the installation is technically correct. Check ServerName, ServerAlias and the certificate's name list together. Choosing which names to cover is a topic of its own; the WordPress guide touches on it for sites that have changed domains or added a www version.

Mixed content. Pages that load images, scripts or styles over HTTP show warnings or have resources blocked. Search your templates, plugins and database for hard-coded http:// addresses and update them.

Several sites on one address. Apache uses Server Name Indication to select the right virtual host and certificate. Each HTTPS virtual host needs its own ServerName and its own certificate directives. If every visitor sees the first site's certificate, a missing or duplicated ServerName is the usual reason.

Renewal. A renewed certificate is a new file, often with a new intermediate. Rebuild the chain file, keep the matching key, run the configuration test and reload. If you create a new key for the renewal, update SSLCertificateKeyFile too.

HSTS. The Strict-Transport-Security header can be added with Header always set once the mod_headers module is enabled. It makes browsers refuse plain HTTP for a period. Add it only after everything works over HTTPS, and start with a short duration because mistakes are slow to reverse.

Backups and key handling. Keep an encrypted backup of the certificate, chain and key. Never commit private keys to a code repository or leave them in a folder that the web server publishes.

Control panels overwrite files. If a panel manages your server, editing configuration files by hand may be overwritten the next time the panel regenerates them. Use the panel's own certificate screen in that case, as described in the Plesk guide.

A short troubleshooting checklist

  1. Run the configuration test again and read the first error, not the last.
  2. Check the error log, for example /var/log/apache2/error.log or /var/log/httpd/error_log.
  3. Confirm that mod_ssl is loaded and that SSLEngine on appears inside the 443 virtual host.
  4. Confirm that the certificate begins the file and that the intermediate follows it.
  5. Compare the public key fingerprints from the certificate and the key to make sure they belong together.
  6. Test from another network and with a private browser window to avoid cached errors.
  7. Check the server clock. A wrong date can make a valid certificate appear expired or not yet valid.

Choosing between reload and restart

Apache offers both, and the difference matters on a live site. A graceful reload tells the parent process to read the new configuration and start new workers while the old ones finish their current requests. A full restart stops everything first, so visitors in the middle of a download or checkout may see an error. Use reload for certificate changes in almost every case. Keep restart for situations where a module change does not take effect after a reload, or when the service has stopped responding.

It is also sensible to keep a copy of the previous working configuration before you edit it. If the new virtual host fails the configuration test, you can restore the old file in seconds and the site stays online, because Apache keeps running with the configuration it loaded earlier until you reload.

Summary

To install an SSL certificate on Apache, enable mod_ssl, store the certificate, intermediates and private key with sensible permissions, create a port 443 virtual host with SSLEngine on and the certificate and key directives, add a permanent redirect on port 80, run apachectl configtest, reload, and verify from another network. Watch for name mismatches, mixed content, renewal steps and the expiry date. When you are ready to pick or renew a certificate, the SSL page lists what is currently available.

Frequently asked questions

Which Apache directives point to the certificate and key?

SSLCertificateFile points to your server certificate, and SSLCertificateKeyFile points to the private key. The intermediate certificates can be appended to the certificate file in current Apache releases, or supplied with the older SSLCertificateChainFile directive on versions that still need it.

Do I need mod_ssl?

Yes. Apache serves HTTPS through the mod_ssl module. On Debian and Ubuntu you enable it with a2enmod ssl; on Red Hat style systems it is installed as a separate package and loaded by the ssl.conf file.

How do I check my Apache configuration before reloading?

Run apachectl configtest (or apache2ctl configtest). It reports Syntax OK when the files parse correctly. Always do this before reloading a live site.

Why does the browser say the certificate chain is incomplete?

The intermediate certificate is missing or in the wrong order. Make sure the server certificate comes first, followed by the intermediate certificates, and that the file is referenced correctly.

How do I send visitors from HTTP to HTTPS?

Add a virtual host on port 80 that issues a permanent redirect to the https address, using the Redirect directive or a rewrite rule. Test it with a browser and with a command line request to confirm the 301 status.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Need an SSL certificate?

Pick the certificate type that fits your site and see the price before you check out.

SSL from $14.99

See SSL certificates

Keep reading

SSL Guides

How to Install an SSL Certificate on Nginx

A practical walkthrough for installing an SSL certificate on Nginx, from preparing the files to testing the configuration, redirecting HTTP and verifying the result.

10 min read

SSL Guides

How to Install an SSL Certificate via Plesk

A step-by-step guide to installing an SSL certificate in Plesk, from creating the request or uploading files to assigning the certificate, redirecting HTTP and checking the result.

9 min read

SSL Guides

How to Install SSL on a WordPress Website

A practical walkthrough for moving WordPress to HTTPS: installing the certificate, updating URLs, fixing mixed content, redirecting and checking the result.

10 min read