After installing PHP on a Linux system, you may sometimes encounter issues where PHP does not run properly, which can disrupt development and delay projects. This article systematically explains common troubleshooting steps and solutions to help you quickly restore PHP service.
First, confirm whether PHP has been installed successfully. Use the following command to check the PHP version:
<span class="fun">php -v</span>
If the command returns the PHP version number, the installation is successful. If an error message appears, consider reinstalling PHP.
If the installation is incomplete or incorrect, run this command to install PHP:
<span class="fun">sudo apt-get install php</span>
After installation, run php -v again to verify the installation status.
The PHP configuration file (usually php.ini) directly affects PHP’s operation. Use the following command to locate the config file:
<span class="fun">php --ini</span>
Open the configuration file and ensure the following settings are appropriate:
In Apache, ensure the PHP module is loaded properly. Edit the apache2.conf file and add:
<span class="fun">LoadModule php7_module modules/libphp7.so</span>
Save and then restart Apache:
<span class="fun">sudo systemctl restart apache2</span>
For Nginx, make sure the PHP-FPM configuration is correctly set in the relevant server block. Example:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
After changes, restart Nginx:
<span class="fun">sudo systemctl restart nginx</span>
If issues persist, review PHP error logs for detailed information. Logs are usually located at /var/log/php_errors.log. Use the log content for further troubleshooting.
Following these steps allows you to systematically locate and solve PHP not running problems on Linux. For complex cases, consider consulting developer communities. With patient debugging, you will successfully restore PHP to normal operation.