How do I allow HTTPS for Apache on localhost?
I've just attempted this - I needed to test some development code on my localhost Apache on Windows. This was WAAAY more difficult than it should be. But here are the steps that managed to work after much hairpulling...
I found that my Apache install comes with openssl.exe
which is helpful. If you don't have a copy, you'll need to download it. My copy was in Apache2\bin
folder which is how I reference it below.
Steps:
- Ensure you have write permissions to your Apache conf folder
- Open a command prompt in
Apache2\conf
folder - Type
..\bin\openssl req -config openssl.cnf -new -out blarg.csr -keyout blarg.pem
You can leave all questions blank except:
- PEM Passphrase: a temporary password such as "password"
- Common Name: the hostname of your server
When that completes, type
..\bin\openssl rsa -in blarg.pem -out blarg.key
Generate your self-signed certificate by typing:
..\bin\openssl x509 -in blarg.csr -out blarg.cert -req -signkey blarg.key -days 365
Open Apache's
conf\httpd.conf
file and ensure SSL module is enabled - there should be no hash at the start of this line:LoadModule ssl_module modules/mod_ssl.so
Some Apache installations place the SSL config in a separate file. If so, ensure that the SSL conf file is being included. In my case I had to uncomment this line:
Include conf/extra/httpd-ssl.conf
In the SSL config
httpd-ssl.conf
I had to update the following lines:- Update
SSLSessionCache "shmcb:C:\Program Files (x86)\Zend\Apache2/logs/ssl_scache(512000)"
to
SSLSessionCache "shmcb:C:/Progra\~2/Zend/Apache2/logs/ssl_scache(512000)"
(The brackets in the path confuse the module, so we need to escape them) DocumentRoot
- set this to the folder for your web filesServerName
- the server's hostnameSSLCertificateFile "conf/blarg.cert"
SSLCertificateKeyFile "conf/blarg.key"
- Update
Restart Apache.
- Try loading
https://localhost/
in your browser.
Hopefully you made it this far. Feel free to update this post with any other helpful info.
(Screenshots courtesy of Neil Obremski and his helpful article - although now quite out-of-date.)
I use ngrok (https://ngrok.com/) for this. ngrok is a command line tool and create a tunnel for localhost. It creates both http and https connection.After downloading it, following command needs to be run :
ngrok http 80
( In version 2, the syntax is : ngrok http 80 . In version 2, any port can be tunneled. )
After few seconds, it will give two urls :
http://a_hexadecimal_number.ngrok.comhttps://a_hexadecimal_number.ngrok.com
Now, both the urls point to the localhost.
here is simplest way to do this
first copy these server.crt & server.key files (find in attachment ) into your apache/conf/ssl directory
then open httpd.conf file & add following line
Listen 80Listen 443NameVirtualHost *:80NameVirtualHost *:443<VirtualHost *:443> DocumentRoot "d:/wamp/www" #your wamp www root dir ServerName localhost SSLEngine on SSLCertificateFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.crt" SSLCertificateKeyFile "d:/wamp/bin/apache/Apache2.4.4/conf/ssl/server.key"</VirtualHost>