PHP使用webHook,搭建自动部署
1,首先我们的解决,shell_exec 没有被禁用
2,第二点,我们得给代码目录权限,默认www-data权限就可以了,因为是http访问
3,第三步,记得会有超时问题,如果我们的用的是github网络慢可能会失败,提示超时,或者项目太大了,我们可以先自己git clone xxx.git
在用git pull 触发拉取代码
4,调试问题,默认 shell_exec 没有提示,我们在最后面加 2>&1 会显示错误消息
5,我们的测试 例子中,是a项目,下面的文件到,b项目目录,这个你懂的,安全和隔离
贴上终代码
$json = file_get_contents('php://input');
$content = json_decode($json, true);
if (!empty($content['repository']['git_http_url']) && !empty($content['password']) && $content['password'] == 'szwtdl')
{
$pwd = getcwd();
// $command = 'cd ' . $pwd . ' && git pull https://gitee.com/liu21st/thinkphp.git 2>&1';
$info = shell_exec('cd /var/www/www.course.com && git pull 2>&1');
print_r($info);
}
喜欢就点个赞吧
发表评论
网友评论
暂无评论