To enable PHP error logging in Nginx with PHP-FPM, you need to follow these steps:
Open the php.ini file for editing. Usually, it can be found in the /etc/php/
Uncomment or add the following line in the php.ini file to enable error logging:
error_log = /var/log/php/error.log
This line specifies the file location where PHP errors will be logged. You can modify the file location and name according to your preference.
Create the error.log file and give it appropriate permissions by running the following commands:
sudo touch /var/log/php/error.log
sudo chown www-data:www-data /var/log/php/error.log
Replace www-data:www-data with your web server user and group if different.
Restart the PHP-FPM service using the appropriate command depending on your system:
sudo service php7.4-fpm restart
Replace php7.4-fpm with the correct PHP-FPM service name for your PHP version.
Reload or restart Nginx for the changes to take effect:
sudo service nginx reload
Alternatively, you can use the restart command instead of reload:
sudo service nginx restart
Verify that PHP error logging is working by intentionally causing a PHP error in your application. The error should now be logged in the specified error.log file.
Note: Make sure you have the necessary permissions to write to the error log file and that the file location is accessible by the PHP-FPM process.