PHP5-FPM Logging

17 / Jun / 2015 by Prakashul . 0 comments

In this blog i will explain how to configure the access, error and slow logs of php-fpm and to modify the format in which the logs are received.


Lets have an application that uses the php5-fpm module, in this case, we will use the WordPress Application running on a LEMP stack.

To enable the logs , two files are relevant, namely

i) /etc/php5/fpm/php-fpm.conf
ii) /etc/php5/fpm/pool.d/www.conf

Firstly, open the first file for editing

[js]vi /etc/php5/fpm/php-fpm.conf[/js]

Set the desired location for getting error logs. The line should look like:
error_log = /var/log/php5/error.log
Then save and exit

Next open the second file for editing

[js] vi /etc/php5/fpm/pool.d/www.conf [/js]

Look for the line containing the location of access.log and set it to the desired path.
ex: access.log = /var/log/php5/access.log

Understanding the access log format:

access.format = %R – %u %t \”%m %r%Q%q\” %s %f %{mili}d %{kilo}M %C%%”

%R : remote IP address
%u : remote user (you dont see these two in output of tail -f)

%t : server time of receiving request
%m : method
%r : request uri {Addidtional : %q:if query string exists, %Q: the ? character is query
string exists }
%s: status response
%f : script filename
%d : time taken to serve request (in mili seconds)
%M : peak memory allocated by php (in kilobytes)
%C : CPU used by request


%t %m %r %s %f %d %M %C
17/May/2015:09:41:04 +0000 "GET /wp-admin/install.php" 200 /var/www/wp-admin/install.php 218.177 2816 87.09%

The format of the access log can be altered as per desire.

The path for slow log is defined is defined just beneath the block of access logs. Uncomment the line and set the desired path for getting slow logs.
slowlog = /var/log/php5/slow.log
Make sure to set the request_slowlog_timeout to the desired value. The line should look like :

Ex: request_slowlog_timeout = 10

At the bottom of the file set
php_admin_value[error_log] = /var/log/php5/error.log ##path of error.log
php_admin_flag[log_errors] = on

Create the directory(if it does not exist) where the logs are to be created.

[js]mkdir -p /var/log/php5[/js]

Restart the php5-fpm service

[js]service php5-fpm restart[/js]

Henceforth you will start getting the logs at the set path.


Leave a Reply

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