[英]Laravel server on Ubuntu boot
我目前正在处理一个 php 项目,实际上我使用php artisan serve --host={myIp}
来安装服务器,我希望它在装有 ubuntu 18.04 的电脑上启动时自动运行,我已将其配置为信息亭。
到目前为止,我知道我必须编写一个脚本并将其放在 init.d 文件夹中
#!/usr/bin/env bash
cd "~Documentos/Folder"
php artisan serve --host=192.168.100.12 &
然而,我完全迷失在如何编写脚本来运行 Laravel 服务器,希望你们能帮助我或指导我如何解决这个问题。
您可以在/etc/systemd/system目录中创建服务文件yourlaravelapp.service时将 is 注册为服务。 您的服务文件的内容将是:
[Unit]
Description= Your Php Laravel service description
[Service]
WorkingDirectory=/var/www/YOUR_PROJECT_FOLDER
ExecStart=/usr/bin/php /var/www/YOUR_PROJECT_FOLDER/artisan serve
Restart=always
# Restart service after 10 seconds if the php laravel service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=php-example
User=www-data
Environment=YourEnvironmentVariable=YourEnvironmentValue
[Install]
WantedBy=multi-user.target*
保存这些更改后,您需要使用以下命令重新加载系统守护程序
systemctl daemon-reload
然后,您可以启用该服务,以便将其添加到启动时启动
sudo systemctl enable yourlaravelapp.service
您可以使用以下命令启动服务
sudo systemctl start yourlaravelapp.service
您可以使用以下命令检查服务的状态
sudo systemctl status yourlaravelapp.service
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.