Last Updated on April 1, 2023 by Freddy Reyes
This post outlines how to swiftly enable SSL for an Apache web server on Linux or a Raspberry Pi.
- Begin by creating a directory to store the encryption certificates:
sudo mkdir /etc/apache2/ssl
- Generate the certificates, valid for 3 years (1095 days):
sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
This command generates the following output:
Generating a 2048 bit RSA private key
...
writing new private key to '/etc/apache2/ssl/server.key'
...
Enter the required information when prompted.
- Install SSL for Apache:
sudo a2enmod ssl
- Edit the default Apache site (using
sudo nano /etc/apache2/sites-enabled/000-default-ssl.conf
) and add these lines:
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
- Restart Apache:
sudo /etc/init.d/apache2 restart
And that’s it!