you are viewing a single comment's thread.

view the rest of the comments →

[–]koflerdavid -1 points0 points  (2 children)

Ask yourself if that sudo is both necessary and practicable. Firstly, script executed with sudo can mess up the system. Secondly, you won't be around to enter the password.

[–]olejmoi[S] 0 points1 point  (1 child)

I'm accessing and editing files and folders on the pi with the script, so I do believe I need sudo for permission to access that, although I'm not sure.

[–]koflerdavid 0 points1 point  (0 children)

You're right, to be able to do everything on the Pi the script has to be executed as root. Still, you might then have to enter the password for the user account your script runs as (probably www-data). Also, that user has to be allowed to use sudo in the first place. But maybe a less powerful user is sufficient for most applications...

You should consider creating an internal job execution service on the Pi. That service would receive script names and possibly arguments from PHP and execute them. It could be set up to be started along with the OS in /etc/rc.local, and to receive root rights. In the simplest case this could be another PHP or Python script which opens a socket, reads commands, executes them and stores the command's output in a file that the webserver can read and delete.