inicio mail me! sindicaci;ón

Archive for September, 2008

Mac. Apache. PHP. MySQL. Woe.

I warn you know, there will never be a nerdier post than this one. If you aren’t a nerd, do yourself a favor and stop reading. Seriously. Still reading? Then I’m willing to bet you didn’t see a girl naked until well after high school. If that’s not the case, you should really stop reading. Seriously. Seriously.

Anyhow, I decided to do some development at work using a Mac. The Internet has taught me that this is the most awesome way you can possibly develop, and if you don’t develop on a Mac, you’re not a real developer.

At first it was a walk in the park, I found applications to replace their pc equivalents. One minor annoyance was that no two applications install in the same way on a mac, but it was all fairly straight forward. For my Apache, MySQL, PHP install, I went with MAMP. It was easy enough at first, but then it took me like 10 minutes to get http://localhost/ to load up. Turns out that MAMP’s default port is 8888, so I actually had to visit http://localhost:8888/. Then when that finally rendered, my HTML output didn’t work. Quick lesson: the default text editor on a Mac does not make an ideal HTML editor as it chooses to create all docs in RTF format despite the file extension. because typing http://localhost:8888 is annoying to me, I decided to run MAMP on port 80. Now, every time I start or stop MAMP I have to enter my root password. This is slightly more annoying that having to add the four eights, so it seems I lose or I lose on that one.

Once I sorted that out, I stumbled across my first hurdle: at work we use an SSH tunnel to forward port 3306 to a shared development database. As my Mac is built on Unix, and SSH is a built in command, I didn’t really forsee this being much of a problem. Setting up the tunnel was easy enough, I even found a nifty tutorial that was nice enough to teach me how to create a script which would reestablish the tunnel on login. Sadly, the tutorial only half worked, so I ended up Googling for about an hour trying to figure out how to run shell commands on log in. (The answer ended up being creating an app using AppleScript and “do shell command” if you found you’re way here trying to accomplish the same thing.)

The SSH tunnel worked just fine and dandy, and it forwarded port 3306 like a dream. Unless of course I tried to establish a database connection in PHP, then, no matter which port I specified, I was always connected to the MAMP install of MySQL.

While I’ll spare you the really boring details, I first feared that MAMP was the problem, so I set about configuring the default Mac install of Apache and PHP. That was a pain in the ass, and I couldn’t get MySQL to work. So I Googled around and was pointed to the Entropy PHP Apache Module. According to The Internet, this is the greatest thing since sliced bread, so I set about to make it happen. Unfortunately, I happen to have OS X 10.5, which completely gags when you install the Entropy PHP Apache Module. Thanks for the heads up Marc Liyanage creator of the Entropy PHP Apache Module. I suppose adding “this completely gags if you try to install it with OS X 10.5″ would be asking a lot in your rather intense install instructions.

Several hours later, I was once again able to get Apache working (but with no PHP or MySQL). So I set about getting the Mac install of PHP working with my own install of MySQL.

Several hours later, I had just that, but, when I tried to connect to the db via port 3306 (where you’ll recall I had established a SSH tunnel to another computer) it ignored my tunnel and connected directly to my local install of MySQL.

While I could use words to describe my feelings after spending hours, and hours, getting my webserver running only to find that the same “bug” I found in MAMP still existed, I will spare you the obscenity. Luckily at this point a coworker who was helping me through this mess somehow discovered that if you connected to ‘localhost’ on a Mac it ignores the port forwarding (or something like that). The answer was to connect via an IP address (127.0.0.1) instead. After a little over a day of shell hacking, nearly destroying my brand new OS X install, and an ungodly amount of frustration, that answer was exactly that simple. I still have no idea why it works, but it does.

On PC there is a program called WAMP. It is wonderful and perfect. Setting up a webserver takes around five minutes. So far we’re at PC: 1, Mac: 0.