码云配置webhook

1、编写webhook内容

<?php
    // function writelog($message,$logFileDir){
    //     $logFile = 'git_info.log';
    //     $log = date('Y-m-d H:i:s') . ' - ' . $message . "\n";
    //     $fp = fopen($logFileDir.$logFile, 'a+');
    //     fwrite($fp, $log);
    //     fclose($fp);
    // }
    $target = dirname(__FILE__);
    $json = json_decode(file_get_contents('php://input'), true);
    $password='yourPassoword';
    // writelog(json_encode($json));
    if (empty($json['password']) || $json['password'] !== $password) {
        exit('error request');
    }
    $cmd=" cd {$target} ;sudo -Hu www git pull 2<&1";
    $r= shell_exec($cmd);
    print_r($r);
    echo date('Y-m-d H:i:s');

2、linux将www用户加入sudoers并赋予无密码执行git命令权限

(1)为当前用户添加写入sudoers的权限
	chmod u+w /etc/sudoers
(2)编辑sudoers
	vim /etc/sudoers
(3)搜索Allow root to run any commands anywhere,插入模式在root用户对应行下写入如下内容:
	www     ALL=(ALL)       NOPASSWD:/usr/bin/git
(4)收回对sudoers的写入权限
	chmod u-w /etc/sudoers

3、编辑php.ini,搜索disable_functions删掉shell_exec

vim /usr/local/php/etc/php.ini
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值