Github <> remote server, auto deploy, the webhook doesn't work

566 views Asked by At

When I push to the github project from any local computer, I want my remote server to pull automatically (its a php website project)

I've searched on google and youtube but having spent an entire day I didn't find how do that.

In my http://xxx.xxx.xxx.xxx/website/, there are the .git folder and the github.php file deploy

github.php :

<?php
`git pull origin master`;
`touch test.txt`;

If I execute ./github.php from a terminal, the "script" works well. The pull works too.

If I enter the url http://xxx.xxx.xxx.xxx/website/github.php, from my browser, the pull doesn't work, but a test.txt is created.

If I push a commit from any local computer, the remote server doesn't pull automaticaly and the test.txt file isn't created;

In my remote server, the permissions are :

  • for .git directory : drwxrwxrwx 8 toji toji 4096 Jun 14 13:31 (-R)

  • for github.php : -rwxrwxrwx 1 toji toji 51 Jun 14 13:28

In my github account, I add a webhook service : Payload URL is : http://xxx.xxx.xxx.xxx/website/github.php

Please help me determine the origin of my problem.

1

There are 1 answers

0
noelboss On

I don't think your PHP is valid since you need to use something like exec() to use git in php... I had the same problem a few days ago and found little tools to help deploy your code from Github or Gitlab so I created Deepl.io to handle Web-Hooks and call scripts to deploy on your own server. This handles the JSON that's sent from github or gitlab and can be used for multiple repositories and branches etc. You can use your own PHP or shell scripts after receiving the pull notification and it sends you status e-mails after every deploy... Check it out: http://deepl.io

The shell scrip that is actually executed (called by php) is something as follows;

#!/bin/sh

TRAGET="/path/to/target/folder"
LOG="/path/to/your/log/file.log"
NOW=$(date +"%Y-%m-%d-%H%M%S")

# Start Sctipt
echo "
SCRIPT START: $NOW" >> $LOG

cd $TRAGET >> $LOG

# checkout correct branch
git checkout master >> $LOG

# clear untracked files
git clean -df >> $LOG

# revert local changes
git checkout -- . >> $LOG

# pulling new stuff
git pull >> $LOG

echo "SCRIPT END.
" >> $LOG