在Debian环境下部署多个Laravel实例,你需要遵循以下步骤:
首先,确保你已经安装了Nginx和PHP-FPM。如果没有,请运行以下命令来安装它们:
sudo apt update
sudo apt install nginx php-fpm
为每个Laravel实例创建一个单独的Nginx配置文件。在/etc/nginx/sites-available目录下创建新的配置文件,例如laravel1.conf和laravel2.conf。以下是一个示例配置:
server {
listen 80;
server_name example1.com; # 更改为你的域名或IP地址
root /var/www/laravel1; # 更改为你的Laravel项目目录
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的PHP版本更改
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
对于第二个Laravel实例,只需将server_name、root和fastcgi_pass等参数更改为相应的值。
为每个Nginx配置文件创建一个符号链接到sites-enabled目录:
sudo ln -s /etc/nginx/sites-available/laravel1.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/laravel2.conf /etc/nginx/sites-enabled/
运行以下命令检查Nginx配置文件是否有语法错误:
sudo nginx -t
如果没有错误,请重启Nginx以应用更改:
sudo systemctl restart nginx
确保Laravel项目的storage和bootstrap/cache目录具有适当的读写权限:
sudo chown -R www-data:www-data /var/www/laravel1/storage
sudo chown -R www-data:www-data /var/www/laravel1/bootstrap/cache
sudo chown -R www-data:www-data /var/www/laravel2/storage
sudo chown -R www-data:www-data /var/www/laravel2/bootstrap/cache
编辑/etc/php/7.4/fpm/pool.d/www.conf文件(根据你的PHP版本更改),将listen参数更改为/run/php/php7.4-fpm.sock(或相应的PHP版本)。
然后重启PHP-FPM服务:
sudo systemctl restart php7.4-fpm
现在,你应该可以在浏览器中访问你的两个Laravel实例了。只需将域名解析到服务器IP地址,或者在本地hosts文件中添加相应的条目。