Skip to content

Instantly share code, notes, and snippets.

@yusureabc
Created July 16, 2018 06:22
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 yusureabc/dd404c67f412f925c43ef045143a15cf to your computer and use it in GitHub Desktop.
Save yusureabc/dd404c67f412f925c43ef045143a15cf to your computer and use it in GitHub Desktop.
Git WebHook 自动更新代码
<?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