Apache: Install Self-Signed Certificate

When developing a website and having to test notifications or webcam access in the browser you require a TLS connection. A self signed certificate is the solution here!

# Generate certificates
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

# Enable ssl in Apache
sudo a2enmod ssl

Add the following to your virtual host file:

SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

Make sure your virtual host is listening on port 443. Change: <VirtualHost *:80> to <VirtualHost *:80 *:443>.

And restart Apache:

sudo service apache2 restart