{"id":19593,"date":"2015-06-17T23:46:12","date_gmt":"2015-06-17T18:16:12","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=19593"},"modified":"2015-06-17T23:46:12","modified_gmt":"2015-06-17T18:16:12","slug":"php5-fpm-logging","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/php5-fpm-logging\/","title":{"rendered":"PHP5-FPM Logging"},"content":{"rendered":"<p>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.<\/p>\n<p>Prerequisites:<\/p>\n<p>Lets have an application that uses the php5-fpm module, in this case, we will use the WordPress Application running on a LEMP stack.<\/p>\n<p>To enable the logs , two files are relevant, namely<br \/>\n<strong><br \/>\ni)\u00a0\/etc\/php5\/fpm\/php-fpm.conf<br \/>\nii) \/etc\/php5\/fpm\/pool.d\/www.conf<\/strong><\/p>\n<p>Firstly, open the first file for editing<\/p>\n<p>[js]vi \/etc\/php5\/fpm\/php-fpm.conf[\/js]<\/p>\n<p>Set the desired location for getting error logs. The line should look like:<br \/>\n<strong>error_log = \/var\/log\/php5\/error.log<\/strong><br \/>\nThen save and exit<\/p>\n<p>Next open the second file for editing<\/p>\n<p>[js] vi \/etc\/php5\/fpm\/pool.d\/www.conf [\/js]<\/p>\n<p>Look for the line containing the location of access.log and set it to the desired path.<br \/>\nex: <strong>access.log = \/var\/log\/php5\/access.log<\/strong><\/p>\n<p>Understanding the access log format:<\/p>\n<p><strong>access.format = %R &#8211; %u %t \\&#8221;%m %r%Q%q\\&#8221; %s %f %{mili}d %{kilo}M %C%%&#8221;<\/strong><\/p>\n<p>%R : remote IP address<br \/>\n%u : remote user (you dont see these two in output of tail -f)<\/p>\n<p>%t : server time of receiving request<br \/>\n%m : method<br \/>\n%r : request uri {Addidtional : %q:if query string exists, %Q: the ? character is query<br \/>\nstring exists }<br \/>\n%s: status response<br \/>\n%f : script filename<br \/>\n%d : time taken to serve request (in mili seconds)<br \/>\n%M : peak memory allocated by php (in kilobytes)<br \/>\n%C : CPU used by request<\/p>\n<p>Example:<\/p>\n<p>[js]<br \/>\n          %t                 %m     %r                   %s          %f                    %d      %M   %C<br \/>\n 17\/May\/2015:09:41:04 +0000 &quot;GET \/wp-admin\/install.php&quot; 200 \/var\/www\/wp-admin\/install.php 218.177 2816 87.09%<br \/>\n[\/js]<\/p>\n<p>The format of the access log can be altered as per desire.<\/p>\n<p>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.<br \/>\n<strong>slowlog = \/var\/log\/php5\/slow.log<\/strong><br \/>\nMake sure to set the request_slowlog_timeout to the desired value. The line should look like :<\/p>\n<p>Ex: <strong>request_slowlog_timeout = 10<\/strong><\/p>\n<p>At the bottom of the file set<br \/>\n<strong>php_admin_value[error_log] = \/var\/log\/php5\/error.log<\/strong>        ##path of error.log<br \/>\n<strong>php_admin_flag[log_errors] = on<\/strong><\/p>\n<p>Create the directory(if it does not exist) where the logs are to be created.<\/p>\n<p>[js]mkdir -p \/var\/log\/php5[\/js]<\/p>\n<p>Restart the php5-fpm service<\/p>\n<p>[js]service php5-fpm restart[\/js]<\/p>\n<p>Henceforth you will start getting the logs at the set path.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. Prerequisites: 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 [&hellip;]<\/p>\n","protected":false},"author":178,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":22},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19593"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/178"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=19593"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/19593\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=19593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=19593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=19593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}