Files
AI-Chat/docs/DEPLOY.md
2026-05-08 10:05:31 +08:00

123 lines
2.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 部署指南
## 宝塔面板部署
### 1. 环境准备
在宝塔面板"软件商店"中安装:
- Nginx 1.22+
- PHP 8.0(在 PHP 设置中确保以下扩展已启用pdo_mysql、curl、mbstring、json、openssl
- MySQL 5.7 或 8.0
### 2. 创建网站
1. 网站 → 添加站点
2. 填写域名
3. PHP 版本选择 **PHP 8.0**
4. 数据库选择"不创建"(安装向导会连接你手动创建的数据库)
### 3. 部署代码
```bash
cd /www/wwwroot/your-domain.com
git clone <repository-url> .
composer install
```
### 4. 设置权限
```bash
chmod -R 755 .
chown -R www:www .
```
### 5. 配置伪静态
1. 站点设置 → 网站目录 → 运行目录改为 `/public`
2. 站点设置 → **伪静态** → 将 `docs/baota-nginx-snippet.conf` 的内容粘贴进去,保存
> 注意:是粘贴到"伪静态"输入框,不是"配置文件"。
> 如 PHP 版本不是 8.0,需将 `php-cgi-80` 改为对应版本号(如 `php-cgi-81`)。
### 6. 创建数据库
安装向导不会自动创建数据库,需要你提前手动创建:
1. 宝塔面板 → 数据库 → 添加数据库
2. 记录数据库名、用户名和密码,安装向导中需要填写
### 7. 运行安装向导
访问 `http://your-domain.com/install.php`,按步骤完成安装。
### 8. SSL 配置(可选)
站点设置 → SSL → Let's Encrypt → 申请证书
---
## 手动部署Nginx + PHP-FPM
### 1. 安装依赖
```bash
composer install
```
### 2. Nginx 站点配置
使用 `docs/nginx.conf` 作为完整的站点配置文件:
```bash
# 复制到 Nginx 配置目录
cp docs/nginx.conf /etc/nginx/sites-available/ai-chat
ln -s /etc/nginx/sites-available/ai-chat /etc/nginx/sites-enabled/
# 编辑配置,修改 server_name 和 root 路径
vim /etc/nginx/sites-available/ai-chat
# 测试并重载
nginx -t && nginx -s reload
```
### 3. 创建数据库
```sql
CREATE DATABASE ai_chat DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'ai_chat'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON ai_chat.* TO 'ai_chat'@'localhost';
FLUSH PRIVILEGES;
```
### 4. 目录权限
```bash
chown -R www-data:www-data /path/to/ai-chat
chmod 755 /path/to/ai-chat/public/uploads
chmod 755 /path/to/ai-chat/config
```
### 5. 运行安装向导
访问 `http://your-domain.com/install.php`
---
## 本地开发PHP 内置服务器)
```bash
php -S localhost:8080 -t public/ public/router.php
```
> 必须使用 `public/router.php` 作为路由文件,否则 `/api/*` 请求无法正确路由到 `api.php`。
---
## 安全建议
1. 配置 SSL 证书HTTPS
2. 修改数据库默认端口
3. 定期更新 PHP 和 Nginx 版本
4. 限制 uploads 目录的执行权限
5. 禁止访问 app/、config/、vendor/ 等非公开目录(已在 Nginx 配置中设置)