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

lindstrom's avatar

Php ssh2 - 504 Bad Gateway Time-Out

OK, I'm about to cry. I can't get past this time out issue.

  1. I have a non-Laravel project I'm trying to run on Homestead and Forge.
  2. The application needs to ssh into another box to copy some configuration info (irrelevant but for background on what/why_
  3. I have installed php-ssh2 and verified it is loaded.
  4. The Homestead vm is running Ubuntu 14.04 with PHP 7
  5. The Forge machine is running Ubuntu 16.04 with the Forge stack including PHP 7
  6. ssh2_connect('ip', port); times out
  7. Given 6, it makes the request then doesn't get a response. The error in my log is:
2016/08/25 00:43:27 [error] 2704#2704: *1400 upstream timed out (110: Connection timed out) while reading response header from upstream, client: [my client ip], server: mydomain.com, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "mydomain.com"
  1. Everything else is functioning as it should -- remote db connection, php, etc.
  2. I can ssh from the command line without any issue to varying ports xx.xx.xx.xx:88, etc,
  3. I tried disabling ufw just to be sure it wasn't getting blocked somehow.

I know this has to be a configuration issue, but I'm just too sleep deprived and dense to figure it out. If anyone has any ideas, I'd be forever grateful.

EDIT: I tried phpseclib with the same result. Does anyone have the ssh2_ functions running under Nginx/PHP 7?

0 likes
1 reply
lindstrom's avatar

Yeah, so this boiled down to something on the host's end. Maybe firewall? What's interesting is that I can ssh to the public ip/port no problem. But, it refuses to respond to connections made by either of ssh2_connect or phpseclib.

This was a huge waste of time, but at least I did learn about http://sdf.org which is a very cool and free way to get a Unix shell you can ssh (and do lots of other stuff with). Just ssh [email protected] and follow the instructions.

Please or to participate in this conversation.