nginx PHP常見錯誤
1、php7.0-fpm.sock許可權不足:
[crit] 3182#3182: *20 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied)
2、webroot路徑不對:
[error] 3147#3147: *10 FastCGI sent in stderr: "Unable to open primary script: /etc/nginx/html/index.php (No such file or directory)" while reading response header from upstream
PHP7安裝
刪除PHP7
apt-get autoremove --purge php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-gd php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-sqlite3
安裝PHP7
apt-get install php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-gd php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-sqlite3
修改php.ini
vi /etc/php/7.0/fpm/php.ini
設定 cgi.fix_pathinfo = 0
修改www.conf
vi /etc/php/7.0/fpm/pool.d/www.conf
把listen.mode = 0660
改成 listen.mode = 0666
php7.0-fpm.sock
預設(0660)許可權
$ls -al /run/php/php7.0-fpm.sock
srw-rw---- 1 www-data www-data 0 Mar 22 13:17 php7.0-fpm.sock
php7.0-fpm.sock
(0666)許可權
$ls -al /run/php/php7.0-fpm.sock
srw-rw-rw- 1 www-data www-data 0 Mar 22 13:17 php7.0-fpm.sock
重啟系統,這樣 /run/php/php7.0-fpm.sock
檔案才會根據0666
許可權重新生成
nginx PHP配置
location ~ .php$ {
root /your/web/root/document //必填,否則$document_root會是預設值/etc/nginx/html
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
相應的錯誤可以在Nginx的日誌/var/log/nginx/error.log
中看到