Most web applications we develop are based on OSX, Apache2, MySQL, PHP5 and Propel. Unfortunately the versions bundled with OSX are not usually kept current by Apple or are bare bones, so it's up to us to load the necessary versions ourselves.
Installing MySQL
The Community Edition of MySQL is available as a free download.
As of this time, it's best to stay with the 5.0 release, rather than 5.1, as word is that it was rushed out and not fully vetted.
If MySQL is not automatically starting at system boot, see http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/
Installing PHP5
For OSX 10.5 and earlier, the Entropy PHP Apache Module distribution compiled by Marc Liyanage is invaluable. It contains a large number of popular PHP extensions, which make it much more versatile than the bare bones PHP included with OSX.
Clint has also documented some pitfalls he's run into during install.
For OSX 10.6, 10.7, etc, Liip maintains a release of PHP 5.3, 5.4+ based on the entropy build. It offers a one-line install, as well as full access to the source and instructions to build your own (if need be).
In development environments the php.ini-development should be used:
- > sudo mv /usr/local/php5/lib/php.ini /usr/local/php5/lib/php.ini.bak
- > sudo cp -p /usr/local/php5/lib/php.ini-development /usr/local/php5/lib/php.ini
In production environments the php.ini-recommended should be used:
- > sudo mv /usr/local/php5/lib/php.ini /usr/local/php5/lib/php.ini.bak
- > sudo cp -p /usr/local/php5/lib/php.ini-recommended /usr/local/php5/lib/php.ini
Setting shell environment paths
Since now there are multiple copies of PHP and MySQL installed on the same server, it's useful to set our environment paths so that, when using Terminal, the binaries we installed above are called. Otherwise the Apple-installed versions (we are not using) would be called, unless we used the full path to the binary every time. Setting the shell environment paths to the versions of PHP and MySQL we are using avoids confusion, like "why isn't mysql running?" Ah... but it is.
Paths may be customized by creating a user shell profile. We use the bash shell, so:
> pico ~/.bash_profile
and add one line at the end:
export PATH=/usr/local/mysql/bin:/usr/local/php5/bin:$PATH
Open a new Terminal window (shell) for these changes to be recognized.
The bash profile will make the shell look in our new mysql and php5 bin directories first when looking for an executable. If it's not found, it continues down the search tree, the pre-existing $PATH .
You can always tell which instance of a binary is being used by typing, ie:
> which pearwhich displays the full path to entropy distribution of PEAR we installed above.
/usr/local/php5/bin/pear
Setting the MySQL root password
After setting your environment paths, be sure to set the MySQL root password. This is done from the command line:
shell>mysqladmin -u root password "
shell>newpwd
"mysqladmin -u root -h
host_name
password "newpwd
"
Updating PEAR
PEAR is a framework and distribution system for reusable PHP components. It's good to be sure they are at their current, newest versions.
> sudo pear upgrade-all
Installing Propel
If you do not know what Propel is, you probably do not need to install it.
If you are a developer you should really really get to know it. Propel is an Object-Relational Mapping (ORM) framework for PHP5. It allows you to access your database using a set of objects, providing a simple API for storing and retrieving data.
To install the current version of Propel on a production box do the following:
> sudo pear channel-discover pear.propelorm.org
then...
> sudo pear install -a propel/propel_runtime
Special Note for 10.7 Server
If you need to edit any Apache configuration directives on a 10.7 server, see the Apple KB article at http://support.apple.com/kb/HT4813 . There are specific methods there for specifying directives based on the scope those directives need to apply to.