Skip to content

Instantly share code, notes, and snippets.

@LaChouetteInformatique
Forked from danieldogeanu/WampHTTPS.md
Created April 14, 2023 12:42
Show Gist options
  • Save LaChouetteInformatique/1c6201b019973dd0a86e5acc640ab0d4 to your computer and use it in GitHub Desktop.
Save LaChouetteInformatique/1c6201b019973dd0a86e5acc640ab0d4 to your computer and use it in GitHub Desktop.
How to enable HTTPS for WAMP Server.

After you've downloaded and installed WAMP Server, follow these steps:

  1. Generate SSL certificate using OpenSSL:
  • Add C:\wamp64\bin\apache\apache2.4.27\bin directory to the PATH so you can access openssl command from the command prompt (WAMP comes with its own version of OpenSSL already integrated, so you don't need to install it. You'll find it in this directory.).

    IMPORTANT: Please note that the path of your installation depends on your version of Apache! DO NOT copy and paste the paths presented in this gist as they will not match with yours!

  • Navigate to your user directory (C:\Users\%YOUR_USERNAME%\), create a new folder (.openssl), navigate to it with Powershell and run these commands:

    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
    
  • You can pretty much answer the questions any way you want though real answers are best. The one question that really matters here is the FQDN. It should be: localhost.

  1. Copy the generated private.key and certificate.crt files from C:\Users\%YOUR_USERNAME%\.openssl to the C:\wamp64\bin\apache\apache2.4.27\conf\key\ folder. If the key folder doesn't already exist, create it.

  2. Using a text editor, open C:\wamp64\bin\apache\apache2.4.27\conf\httpd.conf and un-comment following 3 lines:

    LoadModule ssl_module modules/mod_ssl.so
    Include conf/extra/httpd-ssl.conf
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
    
  3. Now open C:\wamp64\bin\apache\apache2.4.27\conf\extra\httpd-ssl.conf and apply the following changes below the <VirtualHost _default_:443> line. Check the following parameters to ensure they are configured correctly and not commented:

    DocumentRoot "c:/wamp64/www"
    ServerName localhost:443
    ServerAdmin admin@example.com
    SSLSessionCache "shmcb:${SRVROOT}/logs/ssl_scache(512000)"
    ErrorLog "${SRVROOT}/logs/error.log"
    TransferLog "${SRVROOT}/logs/access.log"
    SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
    SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"
    
  4. You can add your virtual hosts in the same file (C:\wamp64\bin\apache\apache2.4.27\conf\extra\httpd-ssl.conf) by adding the following configuration below the closing </VirtualHost>, for each virtual host:

    <VirtualHost _default_:443>
     
    DocumentRoot "d:/dev/example"
    ServerName example.com:443
    ServerAlias example.org
    ServerAdmin admin@example.com
    ErrorLog "${SRVROOT}/logs/error.log"
    TransferLog "${SRVROOT}/logs/access.log"
    
    SSLEngine on
    SSLCertificateFile "${SRVROOT}/conf/key/certificate.crt"
    SSLCertificateKeyFile "${SRVROOT}/conf/key/private.key"
    
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    
    <Directory "d:/dev/example">
        SSLOptions +StdEnvVars
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        Require all granted
        AllowOverride All
    </Directory>
    
    BrowserMatch "MSIE [2-5]" \
             nokeepalive ssl-unclean-shutdown \
             downgrade-1.0 force-response-1.0
    
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    </VirtualHost>
    
  5. You're done! Now, to check the validity of the file, type httpd -t in your command prompt. It will show you if there's any syntax errors. If eveything is fine, restart your WAMP Server and go to https://localhost or https://example.com or whatever virtual hosts you may have.

Please note that you'll get a warning in the browser saying that the certificate is not valid! This is perfectly normal, as the certificate is self-signed. Just add an exception for it and save it in your browser.

Please also note that you can't use valid SSL certificates generated with Let's Encrypt or other free SSL service, because you need to own the domain name that you're trying to validate. These instructions are for localhost development only, we don't need valid certificates for that.

If this was useful, you can buy me a coffee here. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment