PHP and Apache 504 Gateway Timeout Troubleshooting and Solutions
Jan 29, 2015Web DevelopmentComments (14)
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 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.
Comments (14)
Add a Comment
Joerg   Jun 29, 2023
php -ini | grep Configuration
Afshaar   Jun 21, 2023
PHP Config can anyone tell me the path?
Arvind G   Nov 06, 2021
Thanks for such helpfull post. I was struggling for more than 2 days to resolve this problem. My problem resolved. Thanks again.
Juan Adamuz   Apr 12, 2021
Thanks It worked like a charm!!
Ngalande   Nov 17, 2020
Added Timeout 600 to httpd.conf and it worked like magic! Thanks.
Pyae Sone Phyoe   Nov 03, 2020
Thanks for ur information.
Steve   Oct 16, 2020
Thank you for this... it was definitely this setting that had to be added in, Timeout 600 in /etc/httpd/conf/httpd.conf, to prevent a gateway timeout error with an api server in my app.
Mark   Aug 18, 2020
This post is still useful. Added Timeout to httpd.conf and it worked. Thanks
Damilola   Dec 02, 2019
Added Timeout 600 to httpd.conf and it worked! Thank you.
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 ?