1.保证服务器安装了LNMP环境且php版本>=7.1
2.安装swoole扩展,并删除掉与swoole冲突的扩展
3.安装laravel
composer create-project --prefer-dist laravel/laravel blog "6.*"
4.先通过 Composer 安装 LaravelS 扩展包:
composer require hhxsv5/laravel-s
5.运行如下 Artisan 命令相应脚本和配置文件发布到根目录下:
php artisan laravels publish
6.启动laravels
php bin/laravels start
这样,Swoole 服务就被启动起来,监听本地的 5200 端口,如果有请求发送到这个端口,它就可以进行处理。
7.通过 Supervisor 管理 LaravelS
如果是在生产环境使用,推荐使用 Supervisor 对 LaravelS 服务进行管理,从而提供服务的稳定性,相应的配置示例如下:
[program:laravels]
command=/usr/local/php/bin/php /home/www/laravel_swoole/bin/laravels start -i
numprocs=1
autostart=true
autorestart=true
startretries=3
user=root
redirect_stderr=true
stdout_logfile=/home/www/laravel_swoole/storage/logs/supervisord-stdout.log
Nginx配置 在vhost文件夹下的配置文件里
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream laravels {
# Connect IP:Port
server 127.0.0.1:5200 weight=5 max_fails=3 fail_timeout=30s;
keepalive 16;
}
server {
server_name xxx.com;
listen 80 ;
root /home/www/laravel_swoole/public;
index index.html index.htm index.php;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
location / {
try_files $uri @laravels;
}
location =/ws {
# proxy_connect_timeout 60s;
# proxy_send_timeout 60s;
# proxy_read_timeout:如果60秒内被代理的服务器没有响应数据给Nginx,那么Nginx会关闭当前连接;同时,Swoole的心跳设置也会影响连接的关闭
# proxy_read_timeout 60s;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header Server-Protocol $server_protocol;
proxy_set_header Server-Name $server_name;
proxy_set_header Server-Addr $server_addr;
proxy_set_header Server-Port $server_port;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://laravels;
}
location @laravels {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header Server-Protocol $server_protocol;
proxy_set_header Server-Name $server_name;
proxy_set_header Server-Addr $server_addr;
proxy_set_header Server-Port $server_port;
proxy_pass http://laravels;
}
}
https://xueyuanjun.com/post/9801
https://www.bookstack.cn/read/LaravelS/spilt.6.d7f5aa7b24640641.md
https://wiki.swoole.com/#/getting_started/extension