Tip:本文并非是配置的流程指导文件,只是错误解决方案的提示及建议
1、mac自带apache、php环境,需要先关闭,php默认相关环境(包含原来的php-fpm相关文件都清理掉,默认目录:/private/etc/php-fpm.conf)最好删除掉(可自行google下)
2、建议通过brew安装管理nginx,默认网站根目录: /usr/local/var/www
brew install nginx
配置nginx解析php(注意这里我设置的是9090端口,因为自己的9000端口冲突了,需要配置相应php-fpm.conf):
location ~ .php$ {
root /usr/local/var/www;
fastcgi_pass 127.0.0.1:9090;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params; }
3、通过brew安装管理php7.2
(注意安装后提示操作:
echo ‘export PATH="/usr/local/opt/[email protected]/bin:$PATH"‘ >> ~/.bash_profile
echo ‘export PATH="/usr/local/opt/[email protected]/sbin:$PATH"‘ >> ~/.bash_profileexport LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
)
brew install [email protected]
4、启动nginx、php(以root的方式启动)
sudo brew services start nginx
sudo brew services start [email protected]
ps
(1)如果后面报错可以查看管理员是否有权限添加:
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx
sudo chmod u+s/usr/local/opt/nginx/bin/nginx
(2)关于php-fpm.pid的问题:
默认,配置文件中pid配置是注释的,也就是未指定pid生成的位置。不会按默认路径自动生成,所以也就不存在php-fpm.pid文件。如果启动掉时候需要我们动手来配置:
a、找到/usr/local/etc/php/7.2/php-fpm.conf,添加
pid = /usr/local/var/run/php-fpm/php-fpm.pid
b、创建文件,并设置权限,保证php-fpm的用户有权限修改它
touch?/usr/local/var/run/php-fpm/php-fpm.pid
chown www?/usr/local/var/run/php-fpm/php-fpm.pid // 假定php-fpm的用户是 ‘www‘
chmod 644?/usr/local/var/run/php-fpm/php-fpm.pid
c、重新启动php-fpm
(3)php-fpm线程端口掉设置问题(防止端口冲突,有可能需要替换掉)
a、在php-fpm.conf包含的www.conf,listen = 127.0.0.1:9090
b、记得在nginx.conf中掉php解析部分做相应的端口设置
2)创建文件,并设置权限,保证php-fpm的用户有权限修改它
(4)想将php-fpm配置成:php-fpm.sock(没有尝试过)
只需要将:listen = 127.0.0.1:9000 修改成:listen = /usr/local/var/run/php-fpm/php-fpm.sock
5、如果报错请查看日志文件:
日志: /usr/local/var/log
nginx服务错误提示在其中nginx文件夹error.log中,php-fpm.log则显示php进程相关状态问题
6、几个常见掉报错处理:
(1)open() "/usr/local/Cellar/nginx/1.15.12/html/favicon.ico" failed
解决:在nginx.conf配置文件中添加
location = /favicon.ico { log_not_found off; access_log off; }
(2) kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client
解决:参看第3点(2)(3)中php-fpm.pid掉设置
(3)FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
解决:nginx.conf配置文件中
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
改为:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
原文地址:https://blog.51cto.com/13238147/2410509