If you run LEMP (Linux Nginx MySQL PHP) on your server and the nginx and php configurations are still in the default configuration. Surely you will often encounter Error 504 Gateway time-out in your browser when running / executing the php file. That’s because the default PHP script execution time limit is only 30s (30 seconds). Therefore we need to increase the execution time limit of its PHP scripts. I will share information on how to fix error “504 Gateway Time-out” in Nginx PHP by increasing the execution time limit of PHP scripts as follows:
Step 1 – Update the php.ini file
For the first time we increase the execution time of the php script in the php.ini file, use find to find the location of the php.ini file.
find / -name 'php.ini'
If you have found it, enter using your favorite editor, for example:
vim /etc/php/7.3/fpm/php.ini
Set the max_execution_time parameter (in seconds) as needed, for example:
max_execution_time = 300
Step 2 – Update the www.conf file
Next, after finishing php.ini we move on to the www.conf file. The changes here have an impact on the php-fpm we run. set the request_terminate_timeout parameter and match the one we set in php.ini. first, we look for the www.conf file with find
find / -name 'www.conf'
then we enter with each favorite editor, for example:
vim /etc/php/7.3/fpm/pool.d/www.conf
dan kita atur paramater request_terminate_timeout nya, contoh :
request_terminate_timeout = 30s
By default, these parameters will be commented with; at first, delete the comment to activate. In this parameter you can use the available units starting from s(econds) (default), m(inutes), h(ours), or d(ays).
Step 3 – Update the Nginx configuration
Now in the PHP section, we now turn to the Nginx section. You can add it to your nginx.conf file for universal use or you can customize it by adding it to your * .conf file.
For the nginx.conf file, you can add it to the http {..}
section by entering the fastcgi_read_timeout parameter along with the values as in the php configuration. Examples like this :
http { ... fastcgi_read_timeout 300; ... }
Then if you want to add it in the * .conf file you can add these parameters to the location ~ \.php$ {..}
section. Examples like this :
location ~ \.php$ { ... fastcgi_read_timeout 300; ... }
Step 4 – Reload / restart the nginx service and also php-fpm
For the latter, after you set the configuration of the three steps above, you only need to restart the service by:
systemctl restart nginx
systemctl restart php-fpm
After restarting, try to test again and the error has been resolved.
Yep, that’s the information I can share about how to fix error “504 Gateway Time-out” in Nginx PHP. For the value of the parameters I mentioned above, you can adjust it to your needs. Hope this information can be useful, Thanks: lol: