An SSL certificate is an electronic ‘document’ that is used to bind together a public security key and a website’s identity information (such as name, location, etc.) by means of a digital signature. The ‘document’ is issued by a certificate provider such as GlobalSign, Verisign, GoDaddy, Comodo, Thawte, and others. For more information, visit the article: What is an SSL Certificate?
In this article we’re going to be covering how to create a self-signed SSL certificate and assign it to a domain in Apache. Self-signed SSL certificates add security to a domain for testing purposes, but are not verifiable by a third-party certificate provider. Thus, they can result in web browser warnings.
- These instructions are intended for creating a self-signed SSL certificate and assigning it to a domain in Apache.
- I’ll be working from a Liquid Web Core Managed CentOS 6.5 server, and I’ll be logged in as root.
First let’s view whether Apache 2 already has the SSL module loaded using information from our article on How to List Which Apache 2 Modules are Enabled on CentOS 6:
apachectl -M | grep ssl
The module is already loaded if the result of the above command is:
If it is not loaded, then it is possible that
yum -y install mod_ssl
And now we’ll restart Apache:
service httpd restart
Make a directory to store the certificate and the server key:
Generate the SSL via OpenSSL with the following command:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
The above command will generate a
writing new private key to ‘/etc/httpd/ssl/apache.key’
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) [XX]:US
State or Province Name (full name) :Michigan
Locality Name (eg, city) [Default City]:Lansing
Organization Name (eg, company) [Default Company Ltd]:Liquid Web
Organizational Unit Name (eg, section) :KB
Common Name (eg, your name or your server’s hostname) :kb.thebestfakedomainnameintheworld.com
Email Address :firstname.lastname@example.org
For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor
Now that the private key and associated CSR have been generated, we need to edit the SSL configuration file for Apache:
Find the section:
And add the following Virtual Host configuration on the next line:
Be sure to replace kb.thebestfakedomainnameintheworld.com with your fully qualified domain name or server IP address for your Virtual Host. Keep in mind, that the domain should be the same as the
Verify that the following variables are set appropriately in the same file:
Then exit and save the file with the command
Then restart Apache once more:
service httpd restart
In this tutorial my test domain was kb.thebestfakedomainnameintheworld.com, so I can now visit https://kb.thebestfakedomainnameintheworld.com to test the SSL certificate setup. Use https://yourdomain to test your new self-signed SSL certificate!