ThinkPHP 在 CentOS 部署高频问题与排查清单
一 环境兼容性与依赖
php -v 确认版本;如需升级,建议通过 EPEL + Remi 仓库启用对应 PHP 8.x 并安装 CLI 与 FPM。composer install,必要时 composer dump-autoload -o;Composer 安装慢可设置国内镜像:composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/。composer install/update 与 dump-autoload,不要在生产环境使用 --ignore-platform-reqs 掩盖问题。二 目录权限与 SELinux
chown -R nginx:nginx runtime && chmod -R 755 runtime;避免使用 777。apache:apache。sestatus;如拦截访问,按需调整策略或将项目目录加入允许列表,避免 403/读写失败。三 路由重写与 PHP-FPM 连通
location / 中加入 try_files $uri $uri/ /index.php?$query_string;。fastcgi_pass unix:/run/php-fpm/www.sock;(路径以实际 www.conf 为准)。fastcgi_pass 127.0.0.1:9000;。fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 与 fastcgi_split_path_info/PATH_INFO,否则会出现空白页或 404。systemctl status php-fpm)、监听地址与 Nginx 配置是否一致、以及 SELinux/防火墙 是否阻断。.htaccess 覆盖(AllowOverride All)。四 配置文件与错误日志定位
.env 或 config/database.php 中的 DB_HOST/DB_NAME/DB_USER/DB_PASS/DB_PORT 是否正确;确保数据库服务已启动并可连接。PHP_ADMIN_VALUE "open_basedir=...",或在面板将其加入白名单。php.ini,从 disable_functions 移除 scandir 等被禁函数并重启 PHP-FPM。五 生产环境安全与性能
.env 中设 APP_DEBUG=false;php.ini 中 display_errors=Off,仅记录错误日志。location ~ /\.env { deny all; }。