Created
July 16, 2018 06:22
-
-
Save yusureabc/dd404c67f412f925c43ef045143a15cf to your computer and use it in GitHub Desktop.
Git WebHook 自动更新代码
This file contains 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 WebHook 自动更新代码 */ | |
/* 成功条件:1. php 的运行用户(一般是www-data)需要 sudo 免密码 2. git 需要记住密码 */ | |
define( 'PASSWORD', '123456' ); | |
$requestBody = file_get_contents( "php://input" ); | |
$content = json_decode( $requestBody, true ); | |
/* 验证密码 */ | |
if ( $content['password'] != PASSWORD ) return false; | |
$web_path = '/mnt/www/xxxxxx'; | |
$res = shell_exec( "cd {$web_path} && sudo git pull origin master" ); | |
exit( $res ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment