当前位置:首页 > 技术文章 > 正文内容

php脚本自动部署项目(php一键安装脚本)

arlanguage3个月前 (01-31)技术文章25

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 安装命令

扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/1401.html

分享给朋友:

“php脚本自动部署项目(php一键安装脚本)” 的相关文章

nginx 多域名配置 nginx多站点配置示例

Nginx 可以配置多个域名,以便根据不同的域名来处理不同的请求。下面是一个配置多个域名的例子:server { listen 80; server_name example1.com; location / { root /var/www/example1...

NGINX配置跨域CORS支持 nginx配置跨域请求

NGINX配置跨域CORS支持这两天在搞酷瓜云网课的 app,采用 uni-app 做全端支持,现学现卖,目前算是入门了。在做 H5 的时候难免会跨域请求后端 API,虽然用 HBuilder 内置的浏览器不会有跨域问题(这个应该是做了内部处理),但是那个内置浏览器真尼妈坑爹,过一会就会卡死,导致...

PHP nginx配置 配置nginx支持php

在配置 PHP 和 nginx 以运行 PHP 应用程序时,您需要进行以下步骤:安装 nginx 和 PHP:如果您的系统上尚未安装 nginx 和 PHP,请根据您的操作系统的说明来安装它们。配置 nginx:您需要为 PHP 应用程序创建 nginx 服务器配置。您可以使用以下代码作为模板:ph...

Nginx 问题以及对应的解决方案

1. Nginx 无法启动当 Nginx 无法启动时,通常是由于以下几个原因导致的:配置文件有误。可以通过运行 nginx -t 命令检查配置文件是否存在语法错误。端口被占用。可以通过运行 netstat -tlnp 命令查看当前系统中占用该端口的进程,并将其停止或更改端口。缺少权限。Nginx 可...

Linux 系统安装 Nginx

Linux 系统安装 NginxCentOS 7 Nginx 源代码编译安装# 官网下载最新版 https://nginx.org/en/download.html # 系统安装必备组件: yum install gcc gcc-c++ pcre pcre-devel zlib-devel ope...

到 2024 年了,全球仍有 76.4% 的网站在用「已死」的 PHP!

如今资历稍长的程序员,提到 PHP 可能都会联想到一个梗:“PHP 是最好的语言。”这个梗并非出自别处,正源自于 PHP 自己的官方文档:早在 2001 年 7 月,PHP 文档中就有一句“PHP is the best language for web programming(PHP 是世界上最好...