not logged in | [Login]

How To Create an SSL Certificate on Apache, commands, and file locations


  • Restart Apache: sudo service apache2 restart
  • Reload Apache Config: sudo /etc/init.d/apache2 reload
  • Enable Apache Site: sudo a2ensite
  • Disable Apache Site: sudo a2dissite
  • Show Request Assignments: apache2ctl -S
  • Show Error Messages: systemctl status apache2.service


  • Site Configs: /etc/apache2/sites-available
  • Ports file: /etc/apache2/ports.conf
  • Log location: /var/log/apache2

How To Create an SSL Certificate on Apache

Activate the SSL module and restart Apache

sudo a2enmod ssl
sudo service apache2 restart

Now, create the self-signed certificate

sudo mkdir /etc/apache2/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Configure Apache to Use SSL.

Open your sites Apache conf:

sudo vim /etc/apache2/sites-available/<your site conf>.conf

And add something very similar to this:

<VirtualHost *:443>
    # The ServerName is very important. That is how apache decides which VirtualHost to use!
    ServerAdmin webmaster@localhost

    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

    <Location />
        Order deny,allow
        Allow from all

    ErrorLog /var/log/apache2/
    LogLevel info
    CustomLog /var/log/apache2/ combined

Finally, enable and activate:

sudo a2ensite <your site>.conf
sudo service apache2 restart