Yeah, It WORKS, But…
I’m going to geek out for a moment here. Those of you who aren’t into Web programming might want to take this opportunity to go get some coffee or something.
Lately I’ve been working on a project that has required me to use various elements of the LAMP (Linux, Apache, MySQL, PHP/Perl) stack on Windows 2003 servers. Since these servers obviously do not come with LAMP stuff installed, part of the process has been learning how to install and configure PHP & MySQL to play nice with Windows.
Today I spent a good couple of hours banging my head against the desk trying to figure out what I was doing wrong. The app I was trying to set up, you see, requires ImageMagick — it uses IM to do various operations on stored images.
Now, at first I thought plugging in IM would be easy — the project provides Windows installer binaries, so it should be all double-clicky goodness, yes? As it turns out, the answer is NO: the double-clicky installer sets everything up properly, but even after everything was set up the PHP application that needs ImageMagick was still stubbornly insisting that I hadn’t installed it. Grrr.
I tried everything I could think of to get it working — checking permissions, moving IM out of the Program Files directory (so that its path wouldn’t have spaces in it), and so on. But nothing worked.
Finally, though, I came across a message board posting with The Answer. You see, since ImageMagick is a standalone program, my app was using PHP’s exec() function to call it. As it happens, if you’re on Windows, exec() doesn’t work unless you do something kind of counterintuitive — give Execute permission on the cmd.exe to the account IIS runs under (the “IUSR” or “Internet Guest” account).
Yes. For the exec() function to work, you have to allow the anonymous Web server user to have execute permissions on the command shell!
I tried this and it worked like a charm — suddenly my app and ImageMagick were getting along like best buddies. But there has to be a better way than this, doesn’t there? I mean, giving the anonymous IIS account execute permissions over the command shell seems — well — unwise.
Anybody out there with experience using PHP on Windows who can tell me if there’s a better way to make this work?