安装部署
📦 安装部署
多种部署方式,满足不同场景需求
部署方式概览
Section titled “部署方式概览”Toolbox 支持以下部署方式:
| 部署方式 | 适用场景 | 难度 | 推荐度 |
|---|---|---|---|
| 虚拟主机 | 个人网站、小型项目 | ⭐⭐ | ⭐⭐⭐ |
| VPS/云服务器 | 生产环境、中大型项目 | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| Docker | 快速体验、开发测试 | ⭐ | ⭐⭐⭐⭐ |
| 宝塔面板 | 国内用户、可视化操作 | ⭐⭐ | ⭐⭐⭐⭐ |
传统部署(虚拟主机/VPS)
Section titled “传统部署(虚拟主机/VPS)”1. 环境准备
Section titled “1. 环境准备”安装 PHP 和扩展
Section titled “安装 PHP 和扩展”# 安装 PHP 8.0sudo apt updatesudo apt install php8.0 php8.0-fpm php8.0-mysql php8.0-fileinfo
# 安装 Redis 扩展(可选)sudo apt install php8.0-redis# 安装 PHP 8.0sudo yum install epel-releasesudo yum install php php-fpm php-mysql php-fileinfo
# 安装 Redis 扩展(可选)sudo yum install php-redis- 下载 PHP for Windows
- 解压到
C:\php\ - 复制
php.ini-development为php.ini - 启用扩展:
extension=fileinfoextension=pdo_mysql; 可选extension=redis
安装 MySQL
Section titled “安装 MySQL”# Ubuntu/Debiansudo apt install mysql-server
# CentOS/RHELsudo yum install mysql-server
# 创建数据库mysql -u root -pCREATE DATABASE toolbox CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;CREATE USER 'toolbox'@'localhost' IDENTIFIED BY 'your_password';GRANT ALL PRIVILEGES ON toolbox.* TO 'toolbox'@'localhost';FLUSH PRIVILEGES;EXIT;2. 下载和安装
Section titled “2. 下载和安装”# 进入网站目录cd /var/www/
# 下载最新版本wget https://github.com/netcccyun/toolbox/releases/latest/download/toolbox.zip
# 解压unzip toolbox.zip -d toolbox
# 设置权限chown -R www-data:www-data toolbox/chmod -R 755 toolbox/chmod -R 777 toolbox/runtime/chmod -R 777 toolbox/public/uploads/3. Web 服务器配置
Section titled “3. Web 服务器配置”Nginx 配置
Section titled “Nginx 配置”server { listen 80; server_name your-domain.com; root /var/www/toolbox/public; index index.php index.html;
# 伪静态规则 location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } }
# PHP 处理 location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
# 禁止访问敏感文件 location ~ /\.(env|git|gitignore|gitattributes|lock)$ { return 403; }
# 静态文件缓存 location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 30d; add_header Cache-Control "public, immutable"; }}Apache 配置
Section titled “Apache 配置”如果使用 Apache,确保已启用 mod_rewrite:
sudo a2enmod rewrite项目自带的 .htaccess 文件已包含伪静态规则:
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>4. 完成安装
Section titled “4. 完成安装”访问你的网站地址,按照安装向导完成安装。
Docker 部署
Section titled “Docker 部署”使用官方镜像
Section titled “使用官方镜像”# 拉取镜像docker pull netcccyun/toolbox
# 运行容器docker run --name toolbox -dit \ -p 8081:80 \ -v /var/toolbox:/app/www \ --restart unless-stopped \ netcccyun/toolbox
# 查看日志docker logs -f toolbox使用 Docker Compose
Section titled “使用 Docker Compose”创建 docker-compose.yml:
version: '3.8'
services: toolbox: image: netcccyun/toolbox container_name: toolbox ports: - "8081:80" volumes: - ./toolbox:/app/www restart: unless-stopped depends_on: - mysql - redis
mysql: image: mysql:5.7 container_name: toolbox-mysql environment: MYSQL_ROOT_PASSWORD: root_password MYSQL_DATABASE: toolbox MYSQL_USER: toolbox MYSQL_PASSWORD: toolbox_password volumes: - mysql_data:/var/lib/mysql restart: unless-stopped
redis: image: redis:alpine container_name: toolbox-redis restart: unless-stopped
volumes: mysql_data:启动服务:
docker-compose up -d宝塔面板部署
Section titled “宝塔面板部署”1. 创建网站
Section titled “1. 创建网站”- 登录宝塔面板
- 点击”网站” → “添加站点”
- 填写域名信息
- 选择 PHP 版本(建议 8.0)
- 创建数据库(记住账号密码)
2. 上传文件
Section titled “2. 上传文件”- 进入网站目录
- 上传 Toolbox 安装包
- 解压到当前目录
3. 配置伪静态
Section titled “3. 配置伪静态”在宝塔面板中:
- 点击网站 → 设置
- 选择”伪静态”选项卡
- 选择
thinkphp规则 - 保存
4. 设置运行目录
Section titled “4. 设置运行目录”- 点击网站 → 设置
- 选择”网站目录”选项卡
- 运行目录选择
/public - 取消勾选”防跨站攻击”
- 保存
访问网站地址,按向导完成安装。
云服务器部署
Section titled “云服务器部署”阿里云/腾讯云/华为云
Section titled “阿里云/腾讯云/华为云”-
安全组配置
- 开放 80/443 端口(HTTP/HTTPS)
- 开放 3306 端口(MySQL,如需远程访问)
-
域名解析
- 添加 A 记录指向服务器 IP
- 等待 DNS 生效
-
SSL 证书
- 使用 Let’s Encrypt 免费证书
- 或购买商业 SSL 证书
配置 HTTPS
Section titled “配置 HTTPS”Nginx HTTPS 配置
Section titled “Nginx HTTPS 配置”server { listen 443 ssl http2; server_name your-domain.com; root /var/www/toolbox/public; index index.php;
# SSL 证书 ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem;
# 其他配置...}
# HTTP 重定向到 HTTPSserver { listen 80; server_name your-domain.com; return 301 https://$server_name$request_uri;}目录权限设置
Section titled “目录权限设置”确保以下目录有正确的权限:
# 设置所有者chown -R www-data:www-data /var/www/toolbox
# 设置目录权限chmod -R 755 /var/www/toolbox
# 以下目录需要写入权限chmod -R 777 /var/www/toolbox/runtimechmod -R 777 /var/www/toolbox/public/uploadschmod -R 777 /var/www/toolbox/public/static/images常见问题排查
Section titled “常见问题排查”500 错误
Section titled “500 错误”检查:
- PHP 版本是否符合要求
- 扩展是否安装(fileinfo、pdo_mysql)
.env文件是否存在runtime目录是否有写入权限
数据库连接失败
Section titled “数据库连接失败”检查:
- 数据库服务是否运行
- 数据库账号密码是否正确
- 数据库用户是否有权限
- 防火墙是否放行 3306 端口
伪静态不生效
Section titled “伪静态不生效”检查:
- Web 服务器是否启用 rewrite 模块
- 伪静态规则是否正确
- 运行目录是否指向 public
🎉 部署完成!
现在可以访问你的网站并开始使用了~