Tips / Nginx

Configure max_execution_time in PHP-FPM using Nginx

There 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 located 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

Popular search terms:

  • nginx max_execution_time
  • how to set Max Execution Time fastcgi
  • fpm timeout
  • php fcgi config debian max_execution_time

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • sandeep

    If i setup diffrent max execution time in php-fpm ,nginx and php.ini, then which will take in execution?

  • Vee Jay

    Thx 4 this!
    fastcgi_read_timeout 300;

  • Useful post, thank you.

  • Luke Cavanagh

    Thank you.