创意电子

标题: php脚本自动摆设项目 [打印本页]

作者: 51编程    时间: 2021-9-13 16:29
标题: php脚本自动摆设项目
1.ssh公钥天生
#查看当前账户[root@iertf834n89df3ederz ~]# whoami#切换到nginx用户一定要切换,root天生的公钥不能用[root@iertf834n89df3ederz ~]# su wwwThis accout is currently not available.#如果无法切换[root@iertf834n89df3ederz ~]# usermode -s /bin/bash www# 然后就可以切换www用户了[root@iertf834n89df3ederz ~]# su www# 进入跟目次,查看是否存在.ssh文件夹,如果木有手动创建一个[root@iertf834n89df3ederz ~]# cd[root@iertf834n89df3ederz ~]# cd .ssh# 天生命令会天生两个文件[root@iertf834n89df3ederz ~]# ssh-keygen -t rsa -C "gitee邮箱"id_rsa  id_rsa.pub# 测试[root@iertf834n89df3ederz ~]# ssh [email protected]# 手动拉取一下[root@iertf834n89df3ederz ~]# git clone [email protected]:wangcb123/api.evmo.cn.git2.gitee设置公钥
将第一步id_rsa.pub文件全部赋值到公钥输入框,然后点击生存

                               
登录/注册后可看大图

3.编写php脚本
我这里只让develop分支自动部署可自行修改,composer安装更新不全不知道怎么回事,有大神可以教教。
将下面代码复制到php文件里并保证外网可以访问
$root    = '/home/wwwroot/';  //nginx站根目次$post    = json_decode(file_get_contents("php://input"),true);$dir     = $post['root'] ?? ''; //站点目次if(!$dir) die('not found root');$ssh_url = $post['project']['ssh_url'];$branch  = explode('/',$post['ref'])[2];if ($branch != 'develop' || $post['password'] != '123456'){    return false;}$path =  $root . $dir;if (is_dir($path)) {    $res = shell_exec("cd {$path} && git checkout {$branch} && git pull 2>&1");} else {    $res = shell_exec("cd {$root} && git clone {$ssh_url} {$dir} && cd {$dir} && git checkout -b develop origin/develop 2>&1");}/*if (file_exists($path.'/composer.json')){    //exec("(sh $path/build.sh >/dev/null & )");    passthru("cd {$path} && (php composer.phar install >/dev/null &)");}*/$res .= shell_exec("cd {$path} && chown -R www:www {$path} 2>&1");/*file_put_contents('./push.log', "[".date('Y-m-d H:i:s')."] ".json_encode([    'path'    => $path,    'branch'  => $branch,    'ssh_url' => $ssh_url,    'res'     => $res]).PHP_EOL,FILE_APPEND);*/echo 'success';4.仓库设置

                               
登录/注册后可看大图


                               
登录/注册后可看大图

此时已设置完成自动部署,对个人开发私活比较方便,希望各人共同学习,望哪位大神教教php怎么执行composer 安装命令
作者: 第一行代码    时间: 2021-9-13 16:32
厉害了
作者: 时间是贼md    时间: 2021-9-13 17:25
转发了
作者: 普罗米不休息    时间: 2021-9-13 19:15
php脚本自动部署项目




欢迎光临 创意电子 (https://www.wxcydz.cc/) Powered by Discuz! X3.4