1.确认服务器运行php-fpm的用户和用户组
2.切换到php-fpm的用户
su www
3.创建ssh免登秘钥
ls -al ~/.ssh/
ssh-keygen -t rsa -C "xxxx@126.com" //生成时全部默认
cat ~/.ssh/id_rsa.pub
4.在php-fpm用户下拉取代码
git clone git@gitee.com:项目地址 本地文件夹名
5.后续就可以在php-fpm拉取代码
<?php
require_once('./../application/common.php'); //基础方法文件
$target = '/data/project/ttkan'; // 服务器上 web 目录
$wwwUser = 'www';
$wwwGroup = 'www';
$cmds = [
"cd $target ",
// "git reset --hard origin/master && git clean -f ",
"git pull",
// "chown -R {$wwwUser}:{$wwwGroup} $target/",
];
exec("cd {$target}; git pull 2<&1;", $output);
pre($output);
/*foreach ($cmds as $cmd) {
$res = shell_exec($cmd);
pre($res);
}*/