valet: 504 Gateway Timeout
I think laravel/valet should provide more relaxed defaults for a development environment. Importing a large(ish) database in phpmyadmin causes a 504 Gateway Time-out
error.
To fix the 504 error you need to change the default timeout to more than 30 seconds. Here’s how to change it to 5min (300 seconds):
/usr/local/etc/php/{version}/conf.d/php.ini
max_execution_time = 300
function updateConfiguration()
{
$contents = $this->files->get($this->fpmConfigPath());
$contents = preg_replace('/^user = .+$/m', 'user = '.user(), $contents);
$contents = preg_replace('/^group = .+$/m', 'group = staff', $contents);
$contents = preg_replace('/^listen = .+$/m', 'listen = '.VALET_HOME_PATH.'/valet.sock', $contents);
$contents = preg_replace('/^;?listen\.owner = .+$/m', 'listen.owner = '.user(), $contents);
$contents = preg_replace('/^;?listen\.group = .+$/m', 'listen.group = staff', $contents);
$contents = preg_replace('/^;?listen\.mode = .+$/m', 'listen.mode = 0777', $contents);
// Enable the "request_terminate_timeout" parameter
$contents = preg_replace('/^;?request_terminate_timeout = .+$/m', 'request_terminate_timeout = 300', $contents);
$this->files->put($this->fpmConfigPath(), $contents);
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:VALET_HOME_PATH/valet.sock;
fastcgi_index VALET_SERVER_PATH;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME VALET_SERVER_PATH;
# Set the "fastcgi_read_timeout" parameter
fastcgi_read_timeout 300;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:VALET_HOME_PATH/valet.sock;
fastcgi_index VALET_SERVER_PATH;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME VALET_SERVER_PATH;
# Set the "fastcgi_read_timeout" parameter
fastcgi_read_timeout 300;
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 62
- Comments: 40 (9 by maintainers)
@bkkrishna I have solved my issue adding
to
~/usr/local/etc/nginx.confg
file underhttp {}
object.Then restart the services
valet restart
For those who are stuck with 5 concurrent max requests:
If you want to boost the perf:
Valet just installs nginx via brew (unless it is already installed). You can always modify the configs under
/usr/local/etc/nginx/
. If you have usedvalet secure
on the site then there is also a site specific nginx config created under~/.valet/Nginx/
Thanks @AbhinavDobhal
Putting them in
/usr/local/etc/nginx/fastcgi_params
works well too, since it’s a central location and valet loads that file from the same block you mentioned. I recently started exploring using the following to test a suggestion made elsewhere for cookie payload size issues./usr/local/etc/nginx/fastcgi_params
非常感谢楼主,对于一直没有解决问题的小伙伴看好了. 直接修改 /usr/local/etc/nginx/valet/valet.conf 在差不多22行左右
当然php.ini里也是要设置好的 php71的配置在 /usr/local/etc/php/{version}/php.ini 不要偷懒,输入phpinfo就能看到配置文件地址. 改好后记得要重启valet
Added a new
fastcgi_params
inside~/.config/Valet/Nginx
with these details and did avalet restart
and that worked. Thanks!HI all,
I have been experiencing the same issue. I followed the same solution as @simonhamp.
For anyone else still having trouble, I specifically edited
/usr/local/etc/php/7.3/php-fpm.d/www.conf
With the following updates:
See https://dev.to/aubreypwd/how-i-configured-niginx-valet-to-stop-the-504-gateway-time-out-during-long-xdebug-sessions-174i
How I solved this
Added:
in
/opt/homebrew/etc/nginx/nginx.conf
, right before:I spent a lot of time trying to find ~/.valet/Nginx, turns out in newer versions of valet it is under ~/.config/Valet/Nginx. 😃
Solving this issue is easy: just open the file /usr/local/etc/nginx/valet/valet.conf and add the following lines to the block location ~ .php$ { } : proxy_connect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600; fastcgi_read_timeout 300; fastcgi_buffers 8 128k; fastcgi_buffer_size 256k;
Now all you have to do is to run on your valet restart terminal and everything should work fine.
PHP 7.3 is available on homebrew.
If everything is saying bad gateway then it’s likely that your PHP is the problem.
A complete reset of valet (er, well, the nginx/php part anyway; I’m assuming dnsmasq is resolving the .test TLD properly) can be done via:
I’ve got the same issue, but much more frequent when I make multiple requests. However,
2/3/4 - Couldn’t find those files, any clue?
Nice tip @jasperf. That and an entry in php.ini helped a long-running script run to completion.
Closing this issue as it seems there are myriad solutions presented but no forward movement for their impact on Valet; @ctf0 if you’d like to continue that proposal, would you please open it as a separate (and more fleshed-out) issue?
Which files should be changed on an existing/working Valet installation? Something in ~/.valet ?
Is it possible to disable Timeout completely (I use Valet on my notebook, not on server, so I an stop any processes myself, if need to)?