Wednesday, July 1, 2009

MySQL on OS X via PHP

I don't know why, but I always have trouble when I'm setting up PHP and MySQL on OS X. Actually, I do know why, and it's for two reasons:
  1. I usually forget that you have to uncomment the line 'Load module php5..." in /etc/apache2/httpd.conf
  2. Whenever I try to connect to mysql in php using localhost from a website I'm sandboxing on my machine, I get an error.
The error will read something like "Could not connect to socket via /var/mysql/mysl.sock..." I poked around and, indeed, there is no such path on my machine. Instead my mysql.sock goes to /temp/mysql.sock. If instead I try to change the host from 'localhost' to '/tmp/mysql.sock' then I get the same message, but after the server does a lot of thinking. I suspect that it may be something related to the file permissions on my system, but the only thing that works for me is to symlink to /tmp/mysql.sock in /var/mysql/mysql.sock. Bingo, problem solved. I'd be curious to know if there is a better workaround...

Tuesday, June 30, 2009

Recovering From Apple Coma

I recently had the pleasure of reviving my macbook's broken hard drive from the dead. A quick word of advise for anyone with Apple products: get Applecare! You'll wish you did when things start breaking after the year-long factory warranty has expired (aint it always the way...). Warnings aside, I did some funny gymnastics to get up and running again:

My problem was a bum hard drive. I'm not sure what caused it, but at some point my system stopped responding and after a cold restart, I could not progress past the gray apple logo and nice wheel loading screen. I could hear my hard drive sputtering as if it were trying to get fired up and failing. I never received an error, I just hung at this screen indefinitely (8+ hours while I was sleeping didn't make any progress).

I had backups of most things, save for some music I was working on earlier in the day. Luckily my sister's iMac was close by, and my Macbook is old enough to have a firewire port. I happened to have a firewire cable, so I booted up in Target mode (hold 't' after the apple sound during startup), and was actually able to mount my drive on sis's computer. It took me a long time to navigate my folder structure, but everything was visible after enough time. I took this to mean that my hard drive was merely crippled, and not gone.

I got the few files I needed and ran to Fry's to get a new hard drive. Replacing the HD on my macbook was nice and easy -- it sits kiddy corner to the ram -- however, finding the screw driver to mount the new hard drive in the easily removable case that my old one was in was not. It turns out that you need a Torx T8 screwdriver if you ever want to get the drive out again. Luckily Ace Hardware had it, and all I had to do from there was reinstall with the system discs.

Of course, to make things interesting, my CD drive has been broken for almost two years now, so I had to go back into target mode and do it from sis's computer. Luckily it all worked out and I'm back in the blogosphere, the twitterverse, and every other electronic habitat.

Thursday, February 5, 2009

Binutils and objdump on Mac OS 10.4

For some reason OS X (10.4) does not contain objdump.  Seems like quite a useful tool to leave out.  Some searching revealed that objdump is part of binutils.  After much failure trying to install binutils 2.19 for OS X (10.4), I finally came across the supported version on the Apple website (binutils 2.16).  This version of binutils successfully compiled, but much to my chagrin, did not produce any binaries (weird).

To make a long story short, otools, does come with at least the developer tools for OS 10.4, and provides the same functionality as objdump.  Sample usage:

otools -tv a.out

The above will print out the disassembled assembly code of a.out.  You can do other nifty things like print out the shared libraries used.  I hope this saves someone some trouble.