在 Ubuntu 上访问 ThinkPHP 项目出现空白页面(白屏),通常是配置或环境问题。下面按最常见原因 → 排查方法给你一个完整清单。
ThinkPHP 默认在生产环境会隐藏错误,所以白屏看不到原因。
解决方法:
编辑入口文件 public/index.php
// 临时开启错误
ini_set('display_errors', 'On');
error_reporting(E_ALL);
或 .env
APP_DEBUG = true
然后刷新页面,一般就能看到报错。
ThinkPHP 需要写 runtime 目录。
sudo chmod -R 755 runtime
sudo chown -R www-data:www-data runtime
(nginx/apache 用户通常是 www-data)
❌ 错误:指向了项目根目录
✅ 正确:必须指向 public
Nginx 示例:
root /var/www/project/public;
Apache:
DocumentRoot /var/www/project/public
改完重启:
sudo systemctl restart nginx
# 或
sudo systemctl restart apache2
ThinkPHP 需要 URL 重写。
Nginx:
location / {
try_files $uri $uri/ /index.php?s=$request_uri;
}
Apache:
确保有 .htaccess(在 public 下)
ThinkPHP 6 需要 PHP ≥ 7.2
ThinkPHP 8 需要 PHP ≥ 8.0
php -v
sudo apt install php-mbstring php-xml php-curl php-json php-zip
重启 PHP:
sudo systemctl restart php8.1-fpm
composer install
如果没装,直接白屏。
tail -f /var/log/nginx/error.log
tail -f /var/log/php8.1-fpm.log
runtime/log/
/public如果你愿意,可以把:
发给我,我可以直接帮你定位是哪一行配置的问题。