Last active
January 25, 2024 17:34
-
-
Save phedoreanu/11321236 to your computer and use it in GitHub Desktop.
git PHP webhook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mkdir -m 0700 /var/www/.ssh | |
sudo chown -R apache:apache /var/www/.ssh | |
sudo -u apache ssh-keygen (empty passphrase) | |
paste public key into repo manager | |
(git-repo) sudo -u apache git pull origin branch (this will create /var/www/.ssh/known_hosts) | |
call git_hook.php?branch=xxx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$gh_ips = array('171.149.246.236', '95.92.138.4'); | |
if (in_array($_SERVER['REMOTE_ADDR'], $gh_ips) === false) { | |
header('Status: 403 Your IP is not on our list; bugger off', true, 403); | |
mail('root', 'Unfuddle hook error: bad ip', $_SERVER['REMOTE_ADDR']); | |
die(1); | |
} | |
$BRANCH = $_GET['branch']; | |
if (!empty($BRANCH)) { | |
$output = shell_exec("cd /srv/www/git-repo/; git pull origin {$BRANCH};"); | |
echo "<pre>$output</pre>"; | |
} | |
die("done " . mktime()); |
I'm trying to understand all of this, I've been struggling on all of this for like 4 hours now. I'm just trying to catch the webhook from my Github repo, and if I catch it : launch a script to "git pull" ! I know a bit of php so I thought it wouldn't be too difficult but know : either apache doesn't have the right permissions to perform any of my commands (like exec or anything else), so I came here to see that with a customization of ssh I could maybe overcome this difficulty, and maybe, but I don't understand the "call git_hook.php?branch=xxx" part... Do I have to call "myserver.com/.../git_hook.php?branch=xxx" in the webhook ?
I'm just lost and tired so I really like to make a clear, simple solution for webhooks-autopull ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@JackdeVilliers
It's here: https://github.com/_yourLogin/_repoName/settings/keys