Setting up https with Apache

Been months since I wanted to do this.

I always thought that setting up https with Apache was very complicated. Specially because of the certificates.

For the last couple of days I’ve been working on setting up a linux server. It would be used for hosting a couple of pages so I need it to have the basic functionality like smtp, pop, imap, http and ssh as well as a couple of other things like memcached.

I had set up httpd before but honestly never https because I thought it was very difficult but it isn’t!!!

Things are really really simple, follow these simple steps once you have httpd running:

1.Install mod_ssl for apache

yum install mod_ssl

2.Restart httpd

service httpd restart

Now you have https available with a default certificate! so the next step would be creating your own certificate

3. Run the following command

openssl req $@ -new -x509 -days 365 -nodes -out /var/www/html/certs/mycert.pem -keyout /var/www/html/certs/mycert.pem

Remeber to change the path to your certificate or copy it later to the httpd certificate’s path.

You’ll be asked for some info.

4. Open ssl.conf (In my case, I have a Centos 5 distro, it’s the following path: /etc/httpd/conf.d/ssl.conf) and search for the following line:

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

Replace the path with your own certificate’s path.

Comment the following line:

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

5.Now restart httpd

Done! you have https running on port 443 with your own certificate.

Remember the certificate is valid for your site but since it’s not registered with an authority browsers will keep sending a warning.

Tags: , ,

Comments are closed.