I'm trying to run a script with root access from PHP. I can't do that because Apache's user,
www-data, don't have root access because of security reasons. To fix that, I was advised to use a named pipe. I first tried to add sudo permission to
www-data, but was told that was definitely not good due to security risks (plus, I tried to add it but it didn't work).
This is where my problem is. If I understand this correctly, I will need a script that automatically starts on system boot, and constantly waits in the background trying to read from a named pipe. The script, a.k.a. pipe reader, has to be run as root so it gets root access. Then, from PHP, I just send some data through the pipe to the pipe reader, which then is passed on to the main script I'm trying to execute from PHP.
This way, since the reader is run as root, the main script will be run with root access. What I refer to as "main script" is a bash script that creates a user, and it needs root to work. It's the script I'm trying to run from PHP with root access.
Is this the best approach to my issue? Have I understood it correctly?
Update: I'm running Ubuntu 12.04.1.