Categories
Unix Websites

Running root commands in PHP via Apache

I have a web application that needs to perform shells commands as root within a PHP function, and you would think that would be pretty straight forward… but it did take my a few googles to get all the details, so here are my handy notes on it. This is on a Linux system running Apache, and we’ll be using “sudo” within “shell_exec” to run the commands.

The main thing is to edit the /etc/sudoers file, and typically you can (as root) use the ”visudo” command to do so.

Make sure apache can run commands, AND not require a password:

apache  ALL=(ALL)       NOPASSWD: ALL

Then you need to comment out this line:

#Defaults    requiretty

If you don’t, then you will see these errors in /var/log/secure: “sorry, you must have a tty to run sudo”. Now you are ready to go, and the PHP code is simple:

$results = shell_exec(‘sudo date’);

Categories
Photos

Borders without Books

It is sad to see all these bookstores closing these days, and even the large bookstores are suffering. Perhaps some karma at play, seeing how they forced the little bookstores to close in the past!

But nonetheless, I am sad to see this particular Borders shut down, since they had an AWESOME selection of tech books! And I was just there a few days ago to see ALL the bookshelves empty of knowledge.

They were selling everything in the store, even those big-ass bookshelves. I thought briefly of putting in a 12 foot high bookshelf in my home office but decided against it.