Tip:本文並不是是配置的流程指導文件,只是錯誤解決方案的提示及建議php
一、mac自帶apache、php環境,須要先關閉,php默認相關環境(包含原來的php-fpm相關文件都清理掉,默認目錄:/private/etc/php-fpm.conf)最好刪除掉(可自行google下)html
二、建議經過brew安裝管理nginx,默認網站根目錄: /usr/local/var/wwwnginx
brew install nginxapache
配置nginx解析php(注意這裏我設置的是9090端口,由於本身的9000端口衝突了,須要配置相應php-fpm.conf):bash
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;php7include fastcgi_params; }三、經過brew安裝管理php7.2
(注意安裝後提示操做:
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profileideexport LDFLAGS="-L/usr/local/opt/php@7.2/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.2/include"
)
brew install php@7.2php-fpm
四、啓動nginx、php(以root的方式啓動)網站
sudo brew services start nginxgoogle
sudo brew services start php@7.2
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
五、若是報錯請查看日誌文件:
日誌: /usr/local/var/log
nginx服務錯誤提示在其中nginx文件夾error.log中,php-fpm.log則顯示php進程相關狀態問題
六、幾個常見掉報錯處理:
(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;