Nicholas C. Johnson

MySQL 5.1, PHP 5.3, and Mac OS X 10.6

After upgrading to Snow Leopard (Mac OS X 10.6) I found that my local MySQL installation no longer worked. Also, my local Apache server using PHP 5.2 no longer interpreted .html files as PHP as I’d set up before. I did some digging and came up with the following things to get it working again. Hope this helps.

MySQL

There isn’t a MySQL installer package for Snow Leopard yet so you’ll have to build it from source. (I know, really scary sounding, huh. I hadn’t compiled anything before this and was intimidated. But it’s easy. Promise.) Follow this extremely easy-to-follow tutorial by Dan Benjamin and then come right back here for the rest.

Apache & PHP

Welcome back. By now you should be able to connect to your shiny new MySQL instance. Now, if you load any PHP pages that use any of the date functions you’ll see this error (or something similar):

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

PHP 5.3 now requires the timezone to be specified instead of trying to guess at it.

  1. Open Terminal (/Applications/Utilities/Terminal).
  2. Copy the built-in php.ini.default file to php.ini by typing sudo cp php.ini.default php.ini and pressing Return. Supply your password.
  3. Edit php.ini by typing sudo open php.ini. It should open in your default text editor.
  4. Search the file for the phrase “timezone”. You’ll find a line that reads ;date.timezone =. Change it to date.timezone = America/Denver (or whatever timezone you choose from this list). Remember to delete the semicolon from the beginning of the line.
  5. Because of some code I share with colleagues, I ended up needing to restore the short_open_tag attribute by finding that phrase and setting the value to On.
  6. Also, MySQL couldn’t connect to anything until I commented out the mysql.default_socket property by placing a semicolon at the beginning of the line. This lets it use the built-in value instead.
  7. After making these changes to your php.ini file you need to restart Apache to get it to read the new values in. In Terminal type sudo apachectl graceful and test your local php code in your browser.

Happy coding!

Categories

Various Profiles