I am currently working on a Symfony 6 project. Now I have the situation that I want to stop and start a systemd service which is used to consume the messages from the Symfony Messenger message queue. The service is called "messenger-worker@.service" and is located under /etc/systemd/system
Now in my PHP script I run the following:
$output = shell_exec("sudo -u www-data /usr/bin/systemctl stop messenger-worker@1.service 2>&1");
dd($output)
The $output contains the following error message:
Failed to stop messenger-worker@1.service: Interactive authentication required. See system logs and 'systemctl status messenger-worker@1.service' for details.
Under /etc/sudoers.d I already created a file called "www-data". With the following code:
%www-data ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop messenger-worker@1.service
Does anyone have an idea what I am doing wrong here?