Linux 上 Laravel 启动失败的原因非常多,通常需要结合具体报错信息来判断。下面我按最常见原因 → 排查方法 → 解决方式给你一个系统性的清单,你可以逐条对照。
不同 Laravel 版本对 PHP 有要求:
| Laravel | PHP |
|---|---|
| 11 | ≥ 8.2 |
| 10 | ≥ 8.1 |
| 9 | ≥ 8.0 |
| 8 | ≥ 7.3 |
检查:
php -v
解决:
刚 clone 项目最常犯。
报错示例:
Class 'App\Http\Controllers\Controller' not found
解决:
composer install
Laravel 启动必须有 .env
解决:
cp .env.example .env
php artisan key:generate
storage / bootstrap/cache 没写权限
典型报错:
The stream or file "/storage/logs/laravel.log" could not be opened
修复权限:
chmod -R 755 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
www-data视你的 web 服务而定(nginx/apache)
Nginx 常见错误:
index.php正确 Nginx 示例:
root /var/www/laravel/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Laravel 必需扩展:
mbstring
xml
ctype
json
tokenizer
openssl
pdo
检查:
php -m
安装(Ubuntu 示例):
sudo apt install php-mbstring php-xml php-curl
报错:
SQLSTATE[HY000] [2002] Connection refused
排查:
.env 中 DB 配置是否正确systemctl status mysql
php artisan serve
失败可能是:
Address already in use
解决:
php artisan serve --port=8001
tail -f storage/logs/laravel.log
.env
APP_DEBUG=true
请把以下信息发我:
php artisan serve我可以直接帮你指出是哪一行配置或环境问题。