2 years ago
#2110
EuSouVoce
systemctl start service with shell_exec() [Provisory fix]
I've been trying for the past six hours to start and stop a service via systemctl inside a PHP webpage...
I've already:
checked the php.ini on the php8.0-fpm
already added the www-data (shell_exec('whoami');) PHP user to /etc/sudoers
Checked the AppArmor and SELinux for conflicts with PHP. (it can create dirs, use fopen() etc)
The thing is, it can use systemctl is-active service@name
, but cannot start or stop a process.
<?php
$name = $_GET['n'];
$cmd = "start";**
$service = "service@$name";
shell_exec("sudo systemctl $cmd $service");
trying to sudo does not work either.
I'm using nginx with php8.0-fpm
Edit:
got it working using chmod u+s /usr/bin/sudo
but I think that it's not safe enough...
php
systemd
shell-exec
systemctl
0 Answers
Your Answer