How To Increase PHP Script Execution Time With Nginx

Written by Santosh Prasad

Often you have seen the ” 504 Gateway Time-out ” error on your web page if you have large WordPress setup or a server with limited resources.

You can fix this issue increasing the PHP script execution time.

Follow the steps given below to increase the timeout value, default is 30s.

Changes in php.ini

You can change the max execution time limit for php scripts for 30 seconds (default) to 60 seconds.

# vim /etc/php5/ffpm/php.ini


max_execution_time = 60

In Apache, it is sufficient to set max execution time in php.ini, but in our case we need to make this
change at 2 more places.

Changes in PHP-FPM

This is only needed if you have already un-commented request_terminate_timeout parameter before. It is commented by default, and takes value of max_execution_time found in php.ini

You will need to edit.

# vim /etc/php5/fpm/pool.d/www.conf


request_terminate_timeout = 60

Changes in Nginx Configuration

To increase the time limit for example.com by

# vim /etc/nginx/sites‐available/example.com

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5‐fpm.sock;
fastcgi_read_timeout 60;

You can also increase time limit for all sites on your server, you will need to edit main nginx.conf file.

# vim /etc/nginx/nginx.conf

Add following in http{..} section

http {
fastcgi_read_timeout 300;

Reload PHP-FPM & Nginx

Don’t forget to do this so that changes you have made will come into effect:

# service php5‐fpm reload

# service nginx reload


Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment