1

For the sake of my explanation, keep the following im mind.

Machine 1 Internal = 127.0.0.1
Machine 1 External = 192.0.0.1

Machine 2 Internal = 127.0.0.2
Machime 2 External = 192.0.0.2

Client External = 10.0.0.1


So, I will try to connect to the internal IP of Machine #1, while on Machine #1:

$server = "127.0.0.1";
$conn = ssh2_connect($server, 22);


Results in [/var/log/httpd/error_log]:

[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 127.0.0.1 on port 22 in /var/www/html/file.php on line 8
[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 127.0.0.1 in /var/www/html/file.php on line 8

Changing the IP from internal to external yielded the same error.

Now, I will try to connect to the external IP of machine #1 while the PHP file is ran off of Machine #2's webserver:

$server = "192.0.0.1"
$conn = ssh2_connect($server);

Results in [/var/log/httpd/error_log]:

[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 192.0.0.1 on port 22 in /var/www/html/file.php on line 8
[:error] [client 10.0.0.1:0000] PHP Warning:  ssh2_connect(): Unable to connect to 192.0.0.1 in /var/www/html/file.php on line 8

All of this is the case, but oddly enough, if I run the exact code through the php -a interpreter, and proceed to authenticate and run a command, all works flawlessly.

What is the issue??

Nic Plants
  • 11
  • 1
  • Can you please tell us what kind of Apache and OS are you using please? For example, on SELinux, you should run `setsebool -P httpd_can_network_connect 1` to allow HTTPD scripts and modules to connect to the network using TCP – Ayak973 Sep 19 '18 at 07:44
  • OS: `CentOS Linux release 7.5.1804 (Core)` Apache: `Server version: Apache/2.4.6 (CentOS)` – Nic Plants Sep 19 '18 at 20:30

1 Answers1

0

I was able to resolve this by using setenforce 0. Honestly the most puzzling issue I've had while programming. Thanks for the help!

Nic Plants
  • 11
  • 1
  • `setenforce 0` set SELinux in permissive mode, preferably for testing purposes. Please read why you should not do that: https://stackoverflow.com/a/14723853/5847906 – Ayak973 Sep 20 '18 at 07:07