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
We can get a lot of detailed PHP requests information in php-fpm access log.
For example:
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.
The meaning of the format arguments are provided in the www.conf file
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
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.
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
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
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.
In my /home/Logfiles/www.log.slow record, I can see detailed call stack in the log for the slow requests.
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
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;
}
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.