在Debian上设置Laravel虚拟主机的步骤如下:
sudo apt update
sudo apt install nginx php-fpm php-mbstring php-xml php-zip unzip
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
注意:如果你使用的是PHP 8.0,请将php7.4-fpm替换为php8.0-fpm。
sudo nano /etc/nginx/sites-available/yourdomain.com
将yourdomain.com替换为你的域名。
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
将yourdomain.com替换为你的域名,并将/var/www/yourdomain.com/public替换为你的Laravel项目的实际路径。
保存并关闭文件。
创建一个符号链接,将新创建的配置文件链接到sites-enabled目录:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
如果一切正常,你应该会看到以下输出:
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl restart nginx
确保Laravel项目的storage和bootstrap/cache目录具有可写权限:
sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo chmod -R 755 /var/www/yourdomain.com
sudo chmod -R 777 /var/www/yourdomain.com/storage
sudo chmod -R 777 /var/www/yourdomain.com/bootstrap/cache
现在,你应该可以在Debian上通过Nginx访问你的Laravel项目了。请确保你的域名已解析到服务器的IP地址。