Discuss and summarize some reasons and solutions for PHP-FPM not taking effect

PHPz
Release: 2023-04-12 20:46:08
Original
1354 people have browsed it

PHP-FPM is a commonly used FastCGI manager. Many websites use it to process PHP scripts, but sometimes we encounter situations where PHP-FPM does not take effect. In this article, I'll explore some possible causes and how to fix them.

First, we need to verify that PHP-FPM is running. This can be checked by:

systemctl status php-fpm
Copy after login

If PHP-FPM is not started, you need to start it:

systemctl start php-fpm
Copy after login

If it is already running, you can skip this step and continue looking for other potential issues .

Secondly, we need to ensure that the configuration file of PHP-FPM is correct. By default, the PHP version will have its own default configuration file. However, if we need to change some settings, we need to override them and reload the configuration file.

Next, check whether your Nginx configuration file is correct. In Nginx's configuration file, we need to make sure that the correct PHP-FPM socket or port is used. Typically, we will see the following settings in the Nginx configuration file:

location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
    include fastcgi_params;
}
Copy after login

In the above example, Nginx sends the request to PHP-FPM’s socket file. If our PHP-FPM listens on port, we need to change it to fastcgi_pass 127.0.0.1:9000;, where 9000 is the default port.

If you have recently updated your PHP version, you will also need to ensure that the PHP module is available. You can check whether the PHP module is loaded by running the following command:

php -m
Copy after login

If both PHP-FPM and Nginx are configured correctly, but the PHP script is still not being processed correctly, it may be due to permissions issues. PHP-FPM runs under the WWW user, and it has the highest permissions on the document root directory (usually /var/www/html). If the permissions of folders and files are restricted, it may cause PHP scripts to not run properly.

To ensure that permission issues do not cause PHP-FPM to not take effect, please ensure that WWW users have full access to your document root directory. The WWW user can be changed with the following command:

usermod -a -G www-data username
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
Copy after login

The above example changes the WWW user and sets the ownership and permissions of the folders and files to the WWW user and 755. This ensures that PHP-FPM has full access to the document root and that PHP scripts can run properly.

In short, when PHP-FPM does not take effect, we need to check the following aspects:

  1. Check whether PHP-FPM is running
  2. Check the PHP-FPM configuration Whether the file is correct
  3. Check whether the Nginx configuration file is correct
  4. Check whether the PHP module is available
  5. Ensure that WWW users have full access to the document root directory

By checking these possible issues, you should be able to resolve PHP-FPM not working.

The above is the detailed content of Discuss and summarize some reasons and solutions for PHP-FPM not taking effect. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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