I need a PHP script to perform git pull however I am not naive enough to give it permissions on git. I've wrapped git pull in a script which www-data has permissions for, but I'm not sure how to give the script permissions on git itself:

$ sudo tail -n1 /etc/sudoers
www-data ALL=(ALL) NOPASSWD: /home/php-scripts/git-pull

$ cat /home/php-scripts/git-pull
/usr/bin/git pull

$ ls -la /home | grep php-scripts
drwxr-xr-x  2 ubuntu ubuntu 4096 Sep  3 09:26 php-scripts

$ ls -la /home/php-scripts/git-pull
-rwxrwxr-x 1 ubuntu ubuntu 30 Sep  3 08:44 /home/php-scripts/git-pull

$ cat /var/www/public_html/git-wrapper.php

$output = array();
$value = 0;
exec("/home/php-scripts/git-pull", $output, $value);

echo "<pre>";  
echo "Return Value: {$value}\n";

foreach ( $output as $o) {
    echo $o."\n";


Note that /var/www/public_html/ is in fact a git repository. I often perform git pull in that directory from the CLI. However, when I call this script in a web browser I see that the files were not updated via git pull and the following is output to the browser:

Return Value: 1

This is on Ubuntu Server 12.04 with Git The remote repository is on the same server.

  • 1
    /usr/bin/git pull >/tmp/git.log 2>&1 and see what the error – Alex Sep 3 '13 at 11:31

Your script runs under www-data:www-data I suppose. You have to run the git pull with a user that have a write permission on your cloned repository. You have configured sudo, but you don't call it anywhere which doesn't make much sense (not saying you need to do that at all). Verify under what user you are running and then switch to appropriate one if needed and adjust permissions on your cloned repository accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.