Use php-fpm log to troubleshoot PHP 8 Linux Azure App Service
Published Apr 04 2022 08:01 PM 4,452 Views
Microsoft

Azure App Service for Linux platform now supports customer using both PHP 7 and PHP 8 built-in docker image.
When switching from PHP 7 to PHP 8, you may recognize the platform changed the web container from using Apache to Nginx+php-fpm mode.

 

This blog shows how to use customized php-fpm configuration in PHP 8 Linux App Service to get more detailed logs to troubleshoot application issues.

 

How to Enable php-fpm access log

How to Enable php-fpm slow requests log

How to check php-fpm status

 

How to Enable php-fpm access log

We can get a lot of detailed PHP requests information in php-fpm access log.
For example:

  • Request URL
  • Response status code
  • Server time the request was received
  • Time taken to serve the request
  • %CPU used by the request
  • peak of memory allocated by PHP

 

In PHP 8 Linux Azure App Service, the original php-fpm config file is stored in  /usr/local/etc/php-fpm.d/www.conf.

By default, php-fpm access log is disabled in the config.

 

To enable php-fpm access log, we need to modify the php-fpm config file.

1.  Make a copy of www.conf from /usr/local/etc/php-fpm.d/www.conf to /home/www.conf

     Go to https://<appservice-name>.scm.azurewebsites.net/webssh/host

 

cp /usr/local/etc/php-fpm.d/www.conf /home/www.conf

 

2.  Enable access.log by uncomment the following two lines in the /home/www.conf file

 

vi /home/www.conf

 

Define your access.log file path. (We suggest put it anywhere under /home/LogFiles/)
Define the access log format, to add the information you need for application issue investigation.

Hanli_Ren_0-1649058972670.png

The meaning of the format arguments are provided in the www.conf file

Hanli_Ren_1-1649059031448.png

 

3.  Change the customer startup script to overwrite the originally www.config file with your customized one.

Put the following command in the startup script:

 

cp /home/www.conf /usr/local/etc/php-fpm.d/www.conf; service nginx restart

 

Hanli_Ren_0-1649062115607.png

 

4. After Restart the App Service, you should be able to see the php-fpm access log in the path you defined in your www.config file.

Hanli_Ren_1-1649062145171.png

 

 

How to Enable php-fpm slow requests log

We can also enable php-fpm slow log to get more detailed php call stacks to analysis requests slowness issues.

We can enable slow log with the following steps:

1. Make a copy of www.conf from /usr/local/etc/php-fpm.d/www.conf to /home/www.conf

 

cp /usr/local/etc/php-fpm.d/www.conf /home/www.conf

 

2. Enable slowlog by uncomment the following two lines in the /home/www.conf file

 

vi /home/www.conf

 

Define your slowlog file path. (We suggest put it anywhere under /home/Logfiles/ folder)
Define the request_slowlog_timeout

Hanli_Ren_2-1649062387969.png

 

3. Change the customer startup script to overwrite the originally www.config file with your customized one.

Put the following command in the startup script:

 

cp /home/www.conf /usr/local/etc/php-fpm.d/www.conf; service nginx restart

 

Hanli_Ren_3-1649062475268.png

 

4. After Restart the App Service, you should be able to see the php-fpm slow log in the path you defined in your www.config file.

For example, I create a very simple slow request sample.

  • index.php calls test.php
  • test.php sleeps 10 seconds when processing the request.

Hanli_Ren_4-1649062557372.png

In my /home/Logfiles/www.log.slow record, I can see detailed call stack in the log for the slow requests.

Hanli_Ren_5-1649062607160.png

 

 

 

How to check php-fpm status

Sometimes we need to check php-fpm status for performance tuning.
For example, we can check "max active process" and "max children reached" number to decide whether we need to increase the pm.max_children in the php-fpm configuration.

 

We can check php-fpm status with the following steps:

1. Make a copy of www.conf from /usr/local/etc/php-fpm.d/www.conf to /home/www.conf

 

cp /usr/local/etc/php-fpm.d/www.conf /home/www.conf

 

2. Enable pm.status_path by uncomment the following line in the /home/www.conf file

Hanli_Ren_0-1649062804874.png

 

3. Make a copy of Nginx configure file from /etc/nginx/sites-enabled/default to /home/default

 

cp /etc/nginx/sites-enabled/default /home/default

 

4. Add location for php-fpm status check

 

# Add location for php-fpm status check
    location = /status {
       include fastcgi_params;
       fastcgi_param SCRIPT_NAME '/status';
       fastcgi_param SCRIPT_FILENAME '/status';
       fastcgi_pass 127.0.0.1:9000;
    }

 

Hanli_Ren_1-1649062926895.png

5. Modify customer startup command to overwrite Nginx and php-fpm config file with your customized settings

Put the following command in the startup script:

 

cp /home/www.conf /usr/local/etc/php-fpm.d/www.conf; cp /home/default /etc/nginx/sites-enabled/default; service nginx restart

 

Hanli_Ren_2-1649063040793.png

 

6. By accessing the https://<webapp-name>.azurewebsites.net/status uri of your App Service, you should be able to monitor the php-fpm usage status in live time.

Hanli_Ren_3-1649063105738.png

 

1 Comment
Co-Authors
Version history
Last update:
‎Apr 04 2022 02:07 AM
Updated by: