Skip to content
jagaweb.Book the Review
Performance

Fixing 504 Gateway Timeout on Malaysian Shared Servers

4 min readBy JagaWeb Technical Team

Resolve Nginx and PHP-FPM 504 Gateway Timeout errors by tuning max_execution_time, request_terminate_timeout, and proxy_read_timeout.

Diagnosing the 504 Gateway Timeout

A 504 Gateway Timeout occurs when a reverse proxy (like Nginx or Cloudflare) waits too long for the upstream server (PHP-FPM or Apache) to respond. On Malaysian shared hosting environments running Nginx-over-Apache or Nginx-PHP-FPM, long-running processes like WordPress imports, WooCommerce bulk edits, or backup generations frequently trigger this error.

1. Increasing PHP Execution Limits

The first bottleneck is PHP itself. By default, max_execution_time is often restricted to 30 seconds.

If you have access to cPanel's MultiPHP INI Editor, increase the following values:

max_execution_time = 300
max_input_time = 300
memory_limit = 512M

If you don't have WHM access, you can try adding this to your .htaccess (though CloudLinux often blocks overriding these via htaccess):

php_value max_execution_time 300

2. Tuning PHP-FPM Pool Timeouts

If PHP is allowed to run for 300 seconds, but PHP-FPM terminates the request after 60 seconds, you will still get a 504.

If you have WHM root access or VPS SSH access, edit the PHP-FPM pool configuration (e.g., /opt/cpanel/ea-php74/root/etc/php-fpm.d/domain.conf):

request_terminate_timeout = 300

Restart the PHP-FPM service: systemctl restart ea-php74-php-fpm

3. Nginx Proxy Read Timeout

Finally, if Nginx is sitting in front of Apache/PHP-FPM, Nginx will drop the connection if the upstream takes too long.

On a VPS, edit your Nginx configuration (usually /etc/nginx/nginx.conf or the specific vhost):

location / {
    proxy_read_timeout 300s;
    proxy_connect_timeout 300s;
    proxy_send_timeout 300s;
    proxy_pass http://127.0.0.1:8080;
}

Reload Nginx: nginx -s reload.


Tired of babysitting fragile server configurations? At JagaWeb, we build resilient, high-timeout async workers for clients like Trexon Energy so heavy background jobs never crash the frontend.

Stop fighting 504 errors. Let us audit your architecture with our RM5,000 Ownership & Access Review, or migrate and manage your infrastructure flawlessly with our RM450/month Care Plan.

PROTECT YOUR ASSETS

Ready to verify who owns your website?

Replace uncertainty with a decision-ready ownership and access report. The fixed Ownership & Access Review is RM1,500 before SST and includes a 30-day action plan.

WhatsApp