Tutorial – Install SSL Certificate in Apache Virtual Host on CentOS 6

In this tutorial I’ll take you through installing a SSL certificate and intermediate certificate in an Apache virtual host running on CentOS 6.

You’ll need to generate your servers private key which is used to create your certificate signing request (CSR) and also matched to your public SSL certificate. The CSR contains the details about the domain name, your organisation and server details. The CSR is passed onto the company you wish to purchase your certificate from. They use your CSR to create the public SSL certificate that your users need to access your web services securely.

The public SSL certificate that you get created must then be copied onto your server. You’ll then configure Apache to load that SSL Certificate, along with an intermediate certificate if required, to provide secure access to your web services (typically a website).

[box type="info"] Just note that this document assumes CentOS 6 for all example code and references. Syntax, file locations and codes may vary based on your distribution.[/box]

Step 1: Setup Simple Directory Structure

I like to maintain a simple directory structure for my SSL certificates, you may skip this step however just make sure you substitute my directory paths with yours.

Step 2: Generate Servers Private Key

You may already have a private key created for your server, however I’d suggest creating a new one. This due to the fact that most CSR’s require 2048bit encoding.

[box type="warning"] Note, you can set a pass phrase on your certificate to make it more secure, however the downside to doing this is that you will be prompted for the password everytime Apache starts up. Securing the key via file system permissions and general server security is my recommendation.[/box]
Check the file was generated where you wanted it

Change the file permissions so that only the root user can read the file

Step 3: Generate the CSR

Now we can generate our CSR, the entry fields are self explanatory.

[box type="info"] If you are wanting to generate a wildcard certificate ie. secure all subdomains, then all you need to is enter *.website.com for the Common Name prompt[/box]
Lets have a look at what a CSR looks like.

Step 4: Generate your Public SSL Certificate

This step will vary depending on the vendor you use. However you will be required to provide a copy of your CSR (as seen above). You’ll need to copy/paste all lines including the BEGIN/END certificate request lines into your vendors request system. I’d suggest reading their examples of this process.

Once you’ve successfully submitted your CSR, your vendor will then provide you a SSL certificate. It may be attached to an email as a .crt file, or could just be text in the body of an email. If they have provided you with just text, then copy/paste the text (including the BEGIN/END lines) into file on your server. If it’s a file then copy it onto your server.

I’d suggest naming and placing the SSL certificate file into

If you received instructions to install an intermediate certificate, then copy it as

Step 5: Configure Apache to use SSL

In this example I’ll show you how to install the SSL certificate into an virtual host. So firstly we need to make sure Apache is configured to support port 443 for name-based virtual hosting.

You’ll need to make sure that the line “NameVirtualHost *:443″ exists in your Apache configuration file.

If the above command doesn’t return any result, then you’ll need to add “NameVirtualHost *:443″ into httpd.conf. Just search for NameVirtualHost and add it on the next line.

Now you’ll need to add a new entry that contains your virtual host configuration for SSL. I would suggest you simply copy/paste your existing VirtualHost configuration and simply modify the directive to be . Then within the context of your newly created directive add the additional SSL settings. See below for an example:

…Restart Apache and you’re done!!

[author] [author_image timthumb='on']http://mcdee.com.au/wp-content/uploads/2012/11/photo.jpg[/author_image] [author_info]Andrew McDonald is an IT Systems Admin and all round technology junkie. Absolutely a jack-of-all-trades and not one to shy away from a challenge.


 [/author_info] [/author]

Apache PHP-CGI SuExec Session Issues

After enabling php-cgi and suexec to handle your site in Apache, you may discover issues with your web applications working incorrectly. This could simply be a session issue which is result of the suexec user being unable to write into /var/lib/php/session directory.

[box type="info"] Just note that this document assumes CentOS 6 for all example code and references. Syntax, file locations and codes may vary based on your distribution.[/box]

You can verify this problem simply by looking websites error log.

First, lets identify the SuExec user configured for your site. Simply open your Apache configuration file and identify value set for “SuexecUserGroup”.

As you can see the value “user1″ has been set as the SuExec user. Now we need allow user1 access to the /var/lib/php/session directory. The simplest way to do this is to add user1 into the apache group. This is done by editing your /etc/group file and appending the line for the Apache group with your user.

Look for the apache group and append your user, save and close the file (:wq)

….and you’re done, you don’t even have to restart Apache.

[author] [author_image timthumb='on']http://mcdee.com.au/wp-content/uploads/2012/11/photo.jpg[/author_image] [author_info]Andrew McDonald is an IT Systems Admin and all round technology junkie. Absolutely a jack-of-all-trades and not one to shy away from a challenge.


 [/author_info] [/author]