<?php
//echo(shell_exec("whoami"));
if(function_exists("exec")){
$dir = "/home/www/test2";
$giturl = "https://gitee.com/xxxx/test2.git";
#$cute = "cd $dir && git pull $giturl 1>&2";
#$cute = "git --git-dir=$dir/.git --work-tree=$dir pull";
#echo $cute;
#$exe = shell_exec($cute);
# var_dump($exe);
$cmd = "cd $dir && git reset --hard && git pull";
echo ($cmd);
exec($cmd,$data);
var_dump($data);
echo( "pull finish : -".date('Y-m-d H:i:s'));
}else{
echo('php.ini :exec');
}
[root@iZ2zeaujzgp9b5nngo5avrZ testgit]# ps -ef | grep php
root 1072 1 0 15:51 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www 1073 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1074 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1075 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1076 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1077 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1078 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1079 1072 0 15:51 ? 00:00:00 php-fpm: pool www
www 1080 1072 0 15:51 ? 00:00:00 php-fpm: pool www
root 8160 27037 0 17:15 pts/4 00:00:00 grep --color=auto php
vim /etc/passwd
把 www:x:1000:1000::/home/www:/sbin/nologin
改成 www:x:1000:1000::/home/www:/bin/bash
su - www // 测试可以
exit //退出 www
vim /etc/sudoers
root ALL=(ALL) ALL
www ALL= NOPASSWD:/usr/bin/git
su www
git config --global credential.helper store
cd /home/www/test2 //要部署到www可以访问在文件夹
git clone https://gitee.com/xxxx/test2.git .
git pull
cat ~/.git-credentials
有 https://{username}:{password}@gitee.com
或者
添加公钥 参考: https://gitee.com/help/articles/4181
5. 访问测试 或设置到 WebHooks
直接访问 http://x.x.x.ip/git.php