How to Generate SSL Certificate and Enable HTTPS in WAMP Server

How to Generate SSL Certificate and Enable HTTPS in WAMP Server

In this guide, I will explain how to generate an SSL certificate using OpenSSL and enable HTTPS on your WAMP (Windows, Apache, MySQL, PHP) server. This will allow you to access your local websites securely over SSL.

Step 1: Generate SSL certificate using OpenSSL

Make sure you have WAMP Server installed on your computer.

Add the OpenSSL bin directory to the system’s PATH variable:

  • Open the system’s Environment Variables settings.
  • Under the “System variables” section, find the “Path” variable and click on “Edit”.
  • Add the path to the OpenSSL bin directory (e.g., C:\wamp64\bin\apache\apache2.4.27\bin) at the end of the “Variable value” field.
  • Click “OK” to save the changes.

Open a command prompt (CMD) and navigate to your user directory where you want to generate the SSL certificate. You can do this by running the following command:

cd C:\Users\%YOUR_USERNAME%

Create a new directory named .openssl by running the following command:

mkdir .openssl

Navigate to the newly created .openssl directory by running the following command:

cd .openssl

Generate the private key and the certificate files by running the following commands in the command prompt:

openssl genrsa -aes256 -out private.key 2048 openssl rsa -in private.key -out private.key openssl req -new -x509 -nodes -sha1 -key private.key -out certificate.crt -days 36500 -config c:\wamp64\bin\apache\apache2.4.27\conf\openssl.cnf

This will generate a private key file named private.key and a certificate file named certificate.crt. Make sure to answer the questions during the certificate generation process, with “localhost” as the FQDN (Fully Qualified Domain Name).

Step 2: Configure WAMP Server to use the SSL certificate

Copy the generated private.key and certificate.crt files from the .openssl directory to the C:\wamp64\bin\apache\apache2.4.27\conf\key\ directory. If the key directory doesn’t exist, create it.

Open the httpd.conf file located in the C:\wamp64\bin\apache\apache2.4.27\conf\ directory.

Uncomment the following lines by removing the # character at the beginning of each line:

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

Open the httpd-ssl.conf file located in the C:\wamp64\bin\apache\apache2.4.27\conf\extra\ directory.

Update the following configuration parameters based on your setup:

  • DocumentRoot: Set it to the directory where your web files are located (e.g., c:/wamp64/www).
  • ServerName: Set it to localhost:443.
  • ServerAdmin: Set it to your email address.
  • SSLCertificateFile: Set it to the path of the certificate.crt file.
  • SSLCertificateKeyFile: Set it to the path of the private.key file.

If you have multiple virtual hosts, you can add them in the httpd-ssl.conf file using the provided configuration template.

Save the changes and close the file.

Step 3: Test and Restart WAMP Server

Open a command prompt and navigate to the directory where WAMP Server is installed (e.g., C:\wamp64\bin\apache\apache2.4.27\bin).

Run the following command to test the configuration:httpd -t This command will check if there are any syntax errors in the Apache configuration files. If everything is fine, you will see a “Syntax OK” message.

Restart the WAMP Server from the system tray icon to apply the configuration changes.

Step 4: Access your local websites over HTTPS

Open a web browser and enter https://localhost or https://example.com (replace example.com with your virtual host’s ServerName or ServerAlias) in the address bar.

You may see a warning in the browser indicating that the certificate is not valid. This is because the certificate is self-signed. Add an exception for the certificate in your browser to proceed.

Congratulations! You have successfully generated an SSL certificate and enabled HTTPS on your WAMP Server. Now you can access your local websites securely over SSL.

Please note that this certificate is self-signed and will not be trusted by browsers. It is intended for local development purposes only. In a production environment, you should obtain a valid SSL certificate from a trusted certificate authority (CA).

If you found this guide helpful, consider buying me a coffee. Thank you!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *