By default, an Azure PHP App Service does not capture PHP errors in an easily accessible way. It is possible, through Monitoring/Health Check to find some of them, but finding each one is laborious. This procedure will enable a conventional PHP error log.
- In the app service > Configuration > Application Settings (default tab), set an application setting and set it as:
This sets the php service to look at the normal config directory, but also the dir /home/site/ini …which does not yet exist.
- Create the folder /home/site/ini . Inside that folder, create the file extensions.ini and add the settings there. As of Jan 6 2023, this is working:
- Restart the app service and, hopefully, the php errors are showing up to the log. If in doubt, make a file called php_error.php in your wwwroot with an obvious error or three:
- That should generate errors like:
[06-Jan-2023 16:40:00 UTC] PHP Parse error: syntax error, unexpected token ";", expecting ")" in /home/site/wwwroot/php_error.php on line 2
NOTE: As of this writing, php errors have a tendency to generate 404 Not Found errors, when you might expect something more specific like 500’s or similar. If you see a 404, check the php error log.
CUSTOM PHP SETTINGS
A useful side effect of the procedure above, that enables a custom PHP ini, works for more than just error logging. Once you’ve got the custom /home/site/ini/extensions.ini setting working, you can add other custom settings like
(These settings crank up the maximum filesize upload to fifty megabytes, and allow the post size to match.)
- https://azureossd.github.io/2019/01/29/azure-app-service-linux-update-php-settings/index.html – how to set up a custom php ini file on a Windows app service
- https://stackoverflow.com/questions/39601176/how-to-add-to-php-ini-on-azure-web-services – More on custom php ini. Jamal Uddin’s comment from nov 9, 2022 is particularly important.
- https://azureossd.github.io/2015/04/15/info-about-php-fatal-error-and-error-log-on-azure-website/index.html – list of PHP ini commands enable error logging
- https://www.php.net/manual/en/errorfunc.constants.php – php constants for error functions
- https://www.php.net/manual/en/errorfunc.configuration.php – PHP runtime configuration