OS - Ubuntu 14.04
I am working on deployment using GIT webhooks for it.
I have added the deployment keys to git repo and now I want to trigger the git pull origin master
command when a push happens from my local repo.
This is the test.php
file I call via browser:
<?php
//echo "THis is a test file on a test repo for testing the deploy functionality using github webhooks!!!!";
echo exec('whoami');
echo exec('sh -x /var/www/proj/test/git.sh');
?>
This is the git.sh
shell file:
#!/bin/bash
cd /var/www/proj-dir/test
git pull origin master
When I run this on terminal using php test.php
I get the correct result as expected:
ubuntu From github.com:repo/test
* branch master -> FETCH_HEAD
Already up-to-date.
ubuntu
for whoami
followed by the git pull
output.
Now here's the issue when I call the same http://example.com/test.php
via the browser it shows the user or whoami
output as www-data
, which is apache user, but I tried updating the permissions of the php file to execute and changing the user to www-data
but did not work.
checked the apache logs and when I execute through the browser I get a permission error
Please make sure you have the correct access rights and the repository exists. + cd /var/www/proj/deploy-test + git pull origin master
Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
What updates do I need to make so the file works via browser request?
If I need to update the sudoers file what should be the updates?
Update
I added the .ssh
keys to the var/www/
dir as that is the home for apache user. But I still get the
git pull origin master
error: cannot open .git/FETCH_HEAD: Permission denied
Also I added a line for the www-data user to be able to execute the sh file.
www-data ALL=(anthony) NOPASSWD: /var/www/mysite/vendor/tmd/auto-git-pull/scripts/git-pull.sh
Reference here Still no luck
Updated the permissions for .git folder to www-data user
sudo chown www-data:www-data /var/www/proj/test/.git