Skip to content

Karma Mule

Developing whatever I feel like since 1998

Menu
  • About
Menu

Enabling PHP Error logs and Custom PHP settings on Azure PHP-based App Services

Posted on January 11, 2023 by Daggar

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.

  1. In the app service > Configuration > Application Settings (default tab), set an application setting and set it as:
    Name: PHP_INI_SCAN_DIR
    Value: /usr/local/etc/php/conf.d:/home/site/ini
    This sets the php service to look at the normal config directory, but also the dir /home/site/ini …which does not yet exist.
  2. 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:
    log_errors=On
    error_reporting=E_ALL
    display_startup_errors=On
    error_log=/home/LogFiles/php_errors.log
  3. 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:
    <?php
    fakefunction(notvarorconstant; notvarorconstant2)
    ?>
  4. 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

upload_max_filesize=50M
post_max_size=50M

(These settings crank up the maximum filesize upload to fifty megabytes, and allow the post size to match.)

Relevant links:

  • 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pages

  • About

Mine

  • The Next Big Species

Others

  • Design with Intent
  • Strange Maps
  • untidy Revelations

Categories

  • Pointless criticism
  • Uncategorized
  • Useful Bits
  • visuals
January 2023
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031  
« May    

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2023 Karma Mule | Powered by Superbs Personal Blog theme