Sometimes, for a quick and very small project development we need a secure localhost connection.
As you might know, there is a built-in web server in PHP. The very simple command looks like:
# php -S 127.0.0.1:81
After running this command, the website will be available under the http://127.0.0.1:81/
url.
But, what if we want to access this url via HTTPS protocol.
The one solution on Windows I found is next:
- Download
stunnel
from https://www.stunnel.org/downloads.html - Install it
- open configuration file
stunnel.conf
from[installation path]\stunnel\config\
directory - At the end of the file put the next part of the code:
[https]
accept = 82
connect = 81
cert = stunnel.pem
5. Save the configuration file and restart the program.
6. Run php built-in server: php -S 127.0.0.1:81
7. Access the local website via: https://127.0.0.1:82/
and accept the NET::ERR_CERT_AUTHORITY_INVALID
– the SSL connection warning.
Update:
If installed through the brew
, create configuration file located here: /opt/homebrew/etc/stunnel/stunnel.conf
P.S. Don’t forget that all this is for development purposes only!
@source:
https://www.stunnel.org/docs.html
https://www.php.net/manual/en/features.commandline.webserver.php
This does not work in windows.
Actually, based on my experience I made this post and I’ve used this successfully.. only insecure connection warning might be annoying.. maybe I could help you?