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
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:
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
If PHP-FPM does not start successfully, you can manually start PHP-FPM through the following command:
sudo systemctl start php-fpm
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:
Check/etc/nginx/sites-enabled/default
File 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; }
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.
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>
The current PHP version can be confirmed by using the following command :
php -v
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!