Apache 2: Self-Signed Certificates

Self-signed certificates are very useful when doing testing on your local machine. The following was tested using a unix based environment.

Generate the Key and Certificate

First we generate the private key


openssl genrsa -des3 -out server.key 1024

Then we create a certificate signing request


openssl req -new -key server.key -out server.csr

We make sure that everytime we start the apache server, we don’t have to type the passphrase


cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

Lastly we self-sign the certificate


openssl x509 -req -days 365 -in server.csr -signkey server.key -out               server.crt

Configure the Apache Server

Edit your apache’s httpd.conf and uncomment the following lines (just search it in the file)


LoadModule ssl_module modules/mod_ssl.so

#PATH MAY DIFFER TO YOUR SETUP

Include conf/extra/httpd-ssl.conf

Next edit your apache’s httpd-ssl.conf, search for the following configuration item: SSLCertificateFile & SSLCertificateKeyFile, change it to where your server.crt and server.key files are located respectively (absolute path!)

Finally if you’re using VirtualHost it is important to declare two NameVirtualHost (one for port 80 and port 443). Example:


NameVirtualHost 127.0.0.1:80

NameVirtualHost 127.0.0.1:443

<VirtualHost 127.0.0.1:80>

ServerName local.example.com

DocumentRoot /path/to/your/example.com/www

</VirtualHost>

<VirtualHost 127.0.0.1:443>

ServerName local.example.com

DocumentRoot /path/to/your/example.com/www

SSLEngine on

SSLCertificateFile /path/to/your/server.crt

SSLCertificateKeyFile /path/to/your/server.key

</VirtualHost>

Save and restart your Apache server!

  • Share/Bookmark
1 Comment

One Comment

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>