How to generate a self signed SSL certificate.


Of course you should never use a self signed SSL certificate in production, however this can be useful for testing and development. Consider buying a real certificate.

Simply follow the following steps. I've assumed you are already in the /etc/apache2/ssl/ directory, or you are going to save elsewhere and update the relevant lines below.

And, if not obvious, replace [arbitrary_name] with your domain or development host name.

  1. Generate the key
openssl genrsa -out [arbitrary_name].key 2048
  1. Generate the certificate
openssl genrsa -out [arbitrary_name].key 2048
  1. Add the following block to your virtual hosts file if you're running apache
<VirtualHost [arbitrary_name]:443>
    ServerName [arbitrary_name]

    SSLEngine on
    SSLCertificateKeyFile /etc/apache2/ssl/[arbitrary_name].key
    SSLCertificateFile /etc/apache2/ssl/[arbitrary_name].cert
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

    # ...
</VirtualHost>

Note, you will have to enable SSL by running:

 sudo a2enmod ssl