前言
在学习php的时候,遇到了一个花了好几个小时才解决的坑,在这里先粗略的记录下。
nginx配置
我的nginx配置文件目录是 /usr/local/etc/nginx
nginx我使用的是默认的,没有做任何更改,查看nginx.conf,倒数第二行是这样写的
```
include servers/*;
```
由于我要配置多站点,所以创建了servers/nginx-test.conf(servers 目录不要创建任何不符合nginx语法的文件,否则,启动nginx会报错)
/usr/local/etc/nginx/servers/nginx-test.conf
```
server {
listen 80; # 监听端口
server_name kutu.com; # 站点域名
root /Users/huansnow/Documents/php_work/phpinfo; # 站点根目录
# PHP配置
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
index index.php index.html index.htm;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_log /usr/local/etc/nginx/log/test.log error;
```
fastcgi_pass 这个配置需要启动php-fpm的, 找不到php-fpm文件可以使用
```
find / -name 'php-fpm'
```
查找
执行php-fpm
报错
```
[07-Aug-2019 06:17:24] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
[07-Aug-2019 06:17:24] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
[07-Aug-2019 06:17:24] ERROR: FPM initialization failed
```
到/private/etc/ 复制一份
```
cd /private/etc/
cp php-fpm.conf.defaul php-fpm.conf
```
又有报错!!!!!
```
[06-Aug-2019 22:21:33] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125.
[06-Aug-2019 22:21:33] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
[06-Aug-2019 22:21:33] ERROR: failed to post process the configuration
[06-Aug-2019 22:21:33] ERROR: FPM initialization failed
```
修改php-fpm.conf
```
error_log = /usr/local/etc/nginx/log/php-fpm.log
```
又又又报错
```
[06-Aug-2019 22:26:44] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125.
[06-Aug-2019 22:26:44] ERROR: No pool defined. at least one pool section must be specified in config file
[06-Aug-2019 22:26:44] ERROR: failed to post process the configuration
[06-Aug-2019 22:26:44] ERROR: FPM initialization failed
```
继续百度
```
cd /etc/php-fpm.d
sudo cp www.conf.default www.conf
sudo php-fmp
```
终于ok
启动nginx
```
#检测ngixn配置
nginx -t
#启动
nginx
#停止
nginx -s stop
#重启
nginx -s reload
```
访问站点发现访问php文件都404,
查看日志都是
```
2019/08/06 13:42:09 [error] 31423#0: *435 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: kutu.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "kutu.com"
2019/08/06 13:42:09 [error] 31423#0: *435 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: kutu.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "kutu.com"
```
然后百度解决,发现大部分都是博客都抄来抄去,根本没法解决问题,后来有人提到可能是目录权限问题
于是将 /Users/huansnow/Documents/php_work/phpinfo 从根目录开始每个开始全都改成777
```
chmod 777 目录
```
文章仅做个人解决问题记录,没啥参考意义
网友评论