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
Websites

Changing to PHP5 in Yahoo Web Hosting

I was updating some code on a Yahoo hosted site, and it wasn’t working because Yahoo will default you to PHP4 on their hosting. My code of course requires PHP5.

I spent a fair amount of time searching around for an answer and finally found it at http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-38.html

I was surprised at how difficult it was to find this switch option! After I made this post, Yahoo support replied to give me the proper link and some more information, which I must compliment Yahoo support for doing.

Categories
Coding Websites

http AJAX fails in Internet Explorer

I ran across an interesting bug recently where I had an AJAX routine failing when I viewed the page in IE8. When you clicked the little warning icon in the lower left, it gave a message of “Object doesn’t support this property or method”!

It was failing around code that looks like:

function parseCalcResponse() {
if (http.readyState == 4 && http.status == 200) {
results = http.responseText;
results = results.split(“|||”);
document.getElementById(‘test’).innerHTML = results;
}
}

It turns out, the fix was to declare “results” at the top of the function code with:

var results=”;

And that fixed it!

Categories
Websites

Ontok’s domain has expired!

I’ve been using ontok’s API for geocoding for a few years now, and all of a sudden my routines were getting errors! It turns out their domain expired!

I’m not sure why they let that happen, I’m hoping they just didn’t pay attention and it will be back up soon. Maybe I should just call Sourabh! 🙂

Domain Name: ONTOK.COM
Created on: 20-May-05
Expires on: 20-May-09
Last Updated on: 20-May-08

Administrative Contact:
niyogi, sourabh  niyogi@mit.edu
humdaq, inc.
55 Grove St
Somerville, Massachusetts 02144
United States
6177641078      Fax —