Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Created April 25, 2014 05:41
Show Gist options
  • Save ChengLong/11278721 to your computer and use it in GitHub Desktop.
Save ChengLong/11278721 to your computer and use it in GitHub Desktop.
Install SSL certificate on Ubuntu for Apache

I found many misleading guides on how to install SSL certificate so that both http and https can work for the same site. Below are the step by step instructions

  1. Enable mod_ssl, sudo a2enmod ssl
  2. Put your certificate in /etc/ssl/certs/example.com.crt. Other directory may work, but I prefer this.
  3. Put your key in /etc/ssl/private/example.com.key. Other directory may work, but I prefer this.
  4. Add a new virtual host for https, e.g.
    <VirtualHost *:443>
        DocumentRoot /path/to/project
        ServerName example.com
        DirectoryIndex index.html
    
        <Directory /path/to/directory>
          DirectoryIndex index.html
          Options FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all
       </Directory>
    
       SSLEngine on
       SSLCertificateFile /etc/ssl/certs/example.com.crt
       SSLCertificateKeyFile /etc/ssl/private/example.com.key
    </VirtualHost>
    
  5. Restart Apache sudo apache2ctl restart

Both http://example.com and https://example.com should work now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment