> For the complete documentation index, see [llms.txt](https://proxypanel.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://proxypanel.gitbook.io/wiki/deploy/oneinstack-1.md).

# 手动部署 - \[OneinStack]

{% hint style="warning" %}
**请使用root账户进行操作!**
{% endhint %}

## 安装所需软件

{% tabs %}
{% tab title="Debian" %}

```
apt update && apt install wget curl git vim -y
```

{% endtab %}

{% tab title="Centos" %}

```
yum update -y && yum install wget curl git vim -y
```

{% endtab %}
{% endtabs %}

## 安装oneinstack

{% hint style="danger" %}
如果害怕遇到网络中断,SSH断连等问题,可以自行谷歌nohup/screen的用法
{% endhint %}

前往[oneinstack官网](https://oneinstack.com/auto/)选择合适的软件,再复制安装命令到SSH上执行

* PHP >= 7.2.5
  * PHP缓存 Opcache （可选，推荐）
  * fileinfo
  * redis
* MySQL 5.5+
* Redis 无版本要求

![](/files/-Mf8qu_cYUbv_CeE9HWj)

{% hint style="warning" %}
**别忘了DB密码，这个真的很重要!**
{% endhint %}

安装时间视机器配置而定,vultr 2C2G 安装大概20分钟左右

安装完成后会输出nginx等软件的存放位置，安装后别忘记重启

![Install.png](https://imgpp.com/images/2021/07/21/Install.png)

## 创建网站

{% hint style="warning" %}
请先做好域名解析后，再开始创建网站!

如果域名有开启CDN，请先关闭，CDN会影响到之后的证书获取
{% endhint %}

SSH连接到VPS后输入下方命令,创建网站

```
/root/oneinstack/vhost.sh
```

1. 三个选项分别是使用HTTP,使用自己的证书,以及申请免费证书
2. 输入网站域名
3. 网站目录,直接回车网站目录默认位于`/data/wwwroot/网站域名`
4. 是否需要添加更多域名
5. 是否需要HTTP重定向到HTTPS
6. 申请证书使用的邮箱

![creat-website5998a3999d9ff7b7.png](https://imgpp.com/images/2021/07/20/creat-website5998a3999d9ff7b7.png)

自动申请完证书后,还有几步

1. 是否需要热链接保护
2. 是否需要添加伪静态规则
3. 添加哪种伪静态规则(这里直接回车,自带的laravel规则和proxypanel所需的不同)
4. 是否允许记录访问日志

![ssl.png](https://imgpp.com/images/2021/07/20/ssl.png)

{% hint style="success" %}
推荐使用SFTP修改文件不容易出错,~~下面是为了偷懒所以才的vim~~,当然你也可以换成你喜欢的编辑器
{% endhint %}

### 删除禁用函数

```
vim /usr/local/php/etc/php.ini
```

删除以下禁用函数:

* proc\_open
* proc\_get\_status
* symlink

![phpDisableFunctions.png](https://imgpp.com/images/2021/07/21/phpDisableFunctions.png)

删除后重启PHP

```
service php-fpm restart
```

### 修改网站运行目录

```
vim /usr/local/nginx/conf/vhost/网站域名.conf
```

在root开头那行末尾添加/public,别忘了末尾的分号

![nginx48f87e1f222f1e13.png](https://imgpp.com/images/2021/07/21/nginx48f87e1f222f1e13.png)

### 添加伪静态

```
vim /usr/local/nginx/conf/rewrite/other.conf
```

添加以下伪静态规则

```
location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}
```

重启nginx

```
systemctl restart nginx
```

## 创建数据库与用户

### 登录并创建数据库

首先使用以下命令登录mysql,并输入密码(密码是啥?请看安装oneinstack小节)

```
mysql -u root -p
```

创建数据库,查看数据库是否创建成功

```
create database ProxyPanel default character set utf8mb4 collate utf8mb4_unicode_ci;
show databases;
```

{% hint style="success" %}
如果想偷懒，跳过创建数据库用户，直接使用root用户
{% endhint %}

### 创建数据库用户

创建名为ProxyPanel的用户,密码为ProxyPanel(自行更换密码),并给ProxyPanel用户ProxyPanel数据库的所有权限以及所有数据库的使用权限

```
grant usage on *.* to ProxyPanel@'localhost' identified by 'ProxyPanel';
grant  all  privileges  on  ProxyPanel.*  to  ProxyPanel@'localhost' identified by 'ProxyPanel';
flush privileges;
```

{% hint style="danger" %}
如果创建用户失败请尝试先删除用户后再刷新权限

```
drop user 'ProxyPanel'@'localhost';
flush privileges;
```

{% endhint %}

## 安装面板

```
cd /data/wwwroot/网站域名
git clone https://github.com/ProxyPanel/ProxyPanel.git .
cp .env.example .env
```

编辑`.env`

{% hint style="danger" %}
如果跳过了创建数据库用户,下方需要修改为root用户和密码
{% endhint %}

```
vim .env
```

参照下方含义进行编辑

```
| Key                          | Value              |        含义                             |
| ------------------------ |:----------------:| --------------------------:|
| DB_HOST               | localhost        | 数据库IP/域名 |
| DB_PORT               | 3306               | 数据库端口  |
| DB_DATABASE    | ProxyPanel     | 数据库名 |
| DB_USERNAME   | ProxyPanel    | 用户名 |
| DB_PASSWORD    | ProxyPanel    | 密码 |
```

### 安装依赖

输入下方命令安装PHP Composer,安装过程很简单,就不多赘述.

```
/root/oneinstack/addons.sh
```

再运行以下代码安装依赖

```
composer install --prefer-dist --optimize-autoloader --no-dev
```

### 导入数据库

```
php artisan migrate --seed
```

### 必要环境设置

```
php artisan key:generate
php artisan storage:link
chown -R www:www storage/ 
chmod -R 777 storage/
```

### 设置定时任务

```
mkdir /home/www && chown -R www:www /home/www && chmod -R 777 /home/www
crontab -e -u www
* * * * * php /data/wwwroot/网站域名/artisan schedule:run >> /dev/null 2>&1
```

### 设置队列管理 Horizon

```sh
cat > /etc/supervisor/conf.d/horizon.conf <<EOF
[program:horizon]
process_name=%(program_name)s
command=php $(pwd)/artisan horizon
autostart=true
autorestart=true
user=www
redirect_stderr=true
stdout_logfile=$(pwd)/storage/logs/horizon.log
stopwaitsecs=3600
EOF

supervisorctl reread
supervisorctl update
supervisorctl start horizon
```

### 设置广播 Reverb <a href="#reverb" id="reverb"></a>

{% hint style="info" %}
【广播】 应用于内容的实时同步，目前用于用户支付结果查询，管理节点页面节点连通性，地理位置更新，重启结果等，需要内容实时在页面显示的场景。
{% endhint %}

大致步骤：

1. 编辑目录下 `.env` 文件中 REVERB\_ 开头参数；
2. 清理缓存  `php artisan optimize:clear && php artisan optimize`
3. 重新编译前端js和重启reverb，`npm run build && supervisorctl restart reverb`
4. 添加/修改网站nginx配置文件<br>

   <pre class="language-nginx" data-line-numbers data-full-width="false"><code class="lang-nginx">server {
       ...

   <strong>    location / {
   </strong>        proxy_http_version 1.1;
           proxy_set_header Host $http_host;
           proxy_set_header Scheme $scheme;
           proxy_set_header SERVER_PORT $server_port;
           proxy_set_header REMOTE_ADDR $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection "Upgrade";

   <strong>        proxy_pass http://0.0.0.0:8080;
   </strong>    }

       ...
   }
   </code></pre>

#### 通用修改/存在参数

| env参数               | 值                   |
| ------------------- | ------------------- |
| BROADCAST\_DRIVER   | `reverb`            |
| REVERB\_APP\_ID     | 随机数字id              |
| REVERB\_APP\_KEY    | 随机字符串               |
| REVERB\_APP\_SECRET | 随机字符串               |
| REVERB\_SCHEME      | 可选，值为`http`/`https` |

{% hint style="success" %}
以下配置按照自生需求选<mark style="color:$danger;">一个</mark>配置
{% endhint %}

<h4 align="center"><mark style="color:$primary;">方案A 广播使用与面板同子域名</mark></h4>

通知和面板都是使用：proxypanel.ddo.jp；← 域名是为了方便理解使用的案例

* 配置env，REVERB\_PATH， 用于分流正常访问和通知访问；

|              | 作用                                                        | 备注                  |
| ------------ | --------------------------------------------------------- | ------------------- |
| REVERB\_PATH | Reverb 服务器期望接收连接的 URL 路径。在您的配置中为 `REVERB_PATH=`，表示没有路径前缀。 | 例如：`/eventcastsing` |
| REVERB\_HOST |                                                           | proxypanel.ddo.jp   |

```bash
REVERB_APP_ID=510141
REVERB_APP_KEY=ti12342lbcrgjzazvua6
REVERB_APP_SECRET=kvjczliy123hrylnh56z
REVERB_SCHEME=https
REVERB_HOST=proxypanel.ddo.jp
REVERB_PATH=/eventcastsing

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
VITE_REVERB_PATH="${REVERB_PATH}"
REVERB_SERVER_PATH="${REVERB_PATH}"
```

修改nginx配置中第4行需要按照REVERB\_PATH值修改

<pre class="language-nginx" data-overflow="wrap" data-line-numbers><code class="lang-nginx">server {
    ...

<strong>    location /eventcastsing/ {
</strong>        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        proxy_pass http://0.0.0.0:8080;
    }

    ...
}
</code></pre>

***

<h4 align="center"><mark style="color:$primary;">方案B 广播使用与面板使用不同子域名</mark></h4>

* 面板使用：proxypanel.ddo.jp；← 域名是为了方便理解使用的案例
  * 通知使用：b.ddo.jp 或者 proxypanel.work.gd
* 配置env，REVERB\_HOST；

|              | 作用 | 备注                 |
| ------------ | -- | ------------------ |
| REVERB\_HOST |    | proxypanel.work.gd |

```bash
REVERB_APP_ID=510141
REVERB_APP_KEY=ti12342lbcrgjzazvua6
REVERB_APP_SECRET=kvjczliy123hrylnh56z
REVERB_SCHEME=https
REVERB_HOST=proxypanel.work.gd
REVERB_PATH=

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
VITE_REVERB_PATH="${REVERB_PATH}"
REVERB_SERVER_PATH="${REVERB_PATH}"
```

### 优化

{% hint style="info" %}
每次修改 `.env` 后，请运行以下代码，重新预加载必要文件
{% endhint %}

```
php artisan optimize
```

## 更新

### 面板

```
sh /www/wwwroot/demo.proxypanel.ml/update.sh
```

### 数据库

```
php artisan migrate
```
