WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Enable SSL for Localhost in WAMPServer

Edited 1 day ago by ExtremeHow Editorial Team

WAMPServerSSLSecurityLocalhostWindowsHTTPSConfigurationServerWeb DevelopmentApache

How to Enable SSL for Localhost in WAMPServer

This content is available in 7 different language

WAMPServer is a popular choice among developers for testing PHP applications on their local machines. It is a Windows-based stack that includes Apache, MySQL, and PHP. When developing applications, having SSL enabled on your localhost can be useful for a variety of reasons, including monitoring how your application behaves under HTTPS connections, handling secure cookies, or working with third-party libraries that require secure connections.

In this guide, we will learn how to enable SSL for localhost in WAMPServer. The process involves creating a self-signed SSL certificate and configuring the Apache server to use it for HTTPS connections. This is a comprehensive step-by-step tutorial that will cover all the necessary configurations.

Step 1: Create a self-signed SSL certificate

The first step to enabling SSL on your localhost is to create a self-signed SSL certificate. A self-signed certificate is suitable for development purposes where security is not a concern, and you don't want to purchase a certificate from a certificate authority.

To create a self-signed certificate, we will use OpenSSL, which is included with WAMPServer. Here are the steps:

  1. Open the WAMPServer menu from the taskbar and select “Open terminal” or “Open command window here”.
  2. Navigate to the Apache directory by running the following command: cd C:\wamp64\bin\apache\apacheX.XX\bin Replace apacheX.XX with your specific Apache version.
  3. Generate the private key by doing the following:
    OpenSSL genpkey -algorithm rsa -out localhost.key
  4. Next, create a certificate signing request (CSR) with this command:
    OpenSSL Request -new -key localhost.key -out localhost.csr
  5. When prompted, enter the required details. For the Common Name (CN), use localhost since we are creating this for local development.
  6. Finally, generate a self-signed certificate valid for 365 days:
    OpenSSL x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt

By the end of this process, you should have two files: localhost.key and localhost.crt, which represent the private key and certificate, respectively. These files will be used to configure Apache for SSL.

Step 2: Configure Apache for SSL

Once the SSL certificates are ready, the next step is to configure Apache in WAMPServer to use them for secure connections. This involves editing the Apache configuration files and ensuring that the SSL module is enabled.

Enable the SSL module

Before you configure Apache for SSL, make sure the SSL module is enabled. To do this, follow these steps:

  1. Open WAMPServer Manager, go to "Apache" > "Apache Modules".
  2. Scroll through the list and find ssl_module. Make sure it is checked or enabled.

Edit Apache Configuration

Now, let's modify the Apache configuration files to reference the SSL certificate we created.

  1. Go to your Apache configuration directory. Typically, it is located at C:\wamp64\bin\apache\apacheX.XX\conf.
  2. Open httpd.conf in a text editor and make sure the following line is not commented out:
    loadmodule ssl_module modules/mod_ssl.so
  3. Find the line:
    #include conf/extra/httpd-ssl.conf
    Uncomment it by removing the # symbol:
    include conf/extra/httpd-ssl.conf

Edit the SSL configuration file

Now open httpd-ssl.conf, which is located in conf/extra directory.

  1. Look at the section Defining VirtualHost for port 443.
  2. Modify the following lines to point to your newly created certificate and key files:
    SSLCertificateFile "C:/wamp64/bin/apache/apacheX.XX/bin/localhost.crt"
    SSLCertificateKeyFile "C:/wamp64/bin/apache/apacheX.XX/bin/localhost.key"

Make sure the paths refer to the location where you saved your localhost.crt and localhost.key files.

Step 3: Restart WAMPServer

After making configuration changes, restart WAMPServer to apply them. This is done by clicking the WAMPServer icon in the taskbar and selecting "Restart All Services".

Step 4: Access your site via HTTPS

After configuring your Apache server to handle SSL, you can now access your local project using HTTPS. Open a web browser and go to:

https://localhost

You may see a warning indicating that the connection is not private. This is expected since we are using a self-signed certificate. In a browser like Chrome, you can click "Advanced" and then "Proceed to localhost (unsecured)" to continue to your site.

Conclusion

Enabling SSL for localhost in WAMPServer involves several steps, including creation of a self-signed SSL certificate and modifying the Apache configuration. This setup is necessary to simulate a production-like environment on your local machine, especially when working with applications that require secure communications. By following this guide, you can now test HTTPS functionality in your local development environment.

If you find anything wrong with the article content, you can


Comments