在Debian上運行Laravel需要安裝以下依賴:
sudo apt update
sudo apt upgrade
sudo apt install nginx
sudo apt install php php-cli php-common php-json php-gmp php-fpm php-xmlrpc php-bcmath php-imagick php-curl php-zip php-gd php-mysql php-xml php-mbstring php-xmlrpc php-intl php-sqlite3
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo apt install mariadb-server
/etc/nginx/sites-available/example-app,并添加以下內容:server {
listen 80;
listen [::]:80;
server_name example-app.local;
root /path/to/your/laravel/project/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/example-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
確保Laravel項目的 storage 和 bootstrap/cache 目錄具有適當的讀寫權限:
sudo chown -R www-data:www-data /path/to/your/laravel/project/storage
sudo chown -R www-data:www-data /path/to/your/laravel/project/bootstrap/cache
sudo chmod -R 775 /path/to/your/laravel/project/storage
sudo chmod -R 775 /path/to/your/laravel/project/bootstrap/cache
完成以上步驟后,您應該能夠在Debian上成功運行Laravel。