I have a php script that checks if a service is running or not. Here is the code to check the service.
function isClientActive() {
exec("systemctl is-active --quiet MyService", $output, $return);
return $return == 0;
}
This function works fine if I run script from CLI no matter if user has sudo rights or not. How ever When I call this script with apache user using web browser This function always retuns false. So I added 2>&1
at the end of the cmd and printed the output in browser and the output says "sh: systemctl: command not found".
So How I can allow apache user to call systemctl to get service status.
The question is not about executing a command as root. Its just a command that is not available for a specific user.