Home > Article > Backend Development > Implement simple debugging applications through PHP built-in web server
Recommended: "PHP Video Tutorial"
Because I often execute some PHP code snippets, or temporary projects, etc. for testing and office environment In the virtual machine, I don’t want to destroy the office environment for some personal tests;
Therefore, you can install only one PHP locally in win (the installation is omitted), or Linux in the virtual machine Install PHP to run the test task; (it is recommended to use the Linux method in the virtual machine)
Remind again that this method is only used for local testing;
# 在自己家目录下创建www目录 [root@localhost ~]# mkdir www [root@localhost ~]# cd www/ # 创建几个php脚本用于测试 index.php info.php # 启动一个Web服务器 [root@localhost www]# php -S 192.168.204.151:8000 # 注意:因为我是采取虚拟机中Linux,所以这里直接使用了ip,如果是本地win下,可以直接localhost:8000
Request http://192.168.204.151:8000/, the return effect is as follows
Request http://192.168.204.151:8000/info.php, the return effect is as follows
Specify a root directory when starting
# 在~/www下创建一个test目录,并添加php脚本文件(~/www/test/index.php)mkdir ~/www/test # 启动web[root@localhost www]# php -S 192.168.204.151:8000 -t test/
Access test
Specify a script, Use it as a router
# 先创建一个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处理
to directly request 192.168.204.151:8000/
to request a txt file and return the content of the changed file
Summary: Using this method is more convenient for individuals when doing tests. If there are any errors, please correct them!
The above is the detailed content of Implement simple debugging applications through PHP built-in web server. For more information, please follow other related articles on the PHP Chinese website!