Skip to content

Instantly share code, notes, and snippets.

@nasirkhan
Last active December 5, 2023 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasirkhan/1486779e45301d208018f5d170e9ee7e to your computer and use it in GitHub Desktop.
Save nasirkhan/1486779e45301d208018f5d170e9ee7e to your computer and use it in GitHub Desktop.
Deploy to Production Server with Git Webhook using PHP. Configure a Webhook, push to repository and new code will be deployed automatically. Tested with Github, Gitlab webhook auto triggers.
<?php
/**
*
* GIT AUTO DEPLOYMENT SCRIPT
*
* GITHUB? GITLAB webhook
* -------------------------------
*
*/
// The commands
$commands = array(
'date',
'echo $PWD',
'whoami',
// 'git reset --hard HEAD',
'git pull',
'git status',
// 'git submodule sync',
// 'git submodule update',
// 'git submodule status',
);
// Run the commands for output
$output = '';
foreach ($commands as $command) {
// Run it
$tmp = exec($command);
// Output
$output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
$output .= htmlentities(trim($tmp)) . "\n";
}
// Make it pretty for manual user access (and why not?)
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Git Auto Deployment</title>
</head>
<body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 0 10px;">
<pre>
___________________________________
| |
| Git Auto Deployment v0.1 |
| https://gist.github.com/nasirkhan |
|___________________________________|
<?php echo $output; ?>
</pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment