
在生产环境中有效管理Laravel Reverb WebSocket服务器至关重要。本文将指导您如何利用systemd在后台配置和运行Reverb,确保服务器随系统启动并自动重启。
步骤一:创建systemd服务文件
首先,创建一个配置文件来指导systemd管理Reverb。使用以下命令创建并编辑服务文件:
<code class="bash">sudo nano /etc/systemd/system/reverb.service</code>
然后,将以下配置添加到文件中:
<code class="ini">[Unit] Description=Laravel Reverb WebSocket Server After=network.target [Service] ExecStart=/usr/bin/php /var/www/example.test/artisan reverb:start --port=6001 --host=0.0.0.0 Restart=always User=www-data Group=www-data WorkingDirectory=/var/www/example.test [Install] WantedBy=multi-user.target</code>
参数说明:
[Unit] 部分:Description:服务的描述信息。After=network.target:确保服务在网络启动后才启动。[Service] 部分:ExecStart:启动Reverb服务器的命令。请将/var/www/example.test替换为您的Laravel项目路径。Restart=always:服务失败时自动重启。User/Group:以www-data用户和组运行服务(Web服务器的常用用户组)。WorkingDirectory:设置命令的工作目录,确保Laravel环境正确加载。[Install] 部分:WantedBy=multi-user.target:确保服务在多用户模式下启动。步骤二:重新加载systemd并启用服务
创建服务文件后,重新加载systemd以读取更改:
<code class="bash">sudo systemctl daemon-reload</code>
然后启用服务,使其在系统启动时自动启动:
<code class="bash">sudo systemctl enable reverb.service</code>
步骤三:启动服务
首次手动启动服务:
<code class="bash">sudo systemctl start reverb.service</code>
这将在后台启动Reverb WebSocket服务器。
步骤四:检查服务状态
验证服务是否正常运行:
<code class="bash">sudo systemctl status reverb.service</code>
此命令将显示服务的详细状态信息,包括运行状态和错误信息。
附加命令:
sudo systemctl stop reverb.service
sudo systemctl restart reverb.service (用于应用更改后重启服务)更多关于systemd服务配置的信息,请参考相关文档。
以上就是使用SystemD在后台运行Laravel Reverb的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号