How can I execute local programs as root from PHP? I want to use UNIX commands adduser and passwd.
Nov 28th, 2008 07:12
healthy man, dman, K Muma, Jon Bjorseth, Matt Rudderham,
executed commands from PHP is ran as the web-server (like httpd e.g.)
You'd prolly have to make your web-server run as root to be able to run
commands as root
Or you could setup a cron job running as root to check a file every so
often and do the updates from there.
You can also make an executable with the user set to root and the s-bit
set (which will allow the program to run with root permissions).
Here is a simple C program to do that.
#define RUN_CMD "cmd" //the command to be run
Replace cmd with the command to run, then compile and change the
chown root a.out
chmod 4755 a.out
Of course if you want to do more then just run the same command all the
time the c program will need to be modified.