webhook 执行文件
index.php 如下内容:
<?php
error_reporting(1);
// 网站的web目录
$target='/www/test';
$token='test_token';
$json=json_decode(file_get_contents('php://input'),true);
#print_r($json);
if($json['password']!=$token){
exit('error request');
}
$cmd=" cd $target ; sudo -Hu nginx git pull 2>&1"; # 这里的nginx 实际要看你的服务器环境
echo shell_exec($cmd);
echo 'ok';
?>
注意:
1) 这个方法可以判断当前php 执行用户
echo (get_current_user());
如果是: www 用户
最后要把 该index.php 文件 权限改为 www 777
2) php.ini 要开启 shell_exec 方法
所以 php.ini 里面的disable_functions 要删除掉 shell_exec
sudo -u nginx 要使用这个命令,必须把nginx 用户加入 /etc/sudoers 文件中
nginx ALL=(ALL:ALL) ALL