gpt4 book ai didi

php - 在 centos7 中将 php 脚本作为 systemd 服务运行

转载 作者:可可西里 更新时间:2023-11-01 00:42:23 28 4
gpt4 key购买 nike

我正在尝试在 centos7 启动时运行 phpscript。目前systemd进程如下所示

[Unit]
Description=custom Service
After=network.target

[Service]
Type=forking
User=root
ExecStart=/usr/bin/php /var/www/htdocs/mysite/public/index.php abc xyz >> /var/log/custom.log 2>&1


[Install]
WantedBy=multi-user.target

但是上面的脚本没有传递参数。我该如何解决这个问题?谢谢!

最佳答案

作为替代方案,我创建了一个 myphp.sh bash 脚本

#!/bin/bash
nohup /usr/bin/php /var/www/htdocs/mysite/public/index.php abc xyz & >> /var/log/custom.log 2>&1

然后在 systemd 脚本中

[Unit]
Description=custom Service
After=network.target

[Service]
Type=forking
User=root
ExecStart=/etc/init.d/myphp.sh

[Install]
WantedBy=multi-user.target

关于php - 在 centos7 中将 php 脚本作为 systemd 服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520265/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com