0 comments
web
29 Mar 2008

How To Setup OS X Leopard for LAMP Development

This has now been replaced by a more recent article

Before we start, LAMP = Linux, Apache, MySQL and PHP and yes I know Macs aren’t Linux based, but FreeBSD is a flavour of Unix so it’s close enough!

Having recently received my lovely new work Macbook Pro and have been setting it up for some serious PHP and MySQL development. Some of these stages were seriously difficult to find and it took myself and Sheldon Els (also on his shiny new Macbook Pro) a while to figure out; so we thought we would share..

As both of us work with a php framework (php-wax) we have to create custom installs of php, mysql and apache; mainly because the installed version of php does not support PDO or PEAR. Of course soon as you recompile php it generates a Darwin version of the shared object that Apache uses meaning Apache has to be re compiled also.

While xcode is downloading from the Apple Dev Center install all your standard applications (Quicksilver, Adium, Textmate etc).

As mentioned above some security updates will over write files in default system locations; meaning your custom setup will be lost. This guide will try to avoid such things and install to custom locations.

Anyway, time to get to work so crack open a terminal window and lets begin.

MySQL

Download the latest stable release for your machine (please make sure you download the right version!).

Unpackage and change in to the new MySQL directory and then run these on your command line

use the commands from above to set your root password.

That is MySQL setup and running, but to get it to start on boot you will need to copy the text below and save it to /Library/LaunchDaemons/com.mysql.mysqld.plistp.

<?xml version=“1.0” encoding=“UTF-8”?> <!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”> <plist version=“1.0”> <dict>     <key>KeepAlive</key>     <true/>     <key>Label</key>     <string>com.mysql.mysqld</string>     <key>Program</key>     <string>/usr/local/mysql_dev/bin/mysqld_safe</string>     <key>RunAtLoad</key>     <true/> </dict> </plist>

Now run these commands to get MySQL to start at boot:

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plistsudo
launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Also add the below line to you ~/.profile

export PATH=“/usr/local/bin:/usr/local/sbin:/usr/local/mysql_dev/bin:$PATH

That is it! MySQL is sorted… NEXT!

PHP

Download the latest stable release in to your source folder

Unpackage and change in to the new php directory

From your source unpacked directory copy the shared object:

Check in /usr/bin for your php binary and rename it properly:

Fix your pear install directory

cd /usr/lib/php
sudo pear config-set php_dir /usr/lib/php

PHP done and dusted… Almost finished..

Apache

Download the latest stable version into your source folder

Unpackage it and guess what, change into the httpd directory

comment out the old php library load and add a new one in your /etc/apache2/httpd.conf

LoadModule php5_module libexec/apache2/libphp5_dev
#LoadModule php5_module libexec/apache2/libphp5.so

enable vhosts in your /etc/apache2/httpd.conf (Include /private/etc/apache2/extra/httpd-vhosts.conf)

fix up your /etc/apache2/extra/httpd-vhosts.conf with appropriate vhosts.

add a line in your /etc/hosts for each virtual host.

That is everything up and running, not so hard when you know how!

blog comments powered by Disqus