Home>Article>Operation and Maintenance> How to solve nginx cannot start php

How to solve nginx cannot start php

WBOY
WBOY forward
2023-05-22 10:25:05 1800browse

Solution to nginx being unable to start php: 1. Find the nginx configuration file; 2. Add the content "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"; 3. Restart nginx.

nginx installation is complete and cannot parse php solution

After nginx is installed, it is found that php code cannot be parsed. The current solution is as follows

Method 1

Find the nginx configuration file, add the configuration as shown below (shown in the screenshot), the location of my configuration file is /etc/nginx/sites-available/default

location ~ \.php$ { root /var/www/html; include snippets/fastcgi-php.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

How to solve nginx cannot start php

After modifying the nginx configuration file, restart nginx to take effect

/etc/init.d/nginx restart

Method 2

nginx php fpm implementation

Install php7.4-fpm

sudo apt-get install php7.4-fpm

Check whether php-fpm is turned on

ps -ef|grep php

How to solve nginx cannot start php

Find php7.4-fpm.sock

Go back to the root directory and execute find ./ -name php7.4-fpm.sock

Find php7.4-fpm.sock The location, as shown in the following directory, is the location of php7.4-fpm.sock. We copy the location of php7.4-fpm.sock and modify the nginx configuration file.

/run/php/php7.4-fpm.sock

Configure the following screenshot unix:php7.4-fpm.sock path location

fastcgi_pass unix:/run/php/php7.4-fpm.sock;

How to solve nginx cannot start php

After modifying the nginx configuration file, restart nginx to take effect

/etc/init.d/nginx restart

Restart or start php7.4-fpm as follows

/etc/init.d/php7.4-fpm restart /etc/init.d/php7.4-fpm start

The above is the detailed content of How to solve nginx cannot start php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete