Setting up MySQL 5 and PHP 5 under Mac OS X (Tiger)

While setting up MySQL 5 and PHP 5 today, I documented the steps I took to get it all running under Tiger. Here’s the basic rundown if you’d like to move to these new versions as well.

Downloads

Install Xcode

Installation of Apple’s Xcode Developer Tools is straightforward — just install the .pkg file inside the .dmg if you downloaded it, or run the .pkg from the discs that came with your computer.

Install MySQL 5

Setting up MySQL is just as easy as installing Xcode, as the developers have kindly put together a .pkg installer. You could always compile it yourself if you have the need. Also included in the .dmg are a StartupItem and Preference Pane, both of which I find handy (although StartupItems are a bit out-of-date, and should probably be replaced with a launchd item).

Install PHP 5

Unpack PHP’s .tar.gz file with your favorite decompression utility, and open a Terminal window. Type cd, followed by a space, then drop the uncompressed php-5.2.1 folder right into the Terminal window and hit Return to change directory to the PHP files.

Type ./configure --with-mysql=/usr/local/mysql --with-apxs=/usr/sbin/apxs to configure the PHP installation, noting the location where MySQL keeps its files (so PHP knows how to get to it in the future).

While PHP is configuring, in a new Terminal window, you should set the root password for MySQL.
Enter cd /usr/local/mysql/bin,
then ./mysqladmin -u root password 'new-password', where new-password is your chosen MySQL root password. Note that this has nothing to do with your computer’s “root” password, and is entirely separate.

Back at the PHP prompt, you’ll see “Thank you for using PHP.” when it’s done configuring. You can then enter make to compile PHP from the source code. This may take a while. When done, enter sudo make install to install the files to their predetermined locations.

Reconfigure Apache

You’re almost done, except that the Apache web server doesn’t know to handle .php files for PHP 5. PHP 4 comes preinstalled with Mac OS X, but PHP 5 changes your Apache config file to enable itself (to include its shared objects when Apache boots), which turns off PHP 4. In this state, .php files will be printed out to the web browser as text files instead of executed — that’s not good! You’ll have to tweak the config file and reboot Apache to make it all go again. If you have the TextMate command-line utility mate installed, these next steps are quite easy.

Enter sudo mate /etc/httpd/httpd.conf (or sudo pico /etc/httpd/httpd.conf without TextMate) in the Terminal to edit the Apache config file. Find <ifmodule mod_php4.c> and change that 4 to a 5, as we’re now using mod_php5.c.

You’ll also want Apache to recognize index.php as a Directory Index file, so hunt down DirectoryIndex index.html and add a space, then index.php to the list, so it looks like DirectoryIndex index.html index.php when done.

At this point you can save and exit if you prefer, but I like to make one last change so I don’t have to dig to /Library/WebServer/Documents every time I want to edit a file I’m working on. In the root of your hard drive, create a folder called WebServer, and then jump back to TextMate (or the Terminal window) where you’re editing the Apache config file. Find the line DocumentRoot "/Library/WebServer/Documents" and change it to DocumentRoot "/WebServer". After making this change, also change the location a few lines down: <directory "/Library/WebServer/Documents"> to <directory "/WebServer">. Finally, save and exit.

Back at the Terminal prompt, enter sudo apachectl graceful to reboot Apache and let everything fly. I hope that helps some people setting up a PHP coding environment out there! A final note: watch out for the “smart quotes” WordPress likes to insert — they may cause copy-and-pastes to produce failures in the Apache config file.

Setting up MySQL 5 and PHP 5 under Mac OS X (Tiger)

Variable Power Supplies

For the more serious hardware hacker, no tool is more essential than a variable power supply. Able to supply voltages and currents adjustable to the tenths of a unit, the supply will run just about any reasonably-powered electronic device including circuits, iPods, laptops, and more. In only the last few weeks I’ve used my own to test a portable DVD player which had no wall adapter, power an iPod attached to a breakout board, and temporarily resurrect a dying PowerBook. I bring all this all up because I happened to see an influx of these great tools available on eBay using one of my saved searches, and thought others may benefit from them. To find them, search eBay for (HY30*,HY50*) supply or click here.

Variable Power Supplies

Sub-Pixel Font Rendering: What is It?

For the past few years I’d heard the term “sub-pixel rendering” in various font and graphics related writings, and wasn’t really sure what the fuss was about. I finally read up on the technology and was surprised to find what a difference it makes in display clarity. The crux of sub-pixel rendering is using the three red, green, and blue elements that make up a single pixel to effectively triple the horizontal resolution of an LCD display. More resolution in the same physical space lets you show more data, and thus render more clearly. Wikipedia’s definition left much to be desired, however Steve Gibson has an outstanding page — and freeware utility — clearly explaining the subject. What doesn’t that guy know?

Know how sub-pixel rendering works, it’s easy to see how it could also be applied to graphics and gaming. Where an edge is computed, the resulting line could be shown more accurately (as far as the human eye is concerned) by rendering with respect to the sub-pixel elements of the display. Of course, the technology doesn’t work nearly as well on CRT displays, but for LCDs, it appears to provide ultra-crisp images and text. I wonder if Apple plans to make use of this awesome technology in the next revision of Mac OS X, or perhaps on the iPod and iPhone displays…

Sub-Pixel Font Rendering: What is It?

Iconverter

Iconverter is a simple little utility I discovered which helps you juggle between images, ICNS files, and actual “pasted” icons for Mac files and applications. Often when dealing with icons, I find the need to convert an ICNS file to an editable PNG image with transparency, or go from a PNG back to an ICNS. As much as I like IconBuilder, my needs are not nearly that complex, and Iconverter simply gets the job done. What I enjoy most about the little app is the “Use file contents” checkbox, which will force it to read the data from the file instead of the icon itself — most other icon utilities default to using the system-designated icon of an opened ICNS file (a file with dog-eared corner), not the actual file contents. Iconverter handles this with ease, and is my first choice for getting icons just right.

Iconverter