Skip to content
Advertisement

Git WebHook will not pull (PHP)

I have a PHP file, hook.php, that looks like this:

<?php `cd .. && git pull`;

The file is located in /var/www/oliverash.me/site/. However, the git repository that needs to be pulled is /var/www/oliverash.me/. ./site is the folder Apache looks to as the document root.

When I run the file in my browser, it does not seem to be pulling the repository.

I have also tried to echo the result, but the page is blank.

<?php echo `cd .. && git pull`;

Advertisement

Answer

I can’t post a comment in reply to you, but I am assuming that you are running a *nix system. You will be getting a permission denied if your apache/php daemons don’t have permission to access .git/. You can change the owner/group of the .git/ directory recursively. Or do a chmod -R o+rw .git/* to give everyone (ie, not owner, not group) access to read and write in the git directory, which should clear up the permissions error that you are getting.

EDIT Just re-read the question, so what follows probably isn’t needed, but leaving it just in case.

Though, doing that, you need to keep in mind that anyone with access to your server will be able to go to http://myurl/.git/ etc to access those. So as a security precaution, I would add a .htaccess file like:

order deny, allow
deny from all

in the.git directory so that apache will deny access from a web browser to everything in there.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement