git pull with shell_exec

josh21 Source

I am trying to set up an automatic git pull on a shared server that gets triggered when I push to a github repo.

I set up the github repo and I can push/pull from my local machine and as well when I'm logged in via ssh on the server.

When I type git pull in the console, it works like a charm and the files get updated. But when I use php shell_exec I get an error message:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

This is the content of the php file I call:

$output = shell_exec('git pull 2>&1');
echo "<h1>Github pull</h1>";
echo "<pre>".$output."</pre>";


answered 7 days ago Markus Müller #1

When you ssh into the server you are using another OS user. The web server process probably has its own user. You need to add the key of your git server to the list of known hosts of that webserver user.

comments powered by Disqus