Home > Backend Development > PHP Problem > What should I do if lnmp php does not execute?

What should I do if lnmp php does not execute?

PHPz
Release: 2023-04-10 14:07:14
Original
607 people have browsed it

When configuring the lnmp environment, if the PHP file is not executed when accessing it, how should we solve it?

First, we need to rule out several possibilities.

1. PHP is not installed or configured correctly.

First, we need to check whether PHP is correctly installed on our server. You can check by executing the command:

php -v
Copy after login
Copy after login

If the PHP version information appears, PHP has been correctly installed on the server. If there is no output, you need to reinstall PHP.

If PHP has been installed on the server, then you need to check whether the PHP configuration is correct. Generally, we need to let PHP-FPM dynamically connect to NGINX and add some necessary parameters to the NGINX configuration file. Check these files to make sure PHP is configured correctly:

  • /etc/php-fpm.conf
  • /etc/php-fpm.d/www.conf
  • /etc/nginx/nginx.conf
  • /etc/nginx/sites-enabled/default

2. PHP-FPM is not started, causing

If PHP It has been installed and configured correctly, but it still cannot parse the PHP file, then you need to check whether PHP-FPM is started correctly.

You can check the status of PHP-FPM through the following command:

sudo systemctl status php-fpm
Copy after login

If PHP-FPM does not start successfully, you can manually start PHP-FPM through the following command:

sudo systemctl start php-fpm
Copy after login

3. NGINX and PHP-FPM configuration mismatch causes

If PHP-FPM has been started correctly, but NGINX still cannot parse the PHP file, then it may be caused by the configuration mismatch between NGINX and PHP-FPM . Try making the following adjustments to NGINX:

  1. Confirm that NGINX is connecting to PHP-FPM correctly

Check/etc/nginx/sites-enabled/defaultFile and ensure the following content:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    root /var/www/html;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
Copy after login

It should be noted that the fastcgi_pass here must be consistent with /etc/php-fpm.d/www.conf The listen parameter matches. If a mismatch occurs, the file will need to be modified manually.

  1. Set the correct file access permissions

Check whether the access permissions of the PHP file and directory are correct. The following command can be used to confirm and change the permissions of the file:

ls -l <file_name>
chmod 644 <file_name>
chown www-data:www-data <file_name>
Copy after login
  1. Confirm that the PHP version matches the required PHP version

The current PHP version can be confirmed by using the following command :

php -v
Copy after login
Copy after login

If the current PHP version does not match the required PHP version, you need to upgrade the PHP version.

To sum up, if the PHP file is not executed when accessing it, you first need to confirm whether PHP is installed and configured correctly, and check whether the configurations of PHP-FPM and NGINX match. If it still cannot be solved, then you need to check whether the file access permissions match the required PHP version.

The above is the detailed content of What should I do if lnmp php does not execute?. 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