# 在自己家目录下创建www目录[root@localhost ~]# mkdir www[root@localhost ~]# cd www/# 创建几个php脚本用于测试index.phpinfo.php# 启动一个Web服务器[root@localhost www]# php -S 192.168.204.151:8000# 注意:因为我是采取虚拟机中Linux,所以这里直接使用了ip,如果是本地win下,可以直接localhost:8000
请求http://192.168.204.151:8000/,返回效果如下
请求http://192.168.204.151:8000/info.php,返回效果如下

# 在~/www下创建一个test目录,并添加php脚本文件(~/www/test/index.php)mkdir ~/www/test # 启动web[root@localhost www]# php -S 192.168.204.151:8000 -t test/
访问测试

# 先创建一个router.php
[root@localhost www]# vi router.php
[root@localhost www]# cat router.php
<?php
if (preg_match('/\\.(?:png|jpg|jpeg|gif|txt)$/', $_SERVER["REQUEST_URI"]))
return false; // 直接返回请求的文件
else {
echo "<p>Welcome to PHP</p>";
}
# 创建一个txt文件或者图片
[root@localhost www]# ll
-rw-r--r-- 1 root root 31 12月 4 10:56 hello.txt 测试用
-rw-r--r-- 1 root root 65 12月 4 10:35 index.php
-rw-r--r-- 1 root root 17 12月 4 10:36 info.php
-rw-r--r-- 1 root root 177 12月 4 10:55 router.php
drwxr-xr-x 2 root root 23 12月 4 10:49 test
# 启动web
[root@localhost www]# php -S 192.168.204.151:8000 router.php
# 请求需要经过router.php处理
直接请求192.168.204.151:8000/
请求一个txt文件,返回改文件的内容
关于通过PHP内置web服务器实现简单的调试应用的文章就分享到这,如果对你有帮助欢迎继续关注我们哦
本文来自投稿,不代表重蔚自留地立场,如若转载,请注明出处https://www.cwhello.com/42123.html
如有侵犯您的合法权益请发邮件951076433@qq.com联系删除