在 Debian 下运行 Laravel 项目时,报错的原因通常可以归结为环境配置、权限、依赖或 PHP 版本几类问题。下面按常见场景给你一个系统梳理,方便你对照排查。
Laravel 对 PHP 版本有明确要求(如 Laravel 10 需要 PHP ≥ 8.1)。
报错示例
Your requirements could not be resolved to an installable set of packages.
解决
php -v
如版本不够:
sudo apt install php8.1 php8.1-cli php8.1-fpm
Laravel 常用扩展:
mbstringxmlcurljsonbcmathzipgdsqlite / mysql / pgsql报错示例
Class 'DOMDocument' not found
解决
sudo apt install php-mbstring php-xml php-curl php-bcmath php-zip
报错示例
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
sudo chmod -R 775 storage bootstrap/cache
composer install
composer self-update
PHP Fatal error: Allowed memory size exhausted
php -d memory_limit=-1 composer install
正确 root
root /var/www/laravel/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
systemctl status php8.1-fpm
cp .env.example .env
php artisan key:generate
php artisan config:clear
php artisan cache:clear
php artisan migrate
Debian 默认无 SELinux,但若有安全策略限制写权限也会导致报错。
tail -f storage/logs/laravel.log
APP_DEBUG=true
php artisan --version
如果你能贴出具体报错信息或截图,我可以直接帮你定位是哪一种原因。