是的,Laravel 完全兼容 Debian 系统。
实际上,Debian 是运行 Laravel 应用非常流行和稳定的选择之一,尤其是在服务器环境中。
以下是确保 Laravel 在 Debian 上顺利运行的关键要素和步骤:
stable 版本)可能包含较旧的 PHP 版本。
以下是在 Debian (如 Debian 11 Bullseye 或 Debian 12 Bookworm) 上部署 Laravel 的典型流程:
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget git unzip
Debian 官方源的 PHP 版本可能过旧,推荐使用 Sury 仓库:
# 安装 GPG 密钥和软件源
sudo apt install -y lsb-release apt-transport-https ca-certificates
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
sudo apt update
# 安装 PHP 及常用扩展 (以 PHP 8.2 为例,请根据 Laravel 版本调整)
sudo apt install -y php8.2 php8.2-cli php8.2-fpm php8.2-common php8.2-curl php8.2-mbstring php8.2-mysql php8.2-pgsql php8.2-sqlite3 php8.2-xml php8.2-zip php8.2-bcmath php8.2-intl php8.2-gd
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
# 可以使用 NVM 或直接从 NodeSource 安装
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
sudo apt install -y nginx
# 然后配置 Nginx 站点配置,将 root 指向 Laravel 的 public 目录
sudo apt install -y apache2 libapache2-mod-php8.2
# 需要启用 mod_rewrite 并配置虚拟主机
cd /var/www # 或你的网站目录
composer create-project laravel/laravel example-app
composer install --optimize-autoloader --no-dev。sudo chown -R www-data:www-data /var/www/example-app/storage
sudo chown -R www-data:www-data /var/www/example-app/bootstrap/cache
chmod -R 775 /var/www/example-app/storage
chmod -R 775 /var/www/example-app/bootstrap/cache
www-data 用户运行。确保 Laravel 的 storage 和 bootstrap/cache 目录可被该用户写入。php artisan config:cache、php artisan route:cache 等优化命令,并关闭调试模式 (APP_DEBUG=false)。Debian 是一个极其稳定和可靠的操作系统,非常适合运行 Laravel。只要注意通过第三方源安装正确版本的 PHP,整个过程会非常顺畅。许多生产环境的 Laravel 应用都部署在 Debian 或其衍生版(如 Ubuntu)上。