As of version 10.2 (Jaguar), Mac OS X distinguishes itself by being the only consumer OS to install both Apache and PHP as components of every standard installation. That said, the version of PHP provided is a little out-of-date, and you'll need to install the MySQL database as well.
In this section, I'll briefly cover what's involved in setting up up-to-date versions of PHP and MySQL on Mac OS X. Before doing that, however, I'll ask you to make sure that the Apache Web server built into your Mac OS X installation is enabled.
Click to pull down the Apple menu.
Choose System Preferences from the menu.
Select Sharing from the System Preferences panel.
If the Sharing preference panel says Web Sharing Off, click the Start button to launch the Apache Web server.
Exit the System Preferences program.
With this procedure complete, Apache will be automatically run at start-up on your system from now on. You're now ready to enhance this server by installing PHP and MySQL!
Apple maintains a fairly comprehensive guide to installing MySQL on Mac OS X on its Mac OS X Internet Developer site. In this section, I'll attempt to boil down this information to the essentials to permit you to get started as quickly as possible.
First of all, if you happen to be running Mac OS X Server, MySQL is already installed for you. You can run Applications/Utilities/MySQL Manager to access it. More likely, however, you are using the client version of Mac OS X.
To install MySQL on the client version of Mac OS X, begin by downloading the Mac OS X 'pkg' format installation package from http://www.entropy.ch/software/MacOSx/mysql/. As of this writing, that site is the official source of MySQL for Mac OS X; however, MySQL AB (the developers of MySQL) have announced that they plan to take over distribution of this version beginning in February 2003, very soon after this book goes to print. You may, therefore, need to visit the download section of http://www.mysql.com/ to obtain an up-to-date installation package (and possibly updated installation instructions) by the time you read this.
Download and unpack the mysql-version.pkg.tar.gz file to obtain the mysql-version.pkg installation file, then double-click it to install MySQL.
Now, unlike most .pkg installations, MySQL requires some further configuration before it's ready to run on your system. Complete the following steps:
If you're running a version of Mac OS X older than 10.2 (Jaguar), you need to create a special user on your system that can run the server securely (this is already done for you on Mac OS 10.2 or later). To do this, open a Terminal window and type the following commands (don't type shell% — that's just there to represent the prompt displayed by the terminal):
shell%sudo niutil -create / /groups/mysql shell%sudo niutil -createprop / /groups/mysql gid 401 shell%sudo niutil -create / /users/mysql shell%sudo niutil -createprop / /users/mysql gid 401 shell%sudo niutil -createprop / /users/mysql uid 401
This creates a new user called mysql as well as a new user group for that user, also called mysql. You'll need to provide the administrator password for the first of these commands. Once the user is created, assign it a password of your choice by typing this command:
shell%sudo passwd mysql
Next, you need to initialize MySQL's databases. In a Terminal window, type the following commands (and provide the administrator password if you are prompted):
shell%cd /usr/local/mysql shell%sudo ./scripts/mysql_install_db
Finally, you must assign permissions to the mysql directory to prevent unauthorized access to it by anyone except the mysql user:
shell%sudo chown -R mysql /usr/local/mysql/*
With all the configuration done, you can launch the MySQL server with this command:
shell%sudo /usr/local/mysql/bin/safe_mysqld --user=mysql &
Presumably, you'll want your system to automatically launch the MySQL server at start-up. You can download, extract, and run mysql-startupitem.pkg.tar.gz from http://www.entropy.ch/software/MacOSx/mysql/ to make this happen — that's all there is to it!
As with MySQL, a Mac OS X version of PHP is not available from the official Website, but from a third party. Again, Apple also maintains a Web page detailing the installation procedure (although in this case, it is somewhat out of date).
Download the latest version of libphp4.so.tar.gz from http://www.entropy.ch/software/macosx/php/. It may be named libphp4.so-version.tar.gz; if so, rename it to libphp4.so.tar.gz before proceeding with the following steps:
Double-click the downloaded file to extract libphp4.so onto your desktop.
Open a new Terminal window and type this command to move the file to the Apache configuration directory:
shell%sudo mv Desktop/libphp4.so /usr/libexec/httpd/
Provide the administrator password if you are prompted.
Go to the /etc/httpd directory and run the Apache module configuration program (apxs) to install or upgrade to the new module with the following commands:
shell%cd /etc/httpd shell%sudo apxs -e -a -n php4 libexec/httpd/libphp4.so
Add a line telling Apache which file extensions to treat as PHP scripts to the httpd.conf configuration file with the following command (which you must type all on one line):
shell%echo 'echo "AddType application/x-httpd-php .php .php3" >> /etc/httpd/httpd.conf' | sudo sh -s'
Finally, restart Apache with the new PHP module in place:
shell%sudo apachectl graceful
Because Mac OS X is based on the BSD operating system, much of its internals work just like any other Unix-like OS (e.g. Linux). From this point on in the book, owners of Mac OS X servers can follow the instructions provided for Unix/Linux systems unless otherwise indicated. No separate instructions are provided for Mac OS X unless they differ from those for other Unix-like systems.