Install an SSL Certificate on WAMP (Enable Secure HTTPS)

SSL was developed by Netscape to enable secure communication when clients and servers exchange sensitive or private information. Learn in this post how to create and set up an SSL certificate on a WAMP server.

Install an SSL Certificate on WAMP

What is an SSL Certificate and how it works?

An SSL (Secure Sockets Layer) helps to establish a secure communication connection by enabling HTTPS on the local web server. It enables us to securely connect to the server instead of using the HTTP protocol. The following is a general overview of how an SSL certificate works.

  • Whenever a client tries to establish a secure connection with a server (SSL-enabled), it sends all the encryption methods it can support to the server.
  • The server will then choose the strongest encryption method both ends can support. The server will send back a certificate with a public key. This certificate should be signed by a known CA (Certificate Authority) to be credible.
  • The client then receives the certificate along with the public key and generates a new session key encrypted with the public key sent by the server. If the client can not match the key sent by the server, it will use OCSP (Online Certificate Status Protocol) to validate the certificate.
  • After creating a new session key, the client sends this session key to the server to establish a successful handshake.
 

How to Set up an SSL Certificate on WAMP?

The process of WAMP SSL setup involves the following steps:

  1. Generate an SSL private key and remove the passphrase from it.
  2. Generate an SSL certificate.
  3. Move the SSL key and certificate to a specific location.
  4. Configure http-ssl.conf settings.
  5. Configure httpd.conf settings.

Step 1: Generate SSL Private Key

The first step to open the command prompt and go to this location C:\wamp\bin\apache\apache2.4.51\bin and open openssl.exe to run OpenSSL commands.

Create a key for our certificate using the following command:

genrsa -des3 -out domain.key 2048

After pressing the Enter key, it will ask to enter a passphrase. We can enter anything as a passphrase, like a password, but we have to remember it. Next, let's remove the passphrase from our key. To do that, type the following command and press Enter.

rsa -in domain.key -out domain.key
 

Step 2: Generate SSL Certificate

Now that we have removed the passphrase from our key, it is time to create our self-signed certificate, and to do that, type the following command and press Enter.

req -new -x509 -nodes -sha1 -key domain.key -out domain.crt -days 365 -config C:\wamp\bin\apache\apache2.4.51\conf\openssl.cnf

It will ask to enter information about the certificate, like country name, province, company name, company unit, and email address.

 

Step 3: Move The SSL Key and SSL Certificate

After following the above steps, we will see two files, "domain.key" and "domain.crt" generated in C:\wamp\bin\apache\apache2.4.51\bin. Copy them and go to C:\wamp, and create a folder "ssl", and paste these two files in this folder. Then, create another folder "logs" in the same location, where we will store all our transaction logs in this folder.

 

Step 4: Configure http-ssl.conf

After we have created our certificate files and placed them in the right location, we are ready to configure http-ssl. Go to location C:\wamp\bin\apache\apache2.4.51\conf and open http-ssl.conf file. Find these lines:

SSLSessionCache "shmcb:C:/Program Files/Apache Software Foundation/Apache2.4/logs/ssl_scache(512000)"

And replace with:

SSLSessionCache "shmcb:C:/wamp/logs/ssl_scache(512000)"

Next, find these lines:

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.4/htdocs"
ServerName localhost:443
ServerAdmin admin@localhost
ErrorLog "C:/Program Files/Apache Software Foundation/Apache2.4/logs/error_log"
TransferLog "C:/Program Files/Apache Software Foundation/Apache2.4/logs/access_log"

And replace with:

DocumentRoot "C:/wamp/www"
ServerName localhost:443
ServerAdmin admin@localhost
ErrorLog "C:/wamp/logs/ssl_error.log"
TransferLog "C:/wamp/logs/ssl_access.log"

Next, fine these lines:

SSLCertificateFile "C:/Program Files/Apache Software Foundation/Apache2.4/conf/server.crt"

And replace with:

SSLCertificateFile "C:/wamp/ssl/domain.crt"

Next, find this line to set our key file:

SSLCertificateKeyFile "C:/Program Files/Apache Software Foundation/Apache2.4/conf/server.key"

And replace with:

SSLCertificateKeyFile "C:/wamp/ssl/domain.key"

Next, find this line:

CustomLog "C:/Apache24/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

And replace with:

CustomLog "C:/wamp/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" 
 

Step 5: Configure httpd.conf

The next step is to configure our httpd.conf. Go to this location C:\wamp\bin\apache\apache2.4.51\conf, and open httpd.conf file. Find these lines and remove the comment "#" from the beginning of each line:

#LoadModule ssl_module modules/mod_ssl.so
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
#Include conf/extra/httpd-ssl.conf

All done! We just enabled SSL on a WAMP server with self-generated certificate. All we need to do is restart the WAMP server and open the URL https://localhost in the browser.

NOTE: So far, it should be working, still if you face any issues, go to this location C:\wamp\bin\apache\apache2.4.51\bin and copy libeay32.dll and ssleay32.dll and paste them into C:\Windows\System32