三长两短 - PHP后端部署完整教程
php -m | grep -E 'pdo|mysql|json|mbstring|openssl'
需要启用:PDO, pdo_mysql, json, mbstring, openssl
# 下载并解压
cd /www/wwwroot/
unzip threelongtwo-server.zip
cd um.dazitai.com
# 设置权限
chmod 755 /www/wwwroot/um.dazitai.com
chmod 755 install/
浏览器打开:http://um.dazitai.com/install/
rm -rf /www/wwwroot/um.dazitai.com/install/
# CentOS
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh
# Ubuntu/Debian
wget -O install.sh https://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
在宝塔面板 > 软件商店中安装:
宝塔面板 > 软件商店 > PHP 8.0 > 设置
putenv, proc_openupload_max_filesize = 20M宝塔面板 > 网站 > 添加站点
um.dazitai.com/www/wwwroot/um.dazitai.com网站 > um.dazitai.com > 设置 > 配置文件
server {
listen 80;
server_name um.dazitai.com;
root /www/wwwroot/um.dazitai.com;
index index.php index.html;
# API路由
location /api/ {
try_files $uri $uri/ /api/index.php?$query_string;
}
# PHP处理
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi-80.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 安全配置
location ~ /\. {
deny all;
}
}
http://um.dazitai.com/install/# 安装Docker
curl -fsSL https://get.docker.com | bash
systemctl start docker
systemctl enable docker
# 安装Docker Compose
curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
version: '3.8'
services:
php:
image: php:8.1-fpm-alpine
volumes:
- ./:/var/www/html
depends_on:
- mysql
nginx:
image: nginx:alpine
ports:
- "80:80"
volumes:
- ./:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: threelongtwo
MYSQL_USER: app_user
MYSQL_PASSWORD: app_password
volumes:
- mysql_data:/var/lib/mysql
redis:
image: redis:alpine
command: redis-server --appendonly yes
volumes:
mysql_data:
docker-compose up -d
浏览器打开:http://localhost/install/
# CentOS/RHEL
yum install -y mysql-server
systemctl start mysqld
systemctl enable mysqld
# Ubuntu/Debian
apt install -y mysql-server
systemctl start mysql
systemctl enable mysql
mysql -u root -p
CREATE DATABASE threelongtwo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON threelongtwo.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
mysql -u app_user -p threelongtwo < database/schema.sql
cp .env.example .env
vim .env
# 编辑以下内容
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=threelongtwo
DB_USERNAME=app_user
DB_PASSWORD=your_password
vim /etc/nginx/conf.d/threelongtwo.conf
# 添加配置(参考宝塔部署中的Nginx配置)
nginx -t
systemctl reload nginx
chown -R www-data:www-data /var/www/threelongtwo
chmod -R 755 /var/www/threelongtwo
chmod 644 .env
curl http://um.dazitai.com/api/health
{
"status": "healthy",
"services": {
"database": {
"status": "connected"
}
}
}
# 测试分享码检查
curl -X POST http://um.dazitai.com/api/share-code/check \
-H "Content-Type: application/json" \
-d '{"shareCode":"ABC123","codeLength":6}'
try_files 是否正确/api/ 路由配置systemctl reload nginxsystemctl status mysqlmysql -u app_user -p -h 127.0.0.1ls -laps aux | grep php-fpmchown -R www-data:www-data .http://um.dazitai.com/debug-env.php - 环境配置诊断http://um.dazitai.com/test-env.php - 数据库连接测试http://um.dazitai.com/api/health - 健康检查