I have a simple PHP script:
exec('git pull origin master', $shell_output, $output);
print_r($shell_output);
print_r($output)
When I call this via CLI php git.php, it works fine. I get the expected output, and a return value of 0. When I visit the page via a web browser, it fails with a return value of 1.
I’ve set file permissions to 777, and ensured php.ini doesn’t block the exec() function.
I was able to fix the issue with some help by Ates Goral.
To debug the issue, I ran:
sudo -u www-data php git.phpto see how the script behaved when run under the
www-datauser. There were two issues:www-datadid not have its own public key. I created one and added it to the github repo.And the
.gitfolder was not readable bywww-data. This was fixed bychowning the directory to give permissions to the groupwww-datathat both I and apache belong to.