update
This commit is contained in:
parent
7f64e2a9f8
commit
d2ee5ba336
@ -77,8 +77,65 @@ categories:
|
|||||||
|
|
||||||
最后打开要调试的文件,按`F5`就能断点调试啦.
|
最后打开要调试的文件,按`F5`就能断点调试啦.
|
||||||
|
|
||||||
注意要选择第二个调试配置,也就是`Launch currently open script`
|
注意要选择第一个调试配置,也就是`Listen for XDebug`.
|
||||||
|
|
||||||
![](https://raw.githubusercontent.com/FleyX/files/master/blogImg/20190523092530.png)
|
**注意并不是访问 xdebug 的端口来调试,而是需要访问 web 服务器的端口。并将 web 服务器的目录设置为当前开发的目录。(这个问题浪费了半天的时间)**
|
||||||
|
|
||||||
|
# 配置 rest 服务
|
||||||
|
|
||||||
|
php 不同于其他的后端语言,并不能监听某个端口,然后对请求做出响应。因此如果想用 php 搭建 rest 服务,就需要配置访问任意路径都有通过同一个 php 文件来处理请求。下面介绍几种配置方法:
|
||||||
|
|
||||||
|
## nginx 配置
|
||||||
|
|
||||||
|
```properties
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name example.com;
|
||||||
|
index index.php;
|
||||||
|
error_log /path/to/example.error.log;
|
||||||
|
access_log /path/to/example.access.log;
|
||||||
|
root /path/to/public;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri /index.php$is_args$args;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php {
|
||||||
|
try_files $uri =404;
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
include fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||||
|
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## apache 配置
|
||||||
|
|
||||||
|
确保.htaccess 文件和 index.php 在同一个目录中。然后在.htaccess 文件加入如下:
|
||||||
|
|
||||||
|
```properties
|
||||||
|
RewriteEngine On
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule ^ index.php [QSA,L]
|
||||||
|
```
|
||||||
|
|
||||||
|
此配置需要 Apache 启用 mod_rewrite 模块,并开启`AllowOverride All`配置。
|
||||||
|
|
||||||
|
## php 内置服务器
|
||||||
|
|
||||||
|
php 从 5.4.0 开始就自带一个内置服务器了,用于开发调试用,不能用于线上模式。通过如下命令启动:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
php -S localhost:8888 -t public
|
||||||
|
```
|
||||||
|
|
||||||
|
- -S 指定端口
|
||||||
|
- -t 指定根目录
|
||||||
|
|
||||||
|
详细可查看官方文档:[点击跳转](https://www.php.net/manual/zh/features.commandline.webserver.php)
|
||||||
|
|
||||||
**本文原创发布于:**[https://www.tapme.top/blog/detail/20190520](https://www.tapme.top/blog/detail/20190520)
|
**本文原创发布于:**[https://www.tapme.top/blog/detail/20190520](https://www.tapme.top/blog/detail/20190520)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user