Self signed Apache hosted SSL as fast as possible on Ubuntu

 This is a quick guide to setting up SSL using a self signed certificated for all those odd development reasons you need https for on a development machine.


Environment

First get your environment ready (i.e. installed). You will need openssl installed which can be installed in ubuntu via apt:

sudo apt install openssl

Self signed certificate

Next get yourself a self signed SSL certificate. Our aim here is to create 2 files, a CRT file and a KEY file.

This can be done by running openssl at the command line (or sudo openssl in restricted directories) then paste the following:

req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

Press return and ignore all steps. There is no value to a self signed certificate in the public domain. 

Note: change days if you want more than a year.

Please remember this is for development purposes so certificates should never make it to the public domain and therefore security of the certificate only needs to be enough to pass the basics (i.e. apache knows its a certificate and is happy to use it)

Apache SSL

Next enable SSL with the following command

sudo a2enmod ssl

Finally, we can add the configuration to the virtual host configuration file. If you are running a single domain, add it to the bottom of 000-default.conf and replace ServerName with the domain you will be accessing it with.

And lastly, make sure the full route to the certificate file is added


<VirtualHost *:443>
ServerName site.local
DocumentRoot /var/www/public

<Directory /var/www/public>
Options All
AllowOverride All
</Directory>

SSLEngine On
SSLCertificateFile /var/ssl/certificate.crt
SSLCertificateKeyFile /var/ssl/privateKey.key
</VirtualHost>

Comments