This is a Ubuntu system and I need the PHP to execute a program with a specific username, let's say, userA.
I used php exec() function to call sudo -Eu userA command_to_run_program, it did not work because of some security features or environment variables missing on Ubuntu.
So I'm thinking if this alternative way can be achieved:
From the back-end, there is a shell script with a fixed Pid running and waiting for signals. If this process receives a specific signal, it would execute the program. Let's say I manually started this shell script with userA. So I assume when it receives the signal and execute the program, the program is executed with userA.
And there is a apache server with PHP on this machine. The front-end user goes the PHP page and the php program sends the signal to the running shell script, awake the shell script and thus the program is executed by userA.
If it can be achieved, what is the best practice to do so?
Thanks for your help!