How to Install an SSL Certificate on Apache (Ubuntu, Debian and AlmaLinux)

Installing an SSL certificate on Apache

How to Install an SSL Certificate on Apache (Ubuntu, Debian and AlmaLinux)

Enable mod_ssl, create a 443 virtual host and redirect HTTP to HTTPS on Ubuntu, Debian or AlmaLinux, with fixes for common errors.

To install an SSL certificate on Apache, enable mod_ssl, create a virtual host on port 443 that points SSLCertificateFile at your certificate chain and SSLCertificateKeyFile at your private key, test the configuration, and reload Apache. The steps differ slightly between Ubuntu or Debian and AlmaLinux, so both are covered below.

This guide is for Cloud VPS Hosts customers running Apache 2.4 on Ubuntu 22.04, Ubuntu 24.04, Debian 12 or AlmaLinux 8 and 9. It applies to RapidSSL, GeoTrust and DigiCert certificates from our store.

What do you need before you start?

You need your private key, your issued certificate and the intermediate certificate on the server, plus SSH access with sudo.

  • Your private key from the CSR step. If you have not generated a CSR yet, start with How to generate a CSR.
  • Your certificate file, for example example_com.crt.
  • The intermediate certificate, for example DigiCertCA.crt.
  • Apache already serving your site on port 80.

You can download the issued certificate files at any time from your certificate’s page under Services > My Services in the client area.

Where should the certificate files go?

Use the standard locations for your distribution. They already have the right permissions, and on AlmaLinux they carry the right SELinux labels.

File Ubuntu and Debian AlmaLinux
Certificate and chain /etc/ssl/certs/ /etc/pki/tls/certs/
Private key /etc/ssl/private/ /etc/pki/tls/private/
Site configuration /etc/apache2/sites-available/ /etc/httpd/conf.d/
Service name apache2 httpd

Upload the certificate and intermediate with scp, or create each file with sudo nano and paste the text including the BEGIN and END lines. Then lock down the key:

sudo chmod 600 /etc/ssl/private/example.com.key        # Ubuntu and Debian
sudo chmod 600 /etc/pki/tls/private/example.com.key    # AlmaLinux

How do you build the chain file?

Since Apache 2.4.8, SSLCertificateFile can hold your certificate followed by the intermediate, so one combined file is all you need. Put your certificate first:

cd /etc/ssl/certs        # or /etc/pki/tls/certs on AlmaLinux
sudo sh -c 'cat example_com.crt DigiCertCA.crt > example.com.chained.crt'

Check that the certificate belongs to your key. Both commands must print the same value:

openssl x509 -noout -modulus -in example_com.crt | openssl md5
sudo openssl rsa -noout -modulus -in /etc/ssl/private/example.com.key | openssl md5

How do you install the certificate on Ubuntu and Debian?

Enable the SSL module, create an SSL virtual host, enable it and reload Apache.

1. Enable mod_ssl

sudo a2enmod ssl

2. Create the SSL virtual host

sudo nano /etc/apache2/sites-available/example.com-ssl.conf

Add the following, changing the domain and document root to match your site:

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

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

    SSLProtocol -all +TLSv1.2 +TLSv1.3

    ErrorLog ${APACHE_LOG_DIR}/example.com-ssl-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-ssl-access.log combined
</VirtualHost>

If your port 80 virtual host has <Directory> rules or PHP-FPM handlers, copy them into this block too.

3. Enable the site, test and reload

sudo a2ensite example.com-ssl.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Reload only after configtest prints “Syntax OK”. If UFW is active, allow HTTPS with sudo ufw allow 'Apache Full'.

How do you install the certificate on AlmaLinux?

Install mod_ssl, add the virtual host in conf.d, open the firewall and reload httpd.

1. Install mod_ssl

sudo dnf install mod_ssl -y

This also creates /etc/httpd/conf.d/ssl.conf with a default virtual host that uses a self-signed test certificate. Leave it in place. Your own virtual host with a matching ServerName takes priority for your domain.

2. Create the SSL virtual host

sudo nano /etc/httpd/conf.d/example.com-ssl.conf
<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

    SSLEngine on
    SSLCertificateFile    /etc/pki/tls/certs/example.com.chained.crt
    SSLCertificateKeyFile /etc/pki/tls/private/example.com.key

    SSLProtocol -all +TLSv1.2 +TLSv1.3

    ErrorLog logs/example.com-ssl-error.log
    CustomLog logs/example.com-ssl-access.log combined
</VirtualHost>

3. Restore SELinux labels and open the firewall

Files copied in from another folder can keep the wrong SELinux label, and Apache then cannot read them. Reset the labels and allow HTTPS through firewalld:

sudo restorecon -Rv /etc/pki/tls
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

4. Test and reload

sudo apachectl configtest
sudo systemctl reload httpd

How do you redirect HTTP to HTTPS on Apache?

Add a permanent redirect to your existing port 80 virtual host. It needs no extra modules:

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

Run the configtest again, then reload Apache.

How do you check that SSL is working?

Visit https://example.com and check the padlock, then confirm the chain from the command line:

openssl s_client -connect example.com:443 -servername example.com </dev/null | grep -E "subject=|issuer=|Verify return code"

“Verify return code: 0 (ok)” means browsers will trust the certificate. The free Qualys SSL Labs test gives a full report. The Apache mod_ssl how-to covers more advanced options.

How do you fix errors when you install an SSL certificate on Apache?

Error Likely cause Fix
Invalid command 'SSLEngine' mod_ssl is not enabled or installed Run sudo a2enmod ssl (Ubuntu, Debian) or sudo dnf install mod_ssl (AlmaLinux)
AH02565: Certificate and private key ... do not match Key belongs to a different CSR Run the modulus check and reissue with the right CSR if needed
Browser shows the self-signed test certificate Your virtual host is not loaded, or ServerName does not match Check sudo apachectl -S for the 443 virtual hosts
Permission denied reading the key on AlmaLinux Wrong SELinux label Run sudo restorecon -Rv /etc/pki/tls
Some devices say the certificate is not trusted Intermediate missing from the chain file Rebuild the chain file with your certificate first, then the intermediate

Hosting several Apache sites on one server? A Linux VPS gives you full root access for as many virtual hosts as your plan’s resources handle, and a Wildcard SSL certificate covers every subdomain with one install.

Frequently asked questions

Do I still need SSLCertificateChainFile?

No. It was deprecated in Apache 2.4.8. Put the intermediate certificate in the same file as your certificate and point SSLCertificateFile at it, as shown above.

Does reloading Apache take my site offline?

No. A reload applies the new configuration without dropping active connections. Always run the configtest first, because a broken configuration can stop Apache from starting.

How often do I have to replace the certificate?

DigiCert certificates issued since March 15, 2026 are valid for up to 199 days. Before expiry, reissue from the client area, replace the certificate and chain files, and reload Apache. Keeping the same file names means you never have to touch the virtual host again.

My server uses cPanel, Plesk or DirectAdmin. Is this guide for me?

No. Those panels manage Apache’s configuration and overwrite manual changes. Install the certificate through the panel’s own SSL/TLS section instead.

Post Your Comment

Knowledgebase
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.