Blip. The Martino Flynn blog.MartinoFlynn.com

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

  1. Download the source here (Compressed GNU TAR archive)
  2. 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.
  3. Follow these instructions to install MySQL

PostgreSQL Installation

  1. Download the Unified Installer
  2. Follow these instructions to install PostgreSQL
  3. 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

  1. Download the Apache2 Unix source (Version 2.2.9 at the time this was written)
  2. Extract the source and run the configuration and installation commands below.
  3. ./configure --prefix=/Library/Apache2 \
    --enable-cache \
    --enable-disk_cache \
    --enable-asis \
    --enable-ssl \
    --enable-setenvif \
    --enable-unique_id \
    --enable-mods-shared=all
  4. 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

  1. Run the Mac Ports commands below
    sudo port install libpng
    sudo port install jpeg
    sudo port install freetype
    sudo port install libmcrypt
  2. Download the PHP source (Version 5.2.6 at the time this was written)
  3. Extract the source and run the configuration and installation commands below
  4. ./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-pear
  5. make
    sudo make install
  6. 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
  7. 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
  8. 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.
  9. 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


10 Responses to “Installing Development Environments on Mac OS X Leopard Part 1: Installing MySQL, PostgreSQL, Apache2, and PHP”

  1. Adrian Says:

    Thanks for the link! I’m glad you found the link useful.

  2. Jeremy Says:

    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

  3. Mike Ruschak Says:

    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.

  4. Jeremy Says:

    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

  5. asbenicio Says:

    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

  6. asbenicio Says:

    Mike , no Mark

    Sorry for my mistake

  7. Sonny Says:

    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

  8. Georg Says:

    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

  9. Andrew Says:

    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

  10. Mike Ruschak Says:

    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.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>