Shutting down with php - granting apache permission

I am working on a Linux embedded system with a web interface (apache). Basically I need to add stop and reload functions to the web interface. However, when I run, I run into permission issues:

exec ("shutdown now"), etc. when called through a web page (e.g. apache).

How can I allow these commands to be called from apache?

Prefer not to grant full apache permissions, but system security is not a big problem in my case, so if this is the only way, how can I do this?

+2
source share
3 answers

Creating an Apache sudoer is a dangerous move, and I would avoid that. I think the QID is close to this ... the easiest solution is to create a cron job as root, which runs every X seconds and checks the file in the directory into which apache can write. Ask apache to add this file when you want to shut down, and the cron script should have a trigger that (a) deletes the file and (b) restarts the computer.

Just be careful that it deletes the file correctly and gives you a rather long cron delay when you test, or the server will just restart continuously and it will be a mess.

+2
source

Without knowing how to do this, I can offer an ugly solution for hacking: write a tiny daemon that starts as root and takes commands to shut down the system, and ask your PHP script to communicate with the daemon via a reasonable channel (for your definition of a reasonable one, maybe , send a signal, maybe write to a file that the daemon sees, maybe just a network socket, whatever).

+1
source

Be sure you know what you are doing:

exec ("sudo ...

apache ALL = (ALL) NOPASSWD: ALL

0
source

All Articles