Panther Roars, Database Meows
Volume Number: 19 (2003)
Issue Number: 12
Column Tag: Programming
UNTANGLING THE WEB
Panther Roars, Database Meows
by Kevin Hemenway
Panther worth your time? Databases besides Filemaker? Pffffttt.
Panther worth your time? Databases besides Filemaker? Pffffttt.
"What's new in Panther?" you shout with mindless adulation, anxious saliva and drool waiting to soil the pages of your newest MacTech. Bad news, bub: absolutely nothing: nothing to write about, nothing to justify your upgrading, nothing worth your time, effort, or worrisome heart palpitations. I was hoping I could pound out a peck of pickled pages on pathetic Panther proselytizing, but no, Apple has spurned my deadly Shaolin technique.
I am, of course, talking specifically about web serving.
Mr. Piser, I Think You Should Come Up Here
Sure, a lot of other incredible drool-worthy stuff has happened in the latest OS: Expose, word completion in certain applications (via Option-Escape or F5), FileVault for the paranoids, gcc 3.3 and distributed building, a finished version of X11, Xcode, blah, blah, blah. But web serving? Nothing, nadda, zilch. Happily, this is not really a negative--it's hard to improve on something that was nearly perfect in the first place (of course, this all depends on your needs, desires, and expectations).
Which isn't to say there's nothing new with the Apache web server and its related technology... just nothing monumental, merely incremental, ornamental, and supplemental. I'd have loved to see Apache 2.0 and MySQL 4.0, but let's cover the relevant changes we got instead. Note that I'll only cover areas we've touched upon in the previous columns: explaining the differences between features we've yet to use isn't very productive. When the time comes, if there are crucial differences between Jaguar and Panther, I'll address them.
- Apache is now version 1.3.28; the latest available for Jaguar was 1.3.27. 1.3.28 is mostly a security and bugfix release so, although welcome, there's nothing to really get excited about. If you're interested in the specifics and technicalities, you can read the sordid details at http://www.apache.org/dist/httpd/CHANGES_1.3 (which also lists modifications for the just-released, as of this writing, 1.3.29).
- The output of httpd -V (which shows what Apache has been compiled with) includes a new entry: -D DYNAMIC_MODULE_LIMIT=64. This is a standard Apache compile-time setting, and controls how many modules can be dynamically loaded (fairly obvious, eh?). "64" is the standard Apache default; its explicit definition here is unnecessary (but there's no harm in doing so). More info at http://httpd.apache.org/dev/apidoc/apidoc_DYNAMIC_MODULE_LIMIT.html.
- Our included PHP is now version 4.3.2 (as grep PHP /var/log/httpd/error_log confirms). Even though 4.3.4 or higher will probably be available by the time you read this, a number of good security, performance, and language enhancements were made from 4.1.2 (the latest Jaguar version) onward. Most notably, PEAR (the "PHP Extension and Application Repository") is now part of PHP by default, although it seems to be broken in 10.3--see "Homework Malignments" below for analysis.
The PHP configuration has been improved in /etc/httpd.conf. Under Apache 1.3.27, we had the AddModule and LoadModule lines, as well as AddType's for .php and .phps (see last month's Untangling the Web). We've got the same thing in 1.3.28, but they've been slightly improved (Listing 1). First, the MIME types are more tightly defined--they'll only come into play when the PHP module is loaded (IfModule is a simple conditional... if mod_php was loaded, then do this). The second improvement is the addition of index.php to the DirectoryIndex, which allows that file to be served by default when someone requests a directory (http://disobey.com/example/).
- As you'd expect from a new PHP install, the <? phpinfo(); ?> we learned about last issue is different (Figure 1). Along with a heavier command line that explicitly enables a few features, the configuration file (php.ini) has moved from /usr/lib/ to /etc/, an arguably smarter location. If you've installed the recommended php.ini (http://cvs.php.net/co.php/php-src/php.ini-recommended), be sure to move it and restart Apache (sudo apachectl restart). Even with the upgrade, the default Apple-supplied PHP doesn't come close to the number of features and built-ins provided by Liyanage's version (http://www.entropy.ch/software/macosx/php/) or Server Logistics' Complete PHP (http://www.serverlogistics.com/php4.php).
- Perl, which we talked about during our two CGI articles, has been upgraded to 5.8.1-RC3; the final version of 5.8.1 has since been released. If you already know a thing or two about Perl, be forewarned that any modules you've compiled under Jaguar's 5.6.0 (like XML::Parser, HTML::Parser, Compress::Zlib, etc.) will need to be reinstalled, as the two different Perls are not binary compatible. Also note that cpan, similar to perl -MCPAN -esomething, is also available (find out more with man cpan).
Listing 1: Configuring PHP under Panther
The improved PHP configuration from httpd.conf
# If php is turned on, we respect .php and .phps files.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# Since most users will want index.php to work we
# also automatically enable index.php
DirectoryIndex index.html index.php
Figure 1: The output of PHP 4.3.2's phpinfo() under Panther.
Wait, Wait, Hold Up Dog... MySQL?
"Apache 2.0 and MySQL 4.0?" What's this MySQL (http://www.mysql.com/) thingy thing? Quite simply, it's your new Filemaker or 4D, only without the pretty pictures. Pronounced my-ess-que-ell, it's one of the most popular free and open sourced databases, installed and readily available to most web hosting accounts you'd normally pay monthly fees for. It's also installed by default in Apple's Mac OS X Server. Another, arguably stronger, database program is PostgreSQL (http://www.pgsql.com/) but, in a move sure to flirt with disaster, I'll rudely ignore it for most of my Untangling the Web columns. Enough emails convincing me otherwise will certainly sway my decision.
Since this column assumes you're not using OS X Server, our first step is to install MySQL. Incidentally, this is also the most complicated, not because it's difficult, but because there are so many different directions in which to approach it:
Which adventure should you embark on? As much as I like the thrills of a shiny new "official" release, the added treasure of ServerLogistics' unofficial binary can save you a couple of steps in your initial exploration. Regardless which path you choose to install MySQL, its continued configuration and administration is the same: you can use the command line to do everything, or nearly everything through GUIs (like CocoaMySQL, phpMyAdmin, etc.) or code (like PHP). We'll cover CocoaMySQL (http://cocoamysql.sourceforge.net/) and PHP database coding (http://www.php.net/mysql) in our next column and, if there's time, possibly phpMyAdmin (http://www.phpmyadmin.net/).
Installing Complete MySQL
Complete MySQL comes with a rather verbose installation document, but we'll cover the process quickly here. Go ahead and download the latest version (4.0.15 at the time of this writing; the latest official release is 4.0.16). Extract and mount, double-click the MySQL.pkg, agree to everything, and pause for a second when you get to the "Select a Destination" screen.
It continually surprises me how many people don't know about the File > Show Files command. Within any installer built using Apple's package system, you can always get a list of the files that are about to installed simply by choosing that menu item (Figure 2 shows the file lists for both the official MySQL binary and Complete MySQL). The list can be saved, printed, and used as a roadmap if, and when, you want to uninstall the package (though some creative license will need to be applied to find out where the package's root install directory is, represented as ./).
Figure 2: Using "Show Files" gives you a roadmap for uninstalling in the future.
Once the Installer finishes, you should be able to browse to /Library/MySQL and see a bunch of newly added files. Likewise, you should notice that a MySQL StartupItem has been installed into /Library/StartupItems. Note that even though MySQL has successfully been installed, it has not been automatically started... there's still some initialization to do.
Next, install the MySQL Preference Pane. Since I alone will be administrating MySQL, I've dragged my copy into /Users/morbus/Library/PreferencePanes/; if you'd like it accessible to any user on the machine, choose /Library/PreferencePanes/ instead. Once it's in place, open up your System Preferences, and choose the new "MySQL" item (Figure 3).
Figure 3: The newly installed MySQL Preference Pane.
To finalize your installation of MySQL, you'll want to first "Initialize" the database, than assign a password to the MySQL root user. MySQL database users have nothing to do with users that you've created within OS X, so don't get them confused. Once MySQL has been initialized, "Start" the server, then "Set Root Password" (Figure 4).
Figure 4: Setting MySQL's root password in the MySQL Preference Pane.
We can ensure that MySQL is running a few different ways: by checking the newly created logfiles (at /Library/MySQL/data/computername.local.err; you'll need to authenticate as an administrative user to do so), or by checking the currently running processes via the shell (ps auwx) or Panther's Activity Monitor (Figure 5), a much improved replacement for Jaguar's Process Viewer. If you've got hundreds of processes, use the "Filter" input to narrow in on "mysql".
Figure 5: Verify MySQL is running with Panther's Activity Viewer
In our next column, we'll look into interacting with our new MySQL database: administrative tasks from the command line, visual interaction with GUI-based tools like CocoaMySQL, inserting and manipulating database records with PHP, and more. We'll really just be scratching the surface on what's possible, but it'll give you enough knowledge to start your own database project, or feel relatively confident about installing someone else's. For now, students may contact the teacher at email@example.com.
- Who's in the attic?
- In non-Panther versions of OS X, Apple manually installed the optional PEAR, as well as a number of PEAR-released modules, into /System/Library/PHP. In Panther, they probably opted not to do this since PEAR became a default PHP extension. Unfortunately, it appears that the PEAR installation under 10.3 is incomplete (witness the "missing System.php" complaint when running /usr/bin/pear). Simply copying an existing System.php from Jaguar won't work, so you'll want to grab the latest from http://cvs.php.net/cvs.php/php-src/pear/System.php. Save this file to your Desktop and copy it into place with sudo cp ~/Desktop/System.php /usr/lib/php. You should then be able to run PEAR without a problem (list PEAR modules currently installed with sudo pear list).
- Every time Mac OS X boots, zillions of things occur... a fair portion of this zillion is controlled by StartupItems, files that say what should run and when. To create your own StartupItems, take a look at "Creating SystemStarter Startup Item Bundles" (http://www.opensource.apple.com/projects/documentation/howto/html/SystemStarter_HOWTO.html) and "Start Me Up: Writing and Understanding OS X StartupItems" (http://www.oreillynet.com/pub/a/mac/2003/10/21/startup.html).
- If you're interested in seeing what the MySQL PreferencePane actually does for you, the installation PDF provided with Complete MySQL has the command line equivalents.
Kevin Hemenway, coauthor of Mac OS X Hacks and Spidering Hacks, is better known as Morbus Iff, the creator of disobey.com, which bills itself as "content for the discontented." Publisher and developer of more home cooking than you could ever imagine (like the popular open-sourced aggregator AmphetaDesk, the best-kept gaming secret Gamegrene.com, the ever ignorable Nonsense Network, etc.), he is absolutely and positively disgusted by the lack of Jolt cola within walking distance. Contact him at firstname.lastname@example.org.