Debian Buster 配置 Laravel 运行环境(nginx + redis + supervisor)

时间:2023-03-09 18:09:40
Debian Buster 配置 Laravel 运行环境(nginx + redis + supervisor)

1 目标

将开发完成的 Laravel 项目布署于 Debian 之上。由于项目要求使用 horizon 官方扩展,要求 PHP7.1+,故采用 Debian buster (下一版)

2 材料

  • IP 10.1.1.107
  • 假定项目名称为 fmtmis (基于 Laravel 5.5)
  • 假定项目目录为 /var/www/code/fmtmis/webroot
  • 假定域名为 fmtmis.testing
  • debian buster(10)
  • nginx
  • redis
  • supervisor

3 步骤

3.1 安装 debian 9 (略)

修改 APT 源,将其指向 buster 版(将 stretch 换成 buster)

$ sudo vim /etc/apt/sources.list

更新数据

$ sudo aptitude update

3.2 安装 nginx

$ sudo aptitude install nginx

配置 nginx

$ sudo vim /etc/nginx/sites-available/fmtmis

内容如下:

server {
         listen 80;

root /var/www/code/fmtmis/webroot/public;

index index.php;

server_name fmtmis.testing;

location / {
                 try_files $uri $uri/ /index.php?$query_string;
         }

location ~ \.php$ {
                 include snippets/fastcgi-php.conf;
                 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         }

location ~ /\.ht {
                 deny all;
         }

}

3.3 安装 php7.2-fpm

$ sudo aptitude install php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip

按  Laravel 手册要求,安装相应的扩展。

3.4 安装 redis

$ sudo aptitude install redis

3.5 安装 supervisor

$ sudo aptitude install supervisor

建立配置文件

$ sudo vim /etc/supervisor/conf.d/fmtmis.conf

内容如下:

[program:fmtmis-horizon]

process_name=%(program_name)s

command=php /var/www/code/fmtmis/webroot/artisan horizon

autostart=true

autorestart=true

user=root

redirect_stderr=true

stdout_logfile=/var/www/code/fmtmis/webroot/horizon.log

4 验证

$ sudo reboot

Horizon 仪表盘

http://fmtmis.local/horizon