How to prepare Local HTTPS Server via PHP built-in server using Stunnel on Windows

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:

  1. Download stunnel from https://www.stunnel.org/downloads.html
  2. Install it
  3. open configuration file stunnel.conf from [installation path]\stunnel\config\ directory
  4. 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

2 thoughts on “How to prepare Local HTTPS Server via PHP built-in server using Stunnel on Windows

    1. 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?

Leave a Reply