If you are encountering frequent “504 Gateway Timeout” errors or experiencing PHP script timeouts during file uploads or long-running processes, even after increasing the max_execution_time in PHP, this guide will show you how to increase the Apache timeout setting in the CWP (Control WebPanel).
There are two common setups for PHP on CWP: PHP-CGI and PHP-FPM. Depending on which PHP handler you are using (PHP-CGI or PHP-FPM), the process to adjust the timeout will differ. Below are the steps for both configurations.
1. Increasing Timeout for PHP-CGI
If you are using PHP-CGI (with the PHP switcher), follow these steps to increase the Apache timeout:
1. Open or create the configuration file /usr/local/apache/conf.d/timeout.conf:
touch /usr/local/apache/conf.d/timeout.conf
2. Add the following line to set the Apache timeout to 3600 seconds (1 hour):
echo "TimeOut 3600" > /usr/local/apache/conf.d/timeout.conf
3. Restart Apache to apply the changes:
service httpd restart
This will increase the Apache timeout setting, allowing PHP scripts to run for a longer time.
2. Increasing Timeout for PHP-FPM
If you are using PHP-FPM (through the PHP-FPM selector), the process is slightly different. Follow these steps to adjust the timeout:
1. Locate your Apache virtual host configuration files in the directory:
/usr/local/apache/conf.d/vhosts
2. In the appropriate domain’s virtual host configuration file, add the following line under the proxy_fcgi_module configuration:
ProxyTimeout 3600
Example configuration for the domain:
<IfModule proxy_fcgi_module>
<FilesMatch \.php$>
SetHandler "proxy:unix:/opt/alt/php-fpm72/usr/var/sockets/username.sock|fcgi://localhost"
</FilesMatch>
ProxyTimeout 3600
</IfModule>
3. Alternatively, you can create a custom Apache vhost template with the increased timeout setting.
Copy the default PHP-FPM templates to new names (e.g., timeout.stpl and timeout.tpl), then replace the default configuration with the new timeout setting:
Copy the templates:
cp /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/httpd/php-fpm/default.stpl /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/httpd/php-fpm/timeout.stpl cp /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/httpd/php-fpm/default.tpl /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/httpd/php-fpm/timeout.tpl
Edit the timeout.stpl and timeout.tpl files to include the ProxyTimeout directive:
<IfModule proxy_fcgi_module> <FilesMatch \.php$> SetHandler "proxy:%backend_fcgi%|fcgi://localhost" </FilesMatch> ProxyTimeout 3600 </IfModule>
4. After creating the new templates, go to the CWP WebServer domain configuration, select the new template under PHP-FPM, and apply it.
If you prefer, you can choose the default template in the main web server configuration and manually restart Apache.
3. Disabling the reqtimeout Module for Unlimited Timeout
If you need an unlimited timeout and want to disable Apache’s request timeout module, follow these steps:
1. Open the Apache configuration file (httpd.conf) located in /usr/local/apache/conf.
2. Find the following line:
LoadModule reqtimeout_module modules/mod_reqtimeout.so
3. Comment out this line by adding a # at the beginning:
#LoadModule reqtimeout_module modules/mod_reqtimeout.so
4. Save the changes and restart Apache:
service httpd restart
Disabling the reqtimeout_module will allow for an unlimited timeout, meaning Apache will not impose any time restrictions on requests.
That’s It!
By following these steps, you can increase the Apache timeout in CWP for both PHP-CGI and PHP-FPM setups. Whether you choose to increase the timeout to a specific value like 3600 seconds or disable the timeout entirely, these adjustments will help prevent “504 Gateway Timeout” errors and ensure that long-running PHP scripts execute without interruption. Always remember to restart Apache after making changes to the configuration files.
You May Also Like
- 10 Internet Browsing Tricks You Probably Never Knew Existed
- How to Reset the Root Password in MariaDB 10.5/10.4 and MySQL 8.0
- Optimize Your Domain Portfolio with These 6 Free Research Tools
- How to Enable GZIP Compression on a Linux Server Running Apache
- How to Optimize Apache, PHP, and MySQL Performance for a 1GB RAM VPS