Home  >  Article  >  Backend Development  >  What should I do if nginx cannot start php?

What should I do if nginx cannot start php?

藏色散人
藏色散人Original
2022-11-18 10:24:521590browse

Solution for nginx 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.

What should I do if nginx cannot start php?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

nginx What should I do if I cannot start php?

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;
}

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

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;

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

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if nginx cannot start php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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