laradock 安装swoole

it2025-08-15  15

1.我们需要在 laradock 的.env文件下面修改 WORKSPACE_INSTALL_SWOOLE=true 还有 PHP_FPM_INSTALL_SWOOLE=true 2.在 laradock/workspace/Dockerfile 最后添加一行:EXPOSE 1215 3.重新 build workspace 容器:

重新构建并重启 Laradock 相关服务 docker-compose build workspace nginx docker-compose down docker-compose up -d nginx mysql redis memcached 在 laradock 目录下通过 winpty docker exec -it laradock_workspace_1 bash 进入 workspace 容器进入项目根目录:可以在window下直接进入laradock_workspace_1,执行 php -m | grep swoole出现swoole的字样代表成功。修改nginx配置 upstream swoole-http { server workspace:1215; } map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; listen [::]:80; # For https # listen 443 ssl; # listen [::]:443 ssl ipv6only=on; # ssl_certificate /etc/nginx/ssl/default.crt; # ssl_certificate_key /etc/nginx/ssl/default.key; server_name study.test; root /var/www/laravel-learn/public; index index.php index.html index.htm; location = /index.php { # Ensure that there is no such file named "not_exists" # in your "public" directory. try_files /not_exists @swoole; } location / { try_files $uri $uri/ @swoole; } location @swoole { set $suffix ""; if ($uri = /index.php) { set $suffix "/"; } proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header SERVER_PORT $server_port; proxy_set_header REMOTE_ADDR $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; # IF https # proxy_set_header HTTPS "on"; charset utf-8; proxy_pass http://swoole-http$suffix; } }

6.修改 laravel项目 env

SWOOLE_HTTP_HOST=workspace SWOOLE_HTTP_DAEMONIZE=true SWOOLE_HOT_RELOAD_ENABLE=true 在 workspace 容器中启动php artisan swoole:http start | stop | restart | resload由于 swoole 会缓存整个laravel项目,所以在开发环境下,我们需要开启开发环境热更新 更改项目中 config swoole_http.php 中 max_request = 1
最新回复(0)