【服务器】
1、切换到项目目录下 cd /data/www/test
2、进入 .git 文件夹 cd .git 然后 ll
3、授权
chmod -R 777 FETCH_HEAD
chmod -R 777 ./objects
chmod -R 777 ./refs
chmod -R 777 ./logs
【代码】
在public下建一个文件test.php,然后使用网址 www.test.com/test.php能够访问(外网能访问)
写上:
<?php
/**
* 自动更新钩子
**/
//本地路径
$local = '/data/wwwroot/test'; //需要修改为自己服务器上项目的路径的
//密码
$password = 'test123'; //webhooks中设置的密码
//获取请求参数
$request = file_get_contents('php://input');
if (empty($request)) {
die('request is empty');
}
//验证密码是否正确
$data = json_decode($request, true);
if ($data['password'] != $password) {
die('password is error');
}
//仓库地址
$remote = 'https://用户名:密码@gitee.com/xxxxxxx/xxxx.git'; //自己git仓库,加上用户名密码防止没有权限
echo shell_exec("cd {$local} && git pull {$remote} 2>&1");
die('done ' . date('Y-m-d H:i:s', time()));
【GITEE】
进入具体的项目中,点管理,然后点击webhooks添加钩子