Last active
December 5, 2023 16:47
-
-
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.
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 | |
/** | |
* | |
* 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