Skip to content

Instantly share code, notes, and snippets.

@leymannx
Forked from cowboy/github_post_recieve.php
Last active November 6, 2018 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leymannx/91411e5494f5e04e000a7cf28df95447 to your computer and use it in GitHub Desktop.
Save leymannx/91411e5494f5e04e000a7cf28df95447 to your computer and use it in GitHub Desktop.
PHP webhook to pull and Gulp build automatically after push
<?php
if ( isset($_POST['payload']) && $_POST['payload'] ) {
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser git pull');
echo shell_exec('cd /var/www/mydrupal/sites/all/themes/mytheme/ && sudo -u myuser node ./node_modules/gulp/bin/gulp.js mygulptask');
// Adding the drush will cause the delivery being displayed as unsuccessful. Means GitHub doesn't wait so long. The command will run nevertheless.
echo shell_exec('cd /var/www/mydrupal/ && sudo -u myuser drush @sites cc all -y');
}
// Should return www-data
echo shell_exec('whoami');
// Should return myuser
echo shell_exec('sudo -u myuser whoami');
?>
@leymannx
Copy link
Author

leymannx commented Jul 3, 2017

/etc/sudoers:

www-data ALL = (myuser) NOPASSWD: /usr/bin/git
www-data ALL = (myuser) NOPASSWD: /usr/bin/node
www-data ALL = (myuser) NOPASSWD: /usr/bin/drush
www-data ALL = (myuser) NOPASSWD: /usr/bin/whoami

@adibnoh
Copy link

adibnoh commented Nov 6, 2018

Thanks man! this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment