Skip to content

Instantly share code, notes, and snippets.

@danieldogeanu
Last active May 21, 2024 09:01
Show Gist options
  • Save danieldogeanu/081dc198a2d727afd6bf01174990ee8d to your computer and use it in GitHub Desktop.
Save danieldogeanu/081dc198a2d727afd6bf01174990ee8d 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!

@danieldogeanu
Copy link
Author

@niklasdahlheimer I thought that was obvious, but yeah, good point! I'll add a note! Glad you made it work!

@sdj72
Copy link

sdj72 commented Mar 26, 2024

Dear Daniel
when i run the openssl command in C:\Users\soren.openssl I get this: 'openssl' is not recognized as an internal or external command,
operable program or batch file.
running the commands from C:\wamp64\bin\apache\apache2.4.58\bin then i can run the commands, and when i run the command:
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
I get this error:
Error making certificate request
981A0000:error:04000067:object identifier routines:OBJ_txt2obj:unknown object name:crypto\objects\obj_dat.c:418:
981A0000:error:05800077:x509 certificate routines:X509_NAME_ENTRY_create_by_txt:invalid field name:crypto\x509\x509name.c:252:name=countryName_default

@danieldogeanu
Copy link
Author

@sdj72 You have to add openssl to the path. It's literally the first step! Read the instructions carefully!

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