1

I am using the php server from windows cmd. I generated ssl certificate and key using openssl. and started a php server by using the command provided below. but still https is not working. server is starting with the http protocol. I want to use the https protocol with these self signed certificate in php server.

php -S localhost:8000 -t "C:/Users/Pro/Desktop/Web Development/php" -d "C:\Program Files\OpenSSL-Win64\bin\openssl.cfg" -ssl "C:/Users/Pro/Desktop/Web Development/php/openssl/server.crt" -ssl-key "C:/Users/Pro/Desktop/Web Development/php/openssl/server.key"

this is the command.

  • Does this answer your question? [openSSL not working with PHP built-in webserver](https://stackoverflow.com/questions/12946486/openssl-not-working-with-php-built-in-webserver) – M. Eriksson Apr 16 '23 at 15:37
  • And this: [PHP builtin server + SSL](https://stackoverflow.com/questions/53322705/localhost-server-with-php-and-ssl). Where did you get the `-ssl` and `-ssl-key` options from? – M. Eriksson Apr 16 '23 at 15:40
  • chat gpt suggested these commands. but it didn't work accurately or maybe there is some other reason. When trying to open some files on that PHP server this only shows the SSL certificate data and doesn't process any file. – Sharjeel Arain Apr 19 '23 at 07:42
  • I would recommend that you do more research than just asking ChatGPT. It can often point in the right direction, but you should always do more research and verify it's answers. Writing good prompts to get more accurate answers is a skill. If you do `php -h`, you get a list of arguments and options where `-ssl` and `-ssl-key` are not listed, which should be a red flag. If you simply google "php built-in server + ssl", you will get a bunch of questions/answers/articles about it. – M. Eriksson Apr 19 '23 at 10:05

2 Answers2

0

Maybe try adding stunnel3 -d 443 -r 8000? For example: php -S localhost:8000 -t "C:/Users/Pro/Desktop/Web Development/php" -d "C:\Program Files\OpenSSL-Win64\bin\openssl.cfg" -ssl "C:/Users/Pro/Desktop/Web Development/php/openssl/server.crt" -ssl-key "C:/Users/Pro/Desktop/Web Development/php/openssl/server.key" | stunnel3 -d 443 -r 8000

Natsuki.HX
  • 21
  • 5
0

I installed the stunnel latest version which is 5.69. Then I created the config file for stunnel and save this with stunnel.conf extension; Stunnel configuration for PHP built-in server

cert = C:/Users/Pro/Desktop/Web Development/php/openssl/server.crt
key = C:/Users/Pro/Desktop/Web Development/php/openssl/server.key
debug = 7
output = stunnel.log

[php-server]
accept = 443
connect = localhost:8000

  I started the PHP server with:
  • php -S localhost:8000 -t "C:/Users/Pro/Desktop/Web Development/php"

Started stunnel with:

  • stunnel "C:\Program Files (x86)\stunnel\config\stunnel.conf"

now I am listening to port localhost:443 and it is redirecting to port localhost:800:

  • https://localhost:443/1.php