Run PHP script as systemd service on centos7

I am trying to run phpscript on centos7 startup. Currently systemd process looks like below

[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

      

But no arguments are passed to the above script. How can I fix the problem? Thank!

+3


source to share


2 answers


Alternatively, I created a myphp.sh

bash script

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

      



and then in a systemd script

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

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

[Install]
WantedBy=multi-user.target

      

+3


source


Try this config

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

      



UPDATE

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

      

0


source







All Articles