您的位置 首页 php

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 git@gitee.com# 手动拉取一下[root@iertf834n89df3ederz ~]# git clone git@gitee.com:wangcb123/api.evmo.cn.git  

2.gitee配置公钥

将第一步id_rsa.pub文件全部赋值到公钥输入框,然后点击保存

7dd274a9677b45cdbda269ee4f3e40d6

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.仓库配置

9c99473e23b24e7aaafde1c2dc61f66a

eded4af03d80425881c74885f69fd44b

此时已配置完成自动部署,对个人开发私活比较方便,希望大家共同学习,望哪位大神教教php怎么执行composer 安装命令

文章来源:智云一二三科技

文章标题:php脚本自动部署项目

文章地址:https://www.zhihuclub.com/31673.shtml

关于作者: 智云科技

热门文章

网站地图