PHP and Apache 504 Gateway Timeout Troubleshooting and Solutions

Jan 29, 2015   Web Development   Nick Vogt   Comments (5)
Please note that this post is over a year old and may contain outdated information.
If you're experiencing a 504 Gateway Timout on your long PHP scripts, despite having lengthy execution times in php.ini, here are some things you should check.

PHP Config

If you haven't yet, make sure both max_execution_time and max_input_time in your php.ini file are set to a sufficient number of seconds. For example:

max_execution_time = 600
max_input_time = 600

Apache Config

If you have PHP set correctly, it may be Apache's config that is timing out. The setting that controls its timeout is not always present in httpd.conf by default, so you may have to add it.

Open up httpd.conf and look for the setting Timeout. If it doesn't exist, add it on its own line and set it to a sufficient number of seconds. For example:

Timeout 600


If you're experiencing the timeout in PHPMyAdmin, keep in mind that it has its own execution time limit ExecTimeLimit. Open up config.inc.php and if it doesn't exist, add a config option with a sufficient number of seconds like this:

$cfg['ExecTimeLimit'] = 600;
If that config option already exists, edit it to the desired number of seconds.
Share This Post

Comments (5)

George   Jul 21, 2018
Thank you, it was very useful!
Sandeep   Jan 31, 2018
Appreciate the post.
Hari   Nov 29, 2017
Thank you for this post.
Nick Vogt   Oct 28, 2015
If you're on a shared host, you may not have full access to these properties. You can try setting them in your php file or htaccess, but that depends on your server setup. You'll have to ask them.
Habib Bellia   Oct 27, 2015
and in hosting ?
Share This Post
H3XED © Nick Vogt   RSS   Policies   Twitter