Home > Backend Development > PHP Tutorial > Implement simple debugging applications through PHP built-in web server

Implement simple debugging applications through PHP built-in web server

藏色散人
Release: 2023-04-09 16:56:02
forward
3814 people have browsed it

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
Copy after login

Request http://192.168.204.151:8000/, the return effect is as follows
Implement simple debugging applications through PHP built-in web server
Request http://192.168.204.151:8000/info.php, the return effect is as follows

Implement simple debugging applications through PHP built-in web server

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/
Copy after login

Access test

Implement simple debugging applications through PHP built-in web server

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(&#39;/\.(?:png|jpg|jpeg|gif|txt)$/&#39;, $_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处理
Copy after login

to directly request 192.168.204.151:8000/
Implement simple debugging applications through PHP built-in web server
to request a txt file and return the content of the changed file
Implement simple debugging applications through PHP built-in web server

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!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template