Throughout my web development career, I have worked on different projects some are big, some are small. Sometimes I have to work on web servers (production servers) that come with SSL enabled to use the HTTPS protocols and whereas my local development machines use HTTP, and this makes my development system different from the production one. But as a developer, I am sure that every developer always like to have an exact environment like the production system. So here is the step-by-step tutorial on how I installed self-created SSL certificate on my local WAMP server to use HTTPS communication.
Step 1: Download and Install WAMP(Windows machine)
Download & install WAMP (Assuming that WAMP is installed, in my case, it’s on G:/ drive, I did it because I prefer to separate my projects from other files )
Step 2: Download OpenSSL (32 bits/64 bits Windows)
Step 3: Configure WAMP to use HTTP+SSL=HTTPS
Extract the downloaded OpenSSL zip file in step 2 and Copy/Replace following files to the destination given below. It is best practice to take a backup before making any changes.
Path to openssl.exe : G:\wamp\bin\apache\apache2.4.23\bin\openssl.exe Path to libeay32.dll : G:\wamp\bin\apache\apache2.4.23\bin\libeay32.dll Path to ssleay32.dll : G:\wamp\bin\apache\apache2.4.23\bin\ssleay32.dll Path to openssl.cnf : G:\wamp\bin\apache\apache2.4.23\conf\openssl.cnf
Step 4: Create SSL Key and Certificate
Now we will generate a private key which is 2048bits encryption. “localhost_ssl.key” will be our key file. So to do that we need open the command-prompt and “Run as Administrator”. Type the following command to go to the bin folder.
Once we are in the “bin” directory type the following command. You will prompt to enter a pass-phrase (password) and also ask to verify the phrase, just enter any password you like. e.g. “localhost”
openssl genrsa -aes256 -out server.key 2048
Now we will remove the pass phrase from the RSA private key. We will also take a backup copy of the original file. It’ll ask you the passphrase that was entered on the previous command, so just type it.
copy server.key server.key.backup openssl rsa -in server.key.backup -out server.key
Now we will generate a self-signed certificate, which will be used to certify the connection for encrypted traffic. “localhost_certificate.crt” will be our certificate. This is a single line command.
openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt -config G:\wamp\bin\apache\apache2.4.23\conf\openssl.cnf
Step 5: Copy the Created SSL Key and Certificate file
Now, create a folder “sslkeycert“at: “G:\wamp\bin\apache\apache2.4.23\conf” and copy “server.key” and “server.crt” to “sslkeycert” folder.
Step 6: Open httpd.conf, php.ini & uncomment
Open “httpd.conf” in a text editor, located at “G:\wamp\bin\apache\apache2.4.23\conf\httpd.conf“.
LoadModule ssl_module modules/mod_ssl.so Include conf/extra/httpd-ssl.conf LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
Open “php.ini” in a text editor located at “G:\wamp\bin\php\php5.6.25\php.ini“. You may find this uncommented.
Step 7: Open httpd-ssl.conf and make the final changes
Open “G:\wamp\bin\apache\apache2.4.23\conf\extra\httpd-ssl.conf“, find “<VirtualHost _default_:443>” and below that line find and update below configuration according to your setup:
- Change “DocumentRoot …” → DocumentRoot “G:/wamp/www“
- Change “ServerName…” → ServerName “localhost:443“
- Change “ErrorLog….” → Errorlog “G:/wamp/bin/apache/apache2.4.23/logs/sslerror.log“
- Change “TransferLog ….” → TransferLog “G:/wamp/bin/apache/apache2.4.23/logs/sslaccess.log“
- Change “SSLCertificateFile ….” → SSLCertificateFile “G:/wamp/bin/apache/apache2.4.23/conf/sslkeycert/server.crt“
- Change “SSLCertificateKeyFile ….” → SSLCertificateKeyFile “G:/wamp/bin/apache/apache2.4.23/conf/sslkeycert/server.key“
- On the same file replace ‘<Directory “c:/Apache24/cgi-bin”>‘ with ‘<Directory “G:/wamp/www”>’
- On the same file Change “CustomLog….” → CustomLog “G:/wamp/bin/apache/apache2.4.23/logs/ssl_request.log“
Step 8: Test to make sure it works!
Now go back to command prompt window, from the G:\wamp\bin\apache\apache2.4.23\bin type the following and check if you are getting Syntax is OK
Now restart all the services in WAMP server and try to load https://localhost/