Home > Backend Development > PHP7 > body text

Ubuntu16.04 PHP7 installation and Nginx PHP

藏色散人
Release: 2023-02-17 12:36:01
forward
2551 people have browsed it

nginx PHP common errors

1. Insufficient permissions for php7.0-fpm.sock:

[crit] 3182#3182: *20 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied)
Copy after login

2. Wrong webroot path:

[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
Copy after login

PHP7Install

Delete 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
Copy after login

Install 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
Copy after login

Modify php .ini

vi /etc/php/7.0/fpm/php.ini
Copy after login

Set cgi.fix_pathinfo = 0

Modify www.conf

vi /etc/php/7.0/fpm/pool.d/www.conf
Copy after login

Change listen.mode = 0660 to listen .mode = 0666

php7.0-fpm.sock default (0660) permissions

$ls -al /run/php/php7.0-fpm.sock
srw-rw----  1 www-data www-data   0 Mar 22 13:17 php7.0-fpm.sock
Copy after login

php7.0-fpm.sock(0666) permissions

$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
Copy after login

Restart the system, In this way, the /run/php/php7.0-fpm.sock file will be regenerated according to the 0666 permission

nginx PHP configuration

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;
    }
Copy after login

The corresponding error can be found in Nginx See

in the log /var/log/nginx/error.log

The above is the detailed content of Ubuntu16.04 PHP7 installation and Nginx PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!