This article relates to installing and working with Apache, PHP and MySQL in OS X 10.4. These instructions may be out of date on later versions of OS X.
The first part of this tutorial focused on getting Apache up and running in a way that would hopefully reflect a live server environment. This second part will explain how to get PHP and MySQL, the most popular server side language and database combination, installed on your local machine.
Many old-schoolers would download the latest source from php.net, compile it for their machines with custom modules and install it straight to Apache in OS X. As you may have guessed, this is not my way, instead I prefer to get pre-compiled packages from Marc Liyanage that can be installed into Apache like you would any other OS X package. He has all of the latest flavours available—I use PHP 5 locally to reflect my online environment. Using Marc's excellent packages, you don't need to delve into the httpd.conf file to register file extensions or any other dirty work.
Update: I've just upgraded my work system using the latest version of Marc's PHP packages and short tags—the preferred method of echoing data in frameworks like CodeIgniter—are not enabled by default. To enable them you need set
short_open_tag = On in the php.ini file, located in
usr/local/php5/lib/. The value you need to change should be around line 141 and should be changed to the above. This allows you to use
<?= ?> tags in your code.
Since version 4.0.11, Marc's packages have been superseded by similar packages direct from MySQL—these are exactly the same in that they allow you to install the MySQL database from a one-click package file, and they also helpfully add a system preferences button to give you a bit more control and allow you to run the database at start-up and restart the MySQL server.
Administering MySQL Users & Databases
As well as the self-installing package, MySQL have released a number of useful tools that make running MySQL a much simpler, and less command-line driven, task.
The first of these tools is MySQL Administrator—an application that allows you to add and remove users and database schemas. This is the easiest way to maintain your user accounts on the local database and carry out simple database design tasks. I always change my root password from here as it takes far less time than going through the terminal.
The second tool I use extensively is MySQL Query Browser, also from MySQL. This application revolves around database design and allows you to create databases, (called Schemas), stored procedures, (if you use MySQL 5) and add/edit/delete data from your databases. This was the main method of designing and altering the CheckWithMother databases during development. I should warn you that MySQL Query Browser does suffer from sporadic quitting problems—this is being worked on by the developers but can be quite annoying.
Another advantage of both of these tools is that they allow you to access external databases if your hosting company allows it—this is very useful as I can modify data on a live database if such a need arises.
There are other tools of note that can be used to play with MySQL—in the past I have used both CocoaSql and YourSql, but neither support stored procedures in MySQL 5 so became less useful when Dreamhost upgraded their versions.
That's it! You should now be able to run local domains, administer your databases and run PHP-driven sites all form your local machine. Now lets hope someone makes it just as easy to install and deploy [Ruby on Rails] locally.