Installing Development Environments on Mac OS X Leopard Part 1: Installing MySQL, PostgreSQL, Apache2, and PHP
October 14th, 2008 by Mike Ruschak
Installing a development environment on Mac OS X Leopard is extremely tricky. In my attempts I ran into many obstacles. Finally, after hours of hard work, I have what I believe to be a rock-solid installation process. In order to achieve this I had to bury myself in books and online articles. Some of the installations have been covered by others, and I have included links to these excellent articles. Here are my instructions for your convenience. I hope they help or at least save someone time.
Many developers may argue that you can install all the aforementioned software packages using Mac Ports. My argument is Mac Ports packages sometimes fail, plus I also don’t like the way some of the packages are configured. In addition, I am very particular about how things are installed and configured on my system. Unix software should be installed and configured in “/usr/local” and sometimes “/Library”. Mac Ports should adhere to these rules and use the “/usr/local” path. Mac Ports shouldn’t install packages that are already installed on the system. This is just inefficient, and a huge waste of storage space. Mac Ports is an excellent piece of software, and can be a huge time saver. However, I am very picky about what software I install using Mac Ports.
Others may argue that Mac OS X comes with all of this software already installed. I totally agree. PHP in particular, though, doesn’t come with all the modules I need to do work here at Martino Flynn. Unfortunately this is sometimes the case with certain UNIX packages on Mac OS X.
As a side note. When you install software from source you can upgrade the software whenever you want. You are not dependent on waiting on Apple or Mac Ports developers. Lastly, installing software from source is an excellent way to learn about how Mac OS X and Unix systems work. Lets begin.
Dependencies needed to install the development environment.
- Install the Apple Developer Tools (Xcode Tools)
- Install Mac Ports (required if you want GD support)
- I wrote this article with the assumption that you are familiar with the Unix command line. If you are not then I strongly suggest you pick up a book and become familiar with it. I recommend the Unix Visual QuickStart Guide.
- You must be familiar with installing software from source on Unix. If you are not check out this article. I also recommend you Google around and find other good references as well on building software on Unix systems.
Configure PATHS
Make sure to setup your Unix shell paths, or nothing will work. My path is in the file .profile in my home directory. Create this file if it does not exist. You can also put your path in .bash_profile or .bash_login.
export PATH=/opt/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/Library/Apache2/bin:/Library/PostgreSQL8/bin:/usr/local/php/bin:$PATH
MySQL Installation
- Download the source here (Compressed GNU TAR archive)
- Extract the source to a common location such as “/usr/local/src” or “~/src”. Its good practice to keep all downloaded source code in one place.
- Follow these instructions to install MySQL
PostgreSQL Installation
- Download the Unified Installer
- Follow these instructions to install PostgreSQL
- Download and Install pgAdmin III
The pgAdmin software should allow you to connect to your server at the hostname “localhost”. After you connect you should be able to create a test database.
Apache2 Installation
- Download the Apache2 Unix source (Version 2.2.9 at the time this was written)
- Extract the source and run the configuration and installation commands below.
./configure --prefix=/Library/Apache2 \
--enable-cache \
--enable-disk_cache \
--enable-asis \
--enable-ssl \
--enable-setenvif \
--enable-unique_id \
--enable-mods-shared=all
make
sudo make install
If you made it this far congratulations. Installing PHP from source on Mac OS X Leopard with many of the popular modules is not simple. My configuration includes all the modules in the Apple installation with the addition of GD and many more. This PHP configuration I came up with will communicate with all of your DBMS packages including PostgreSQL, SQLite, and MySQL.
PHP Installation
- Run the Mac Ports commands below
sudo port install libpng
sudo port install jpeg
sudo port install freetype
sudo port install libmcrypt
- Download the PHP source (Version 5.2.6 at the time this was written)
- Extract the source and run the configuration and installation commands below
./configure --prefix=/usr/local/php \
--with-zlib \
--with-xsl \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-apxs2=/Library/Apache2/bin/apxs \
--with-curl \
--with-iodbc=/usr \
--with-openssl \
--with-pgsql=/Library/PostgreSQL8 \
--with-pdo-pgsql=/Library/PostgreSQL8 \
--with-ldap=/usr \
--with-kerberos=/usr \
--with-gd \
--with-jpeg-dir=/opt/local \
--with-png-dir=/opt/local \
--with-freetype-dir=/opt/local \
--with-mcrypt=/opt/local \
--with-iconv=/usr \
--with-bz2=/usr \
--enable-cli \
--enable-exif \
--enable-zip \
--enable-sockets \
--enable-ftp \
--enable-wddx \
--enable-calendar \
--enable-soap \
--enable-sqlite-utf8 \
--enable-pcntl \
--enable-mbstring \
--enable-mbregex \
--enable-bcmath \
--without-pearmake
sudo make install
- Copy over the php5 Apache config file from the Apple web server. Run this command.
cp /etc/apache2/other/php5.conf /Library/Apache2/conf/extra/httpd-php5.conf - Include the new config file in your httpd.conf “/Library/Apache2/conf/httpd.conf”. Add this to the bottom of the file.
Include conf/extra/httpd-php5.conf - Run the following command:
which php
If the path returned is not “/usr/local/php/bin/php” then you have come across a post installation bug. See below to solve this problem. Otherwise your done. - There is a bug when installing PHP 5.2.6 on Mac OS X Leopard. For some reason the PHP command line program is named incorrectly “php.dSYM”. Your case may be different. However to fix this you simply need to rename the tool. I used the commands below:
cd /usr/local/php/bin/
sudo mv php.dSYM php
Please post a comment if you don’t come across this bug. Here is the bug report if you would like more information.
Keep coming back. Part 2 is coming soon and will cover installing Git, Ruby, Mongrel, Rails, Gems, and more.
- Mike Ruschak
This entry was posted by Mike Ruschak on Tuesday, October 14th, 2008 and is filed under Development, Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.











October 15th, 2008 at 9:05 am
Thanks for the link! I’m glad you found the link useful.
October 25th, 2008 at 5:29 pm
Great article! Unfortunately, it was couple of months late for me =( However, I’m really looking forward to Part 2. I’ve been researching and am in the process of trying to set up my development machine to include: PHP, MySQL, Apache2 (with virtual hosting), git, and a complete Ruby on Rails solution. I’m looking forward to seeing how you achieve this. Any spoilers as to when you might publish it?
Cheers,
- j
October 27th, 2008 at 8:58 am
Jeremy,
Glad you found the article to be useful. With Leopard being 64bit its very challenging to get this software installed and all the packages communicating with each other efficiently. Unfortunately Marc Liyanage over at entropy.ch has not come out with a PHP package for Leopard yet. I realize Marc is busy and he has my respect and understanding. His package saves us time. There is one available however that you can use but it is in beta. I chose to use it however for as long as possible so I can use the Mac OS X built in Apache server. However there will come a time when this won’t be possible anymore as PHP is updated. So I left this out of the article. However if your interested you can find this php package on the entropy forums.
As for my second article. I have no timetable right now for it because of some other things I have going on. I have finished some of the installations and will be writing the article soon.
October 28th, 2008 at 2:21 pm
Mike,
Thanks for the reply. I too have been keeping an eye on Marc’s page for a “newer” php build for leopard. He does great work and I highly recommend his site to anyone.
I’m looking forward to your next installment because I’ve finally decided to try my hand at Rails. A friend turned me on to it and after some reading, I’m extremely eager to get started. I was researching tips on the best way to integrate Git, Ruby, Mongrel, Rails, Gems, etc with my current development environment.
Any tips you could offer would be greatly appreciated!
I’ll be sure to add this site to my “best of” list.
Thanks again,
- j
November 16th, 2008 at 11:52 am
I Mark
Before I attempt one more painfull task (I`m very angry of many, many attempts to get phppgadmin+postgres from enterprisedb.com) I need one information, if you can pass to me:
There are some special tip about phppgadmin?
thanks in advance
November 16th, 2008 at 12:03 pm
Mike , no Mark
Sorry for my mistake
December 3rd, 2008 at 7:32 am
Ok..great article…only thing is…I can’t access my localhost anymore, nor any of my virtual hosts. Any suggestions?
I really need help getting this back up and running. I wanted to do this in order to get php with GD and image capabilities, now I’m stuck.
Any help would be greatly appreciated.
Sonny
January 9th, 2009 at 9:52 am
Hi,
great tutorial. It’s exactly what I’ve been looking for.
I performed all the steps you said and it went great. The bug you mentioned in the end did not occurr.
But I’ve got a different problem.:
When I activate Web-Sharing in System Preferences Leopard uses the built-in Apache and PHP. How can I make the Leopard to use the system I built?
thanks for everthing
Georg
February 11th, 2009 at 8:30 am
Thanks for this excellent tutorial, which went well, without the last bug occurring.
I have the same problem as Georg – whenever I activate Web Sharing, it uses the built-in Apache rather than the one created here. I feel sure there must be a very simple solution to this, but I can’t find it. Do you have any ideas?
I’m running MacOS 10.5.6 on a MacBook.
Andrew
February 16th, 2009 at 2:18 pm
Andrew,
I will look into this. At the very least perhaps I could create a simple application that starts up the correct Apache server. Sorry for the delay in releasing part 2. I am currently working on it and just want to make sure everything is right before I release it.