How to Create a SSL Certificate on Apache for Ubuntu 12.04

Step One—Activate the SSL Module

a2enmod ssl

Follow up by restarting Apache.

service apache2 restart

Step Two—Create a New Directory

mkdir /etc/apache2/ssl

Step Three—Create a Self Signed SSL Certificate

When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.

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

This command will prompt terminal to display a lists of fields that need to be filled in.

The most important line is “Common Name”. Enter your official domain name here or, if you don’t have one yet, your site’s IP address.

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Awesome Inc
Organizational Unit Name (eg, section) []:Dept of Merriment
Common Name (e.g. server FQDN or YOUR name) []:example.com                  
Email Address []:webmaster@awesomeinc.com

Step Four—Set Up the Certificate

nano /etc/apache2/sites-available/default

Change the port on the virtual host to 443, the default SSL port:

<VirtualHost *:443>
ServerName example.com

Replace example.com with your DNS approved domain name or server IP address (it should be the same as the common name on the certificate).

Add in the following three lines to the end of your virtual host configuration, and make sure that they match the extensions below:

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

Save and Exit out of the file.

Step Five—Activate the New Virtual Host

a2ensite default
service apache2 reload

From me:
After your apache2 reload, maybe any error message, like this :
"_default_ VirtualHost overlap on port 443, the first has precedence" ..

Solutions:

after installing ssl on ubuntu lucid, add this line

NameVirtualHost *:443

in

/etc/apache2/ports.conf
and restart apache2.

Sources: https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: