cag8f
cag8f

Reputation: 968

GitHub webhook to auto-pull not working as expected

I'm trying to install a webhook in Github that will instruct my remote server to automatically pull from my Github repository whenever I push to the same repository, but it is not working as expected.

I followed the instructions in this guide (in the Automatic Git Pull on Server section). Here is exactly what I did:

--I created a simple PHP file containing only the line:

<?php `git pull`;’ >

and loaded it onto my web server.

--I then created the webhook in Github to run this file every time a push event occurs (I have double and triple checked that the correct file and path are specified).

But this is not working as expected. To be clear, the webhook fires as expected (whenever I push to Github), but the pull does not occur as expected. Any thoughts why? Perhaps syntax error? Perhaps permission error? Troubleshooting suggestions are also welcome. Are there logs I can review that would shed more light?

Possibly Relevant Info

Upvotes: 1

Views: 1098

Answers (2)

RAJAT MALIK
RAJAT MALIK

Reputation: 17

The PHP script you wrote doesn't work like this. Try the steps below:

  1. create this on site html folder
  2. add this in gitignore if you want.
  3. add url ex: https://domainname.com/deploy.php to webhooks
  4. deploy.php script code ::

     <?php
     echo exec('git pull http://github.com/rajatmalik3143/bug-fixes.git')
     #echo shell_exec('whoami')
      ?>
    
  5. chmod +x deploy.php

  6. chown apache:apache deploy.php
  7. chown apache:apache html/

Upvotes: 1

Patrick Boguet
Patrick Boguet

Reputation: 1

https://github.com/markomarkovic/simple-php-git-deploy/blob/master/deploy.php

I used an old version of this repo, that should work for you

Upvotes: 0

Related Questions