网站首页 > 基础教程 正文
1.ssh公钥生成
#查看当前账户
[root@iertf834n89df3ederz ~]# whoami
#切换到nginx用户一定要切换,root生成的公钥不能用
[root@iertf834n89df3ederz ~]# su www
This 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文件全部赋值到公钥输入框,然后点击保存
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 安装命令
- 上一篇: PHP怎么连接Mysql数据库
- 下一篇: PHP8.2将会有哪些新东西?
猜你喜欢
- 2024-11-23 西邮冯景瑜团队挖掘到CVE漏洞,被国家信息安全漏洞库收录公布
- 2024-11-23 PHP操作SQL数据库增删改查的代码
- 2024-11-23 简单轻量级的php的web防火墙,拦截SQL注入和XSS攻击
- 2024-11-23 PHP操作FTP类实现(上传、下载、移动、创建)的方法
- 2024-11-23 PHP7开发API离不开签名验证,你是如何设计?
- 2024-11-23 PHP连接msSQL数据库方法
- 2024-11-23 「PHP」如何使用imap协议接收邮件
- 2024-11-23 php 多进程是如何实现的?
- 2024-11-23 PHP自动加载学习记录
- 2024-11-23 PHP安全编码规范不可忽略
- 最近发表
- 标签列表
-
- jsp (69)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (86)
- location.href (69)
- dockerexec (65)
- tail-f (79)
- queryselectorall (63)
- location.search (79)
- bootstrap教程 (74)
- deletesql (62)
- linuxgzip (68)
- 字符串连接 (73)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)