Published:

May 17, 2008

How To Setup OS X Leopard for a LAMP Development

Before we start, LAMP = Linux, Apache, MySQL and PHP and yes I...

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 recieved my lovely new work Macbook Pro and have been setting it up for some serious PHP & 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.

Firstly, wipe and reinstall your version of Leopard and remove all of those extra printer drivers and languages to save yourself over 5gb.

Do all of the software updates so any changes you do to the default locations are not over written by a security update.

I recommend creating a src folder within your user in to keep all of your source files.

Get your hands on the latest version of xcode and install it. This is needed by everything, as it has all the gcc utils required for compiling anything!

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
  • ./configure --prefix=/usr/local/mysql_dev --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared
  • make
  • sudo make install
  • cd /usr/local/mysql_dev
  • sudo ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql_dev (make a note of the password commands needed to set a root user)
  • sudo chown -R mysql ./var
  • sudo /usr/local/mysql_dev/bin/mysqld_safe & (this starts the mysql daemon)
  • 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.plist

<?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.plist
  • sudo 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
  • ./configure --prefix=/usr --without-iconv --with-mysql=/usr/local/mysql_dev --with-pdo-mysql=/usr/local/mysql_dev --with-apxs2=/usr/sbin/apxs --with-curl=/opt/local/bin/curl --with-zlib --with-bz2
  • make
  • sudo make install
  • From your source unpacked directory copy the shared object: sudo cp ./libs/libphp5.so /usr/libexec/apache2/libphp5_dev.so
  • Check in /usr/bin for your php binary and rename it properly:
    • ls /usr/bin/php*
    • sudo mv /usr/bin/php.dSYM /usr/bin/php
  • 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
  • ./configure -enable-layout=Darwin -enable-mods-shared=all
  • make
  • sudo make install
  • 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! Before starting in earnest you might want to have a quick read of our article on using apache for local development for some useful tips.

Lets Talk

Leave your phone number or email address below and we will contact you back

Or you can call us on 0121 224 7960