Quickly Enable SSL for Apache Web Server on Linux or Raspberry Pi: A Step-by-Step Guide

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.

  1. Begin by creating a directory to store the encryption certificates:
sudo mkdir /etc/apache2/ssl
  1. 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.

  1. Install SSL for Apache:
sudo a2enmod ssl
  1. 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
  1. Restart Apache:
sudo /etc/init.d/apache2 restart

And that’s it!