gogs服务器php
linux网站服务器(宝塔)linux
本地客户端git
在public下新建githook.php文件,代码以下:服务器
<?php $cmd = "cd /www/wwwroot/testfc/pro/ && git reset --hard origin/master && sudo git pull origin master 2>&1"; $res = array(); exec($cmd,$res); var_dump($res);
有多台服务器就每一个服务器的网站public下都加这个,而后配置到gogs服务器去函数
4.1 先把cmd命令换成 $cmd = "cd /www/wwwroot/testfc/pro/ sudo git pull origin master 2>&1"; 测试下
var_dump($res); 打印出错误测试
可能会出现如下错误:网站
错误1:Warning: scandir() has been disabled for security reasons in…
缘由:LNMP 0.9禁用了部分存在危险的PHP函数,当前是exec没法执行
找到php版本,修改配置信息,搜索 disable_functions 把它后面的 exec去掉,保存,重启phpurl
错误2:sudo: no tty present and no askpass program specified
在宝塔上找到etc/sudoers 编辑 ,加入 %www ALL = NOPASSWD: ALLspa
错误3:fatal: could not read Username for
找到项目 .git/config文件夹 /www/wwwroot/testfc/pro/.git/config
在ip前面加上用户名与密码格式如: url = http://username:psd@xxx.xxx.xxx.xxx:3000/aaa/pro.git3d
有看到 Already up-to-date 字眼表示测试成功,把cmd改回去
点击项目git主页--》仓库设置,--》在左侧找到管理Web钩子,--》添加钩子--》输入githook.php地址,其余默认便可,点击添加,有多个服务器就配置多个钩子地址,客户端一旦推送,会同时触发