Introduction
Securing your website with SSL is critical for encryption and trust. This guide explains how to install SSL certificates on Apache for Debian-based and RPM-based systems.
Prerequisites
- Installed Apache server.
- SSL certificate files:
certificate.crt
,private.key
, andintermediate.crt
.
Enable SSL Module
# Debian-Based Systems
sudo a2enmod ssl
sudo systemctl restart apache2
# RPM-Based Systems
sudo yum install mod_ssl
sudo systemctl restart httpd
Configure Apache for SSL
Edit the following configuration files for your setup:
- Debian-Based:
/etc/apache2/sites-available/yourdomain.conf
- RPM-Based:
/etc/httpd/conf.d/ssl.conf
Modify the configuration to enable SSL:
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/private.key
SSLCertificateChainFile /path/to/intermediate.crt
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Enable Virtual Host
# Debian-Based
sudo a2ensite yourdomain.conf
sudo systemctl restart apache2
# RPM-Based
sudo systemctl restart httpd
Redirect HTTP to HTTPS
Add this block to redirect HTTP to HTTPS:
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
Restart Apache:
sudo systemctl restart apache2 # Debian-Based
sudo systemctl restart httpd # RPM-Based
Verify the Installation
Test your configuration using:
openssl s_client -connect www.example.com:443
Or use online tools like SSL Labs.