Git auto-deploy from Webhook giving permissions error?

Posted February 26, 2019 3.1k views

Hi all. I have an Ubuntu server which I want to update whenever new code is pushed to a remote repository. I can successfully run a “git pull” from the command line when I Putty into the server and am at the file location. I have code working to verify the secret key is correct, but I can’t seem to get the code to execute “git pull” successfully. It returns the following error:
“error: cannot open .git/FETCH_HEAD: Permission denied”

This makes me think that the “user” (the script being run) doesn’t have permission to access git? Because I can manually run “git pull” from the directory in Putty successfully, but when using PHP and putting shell_exec(‘git pull’), it returns that error.

I assume the solution needs to involve setting user permissions in the line before calling git pull. But I’m unsure what this shell snippet code should be.

Thanks every much for your help, I’m brand new to Digital ocean, and cloud computing in general.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hey friend,

It sounds like you’re running as a privileged user (not root) and executing a git pull on files that the user does not have access to. You could probably just make the user a sudo user and toss a sudo in front of the git pull. There are other ways to do it but it depends on your user/group setup.