Report this

What is the reason for this report?

Git auto-deploy from Webhook giving permissions error?

Posted on February 26, 2019

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.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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.

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Jarland

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.