Systemctl is not working in shell from PHP

Viewed 122

i'm creating a service for a socket server in PHP on my server with CentOS 7.

I've a problem starting and retrieving the status of the service with systemctl command.

Basically if i run:

system('systemctl status myservice');

i get a blank string.

I tried with "start" command and it doesn't start anything. I also tried with standard services like httpd.

If i start these commands from SSH Shell everything works.

I don't think it is a problem of disabled shell in php, because if i run

system("pwd");

i get the right output. So shell is active.

What can i do?

1 Answers

I have just tested this command with my created systemctl service for PHP command and it work just fine. Please can you check your myservice.service and check out the user and group permissions. the web server should be run from the same user that have permissions in myservice.service

[Unit]
Description=PHP orders_change


[Service]
User=www-root
Group=www-root

Type=simple
TimeoutSec=0
PIDFile=/var/run/orders_change.pid
ExecStart=/bin/sh -c '/usr/bin/php -f /home/alex/projects/statistics/artisan orders_change  2>&1 > /home/alex/projects/statistics/orders_change.log'
KillMode=mixed

Restart=on-failure
RestartSec=30s

[Install]
WantedBy=default.target
Related