ubuntu16.04 PHP7安装与Nginx PHP

前端之家收集整理的这篇文章主要介绍了ubuntu16.04 PHP7安装与Nginx PHP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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中看到

原文链接:https://www.f2er.com/ubuntu/349813.html

猜你在找的Ubuntu相关文章