Laravel 在 Debian 上报错的原因有很多,通常并不是“Laravel 本身不支持 Debian”,而是环境配置或权限问题。下面按最常见原因给你一个排查清单,你可以对照看是哪一种。
Laravel 对 PHP 版本要求较新:
| Laravel | 最低 PHP |
|---|---|
| 10 | 8.1 |
| 11 | 8.2 |
| 12 | 8.2+ |
检查:
php -v
Debian 默认仓库 PHP 可能很旧(如 7.4)
解决:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-fpm
Laravel 需要:
mbstring, xml, curl, json, tokenizer, bcmath, sqlite/mysql, gd, openssl
检查:
php -m
安装:
sudo apt install php8.2-mbstring php8.2-xml php8.2-curl php8.2-bcmath php8.2-gd
报错类似:
The stream or file "/var/www/laravel/storage/logs/laravel.log" could not be opened
解决:
sudo chown -R www-data:www-data /var/www/laravel
sudo chmod -R 755 /var/www/laravel/storage
sudo chmod -R 755 /var/www/laravel/bootstrap/cache
报错:
No application encryption key has been specified
解决:
cp .env.example .env
php artisan key:generate
Debian 可能装了旧 Composer:
composer -V
建议:
sudo apt remove composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
常见错误:
publicNginx 示例:
root /var/www/laravel/public;
index index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
请告诉我:
cat /etc/os-release)我可以直接帮你定位是哪一行配置或权限的问题 ✅