You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下PHP内置服务器使用自签名SSL证书无法建立HTTPS连接

解决PHP内置服务器无法启用HTTPS的问题

问题诊断

你的命令存在两个关键错误,导致HTTPS无法生效:

  • 未指定HTTPS协议前缀:仅写localhost:8000会默认走HTTP,必须明确指定https://localhost:8000
  • SSL参数格式错误:PHP内置服务器的SSL参数是双横线的--ssl和--ssl-key,而非单横线;另外-d参数用于设置PHP配置项,不需要指定OpenSSL配置文件路径,这一步属于多余操作

正确启动命令

将命令修改为以下格式(保留你的实际文件路径):

php -S https://localhost:8000 -t "C:/Users/Pro/Desktop/Web Development/php" --ssl "C:/Users/Pro/Desktop/Web Development/php/openssl/server.crt" --ssl-key "C:/Users/Pro/Desktop/Web Development/php/openssl/server.key"

验证步骤

  1. 执行修改后的命令,命令提示符会显示类似PHP 8.x.x Development Server (https://localhost:8000) started的提示,说明HTTPS已正常启动
  2. 打开浏览器访问https://localhost:8000,由于是自签名证书,浏览器会弹出安全警告,选择「高级」->「继续访问」即可正常访问HTTPS站点

内容的提问来源于stack exchange,提问作者Sharjeel Arain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 22:29:54