Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GertTimmerman's avatar

504 Gateway Timeout

Since this morning i get an 504 Gateway Timeout and sometimes an 502 Bad Gateway. I haven't changed anything, but the nginx.log says:

connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream

how can i solve this?

0 likes
8 replies
bashy's avatar

Have you tried restarting php5-fpm?

sudo service php5-fpm restart
1 like
GertTimmerman's avatar

doesn't help .. :( i've rebooted the server, rebooted nginx, but nothing helps ..

bashy's avatar

The socket will only be there if php5-fpm creates it, maybe your config became messed up. Not sure why it would randomly do it though, never happened to me.

/etc/php5/fpm/pool.d/www.conf

GertTimmerman's avatar
GertTimmerman
OP
Best Answer
Level 12

Found It! The site depends on the data from an API and the API call has a 504 timeout. Maybe i have to check my code to prevent this :(

mln.mln.mln's avatar

I had the same issue. The problem was due to the invalid database host name. Hope this might be helpful to someone.

1 like
calichepentecostal's avatar

$ sudo nano /etc/php/7.0/fpm/php.ini

max_execution_time = 600

$ sudo nano /etc/php/7.0/fpm/pool.d/www.conf

request_terminate_timeout = 600

$ sudo /etc/nginx/sites-available/midominio.dev

location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors off; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; fastcgi_connect_timeout 600; fastcgi_send_timeout 600; fastcgi_read_timeout 600; }

defayeke's avatar

If you are able to debug your way through, you might find the source of the problem relatively easily. For me, a dd(); would trigger before but not after a model query, which made me realise MySQL was the issue. Since it was installed via brew, I just ran brew services restart mysql to resolve it.

Please or to participate in this conversation.