icanhazstring/systemctl-php

Run command with sudo

wadealer opened this issue · 4 comments

If you need sudo, you should execute the bin executable with sudo. The incode support was dropped due to security reason.

How can I do this? If I do this:
$cmd = "php_systemctl"; \SystemCtl\SystemCtl::setBinary("sudo $cmd");
I get an error:
sh: sudo /home/.../php_systemctl: No such file or directory

It seems that the php_systemctl binary is not found.

Do you check the specific binary path is correct?

Maybe you should use root user to execute the current PHP program rather than using the sudo prefix during setBinary method call.

The reason is: It seems that the setBinay method only allow a binary path without other prefix command.

Hi @wadealer

To be fair, the documentation is fairly unclear at this point.
What it should say: If you need sudo, you should execute your script with sudo.

What that means.

Having your php script:

## stopService.php
$systemCtl = new SystemCtl();
$systemCtl->getService(...)->stop();

Then on your CLI you need to execute this script using sudo

$ sudo php stopService.php

Ok, I see