Configure max_execution_time in PHP-FPM using Nginx

Contents

  1.  

here are some times when you will need to increase PHP script execution time with Nginx (often lower times can cause a 504 gateway timeout error). In order to configure/increase max_execution_time variable from PHP-FPM using Nginx, you should follow this steps:

Edit php.ini, in CentOS it is locatd at

pico -w /etc/php.ini

Then set:

max_execution_time = 300

Edit www.conf file from php-fpm:

pico -w /etc/php-fpm.d/www.conf

Then set:

request_terminate_timeout = 300

Edit nginx virtual hosts file for your website.

We will now edit the time limit and set fastcgi_read_timeout to 300:

location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 300;
}

Otherwise, if you need to increase time limit globally for all the websites served by Nginx, you need to edit the main nginx.conf file. At CentOS it is located in:

pico -w /etc/nginx/nginx.conf

Add following code inside the http{..} block

fastcgi_read_timeout 300; 

Restart php-fpm and nginx

service php5-fpmd restart
service nginx restart

 

Revisions

No comments yet.

Leave a Reply