Php run git got "ssh Permission denied"

I try to run git, pull the PHP script from the browser, but I got "sh: connect to the git.assembla.com host port 22: permission denied

my php script :

<?php
$output=array();
$returnVar=0;
chdir("/var/www/html");
exec('git pull git@git.assembla.com:andrewadel.git master 2>&1', $output , $returnVar);
// exec('pwd', $output , $returnVar);
echo "<pre>\n";
echo "return status: $returnVar\n\n";
print_r($output);
echo "</pre>\n";

when I manually run the script as "apache" everything is fine

bash-4.1$ whoami
apache
bash-4.1$ php gitsync.php
<pre>
return status: 0

Array
(
    [0] => From git.assembla.com:andrewadel
    [1] =>  * branch            master     -> FETCH_HEAD
    [2] => Already up-to-date.
)
</pre>

When I launch it from the browser, it fails

http://103.7.164.33/gitsync.php?111

return status: 1

Array
(
    [0] => ssh: connect to host git.assembla.com port 22: Permission denied
    [1] => fatal: The remote end hung up unexpectedly
)

thank

+5
source share
4 answers

There are many variables here ... but I came across the same behavior with the remote cgi script that I was working on.

In my case, the problem was related to SELinux on CentOS.

user@remoteserver:~$ getsebool -a | grep httpd

Showed:

...
httpd_can_network_connect --> off
...

Check for a possible fix (sudo or run as root):

user@remoteserver:~$ setsebool httpd_can_network_connect=1
//...then initiate your serverside script remotely

Permanent correction (if proven above):

user@remoteserver:~$ setsebool -P httpd_can_network_connect=1

Option

-P , SELinux . : man getsebool man setsebool

+3

- PHP Suhosin, , ?

PHP- Git, php-git, . Git PHP-.

+1

Apache script "nobody". script , , ~ apache/.ssh/id_rsa

, git git.

, , script.

, :

SSH- Ruby ?

:

https://serverfault.com/questions/226374/how-to-run-php-files-as-another-user-with-apache-and-fastcgi

( ) apache ( , , ). git. , , (/) ~/.ssh

+1

? PHP script , , git.

0

All Articles