ubuntu16.04 PHP7安装与Nginx PHP

时间:2020-8-5 作者:admin

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

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。