Setup Local Apache/MySQL/PHP Dev Environment in OS X Leopard

images.jpeg

I have used MAMP for a long time, but I recently decided to build a development environment on my MacBook Pro to mirror my test and production servers. MAMP uses Apache 2.0 and I really wanted to run Apache 2.2. I also needed custom PHP for use with Oracle databases. I just want

ed to share the documentation to setup my development environment. Feel free to comment and let me know if you have any improvements.

Some development tools I use with this environment:

NaviCat - http://www.navicat.com/ - A nice MySQL administration tool.

VirtualHostX - http://clickontyler.com/virtualhostx/ - A great GUI tool for Mac OS X that makes it a breeze to setup new virtual hosts. This toold handles the modifications to Apache configuration files and /etc/hosts. This tool just makes it faster to create and remove sites. Love it!

See the documentation below for details on how I configured my development environment.

Note: I use wget to download files at command line. Wget does not come standard with OS X, but you can download it and compile/install it easily. If you don't want to mess with that, you can use the curl command. Also, be aware that Apple updates may write over your PHP and Apache related files. Before you start an Apple update, make sure you have backups or are ready to recompile in case of problems.

Provides:
Apache, MySQL and PHP for OS X Leopard.Apache - Version 2.2.9 downloaded from httpd.apache.orgMySQL - Version 5.0.51b downloaded from mysql.com.PHP5 - Version 5.2.6 downloaded from php.net with libjpeg, libpng, imap and freetype.

mysql_logo.jpg

1. Install MySQL 5.0.51b
a. Download the package installer from http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg.
b. Download and install the Leopard preference pane fix if running community package 5.0.51a from ftp://ftp.mysql.com/pub/mysql/download/gui-tools/MySQL.prefPane-leopardfix.zip.
c. Install mysql-5.051b-osx10.4-i686.pkg and then the MySQLStartupItem.pkg.
d. Install the Leopard fix preference pane - MySQL.prefPane.
e. You can now start MySQL from system preferences.
f. NOTE: Make sure to follow standard security precaution like removing test databases, configuring your firewall to not expose port 3306 and setting a root password (The root password is blank until you set it!).

php-big.jpg

2. Activating PHP5
a. Open /etc/apache2/httpd.conf for editing.
b. Uncomment the line #LoadModule php5_module libexec/apache2/libphp5.so
c. Restart Apache via the Sharing Preference Pane or by issuing the command "apachectl restart" in terminal.
d. PHP5 is now running and can be tested by placing a phpinfo() command in a test php file in the Apache root at /Library/WebServer/Documents. Browse to http://localhost/<test-file-name>.php to see if PHP is active and working.
e. Unfortunately, PHP5 that ships with OS X Leopard does not have many of the PHP modules that are required by web applications. The next section will detail compiling custom PHP5 for OS X.
f. NOTE: If you need to edit php.ini, copy /etc/php.ini.default to /etc/php.ini

3. Customizing PHP

libjpg Install:
Application: libjpeg 6b
Description: Jpeg image processing library.
Install Path: /opt/libjpeg
Web Site: http://www.ijg.org/
Install Instructions:
% wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
% tar -xzvf /opt/jpegsrc.v6b.tar.gz
% cd /opt/jpeg-6b
% mkdir -p /opt/libjpeg/include
% mkdir -p /opt/libjpeg/bin
% mkdir -p /opt/libjpeg/man/man1
% mkdir -p /opt/libjpeg/lib
% ./configure --prefix=/opt/libjpeg
% sudo make install
% sudo make install-lib
% sudo ranlib /opt/libjpeg/lib/libjpeg.a

libpng Install:
Application: libpng 1.2.29
Description: libpng is the official PNG reference library.
Install Path: /opt/libpng
Web Site: http://www.libpng.org/pub/png/libpng.html
Install Instructions:
% cd /opt
% wget http://prdownloads.sourceforge.net/libpng/libpng-1.2.29.tar.gz?download
% tar -xzvf /opt/libpng-1.2.29.tar.gz
% cd /opt/libpng-1.2.29
% mkdir /opt/libpng
% ./configure --prefix=/opt/libpng
% make
% sudo make install
% sudo ranlib /opt/libpng/lib/libpng.a

freetype Install:
Application: freetype 2.3.7
Description: freetype is a software font engine.
Install Path: /opt/freetype
Web Site: http://freetype.sourceforge.net/index2.html
Install Instructions:
% cd /opt
% wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.7.tar.gz
% tar -xzvf /opt/freetype-2.3.7.tar.gz
% cd /opt/freetype-2.3.7
% mkdir /opt/freetype
% ./configure --prefix=/opt/freetype
% make
% sudo make install

imap2006i Install:
Application: imap2007b
Description: IMAP SSL libraries.
Install Path: /opt/imap
Web Site: http://www.washington.edu/imap/
Install Instructions:
% wget ftp://ftp.cac.washington.edu/mail/imap.tar.Z
% tar -xzvf /opt/imap.tar.z
% cd /opt/imap-2007b
% mkdir -p /opt/imap/include
% mkdir -p /opt/imap/lib
% make oxp
% cd c-client
% cp *.c /opt/imap/lib
% cp *.h /opt/imap/include
% cp c-client.a /opt/imap/lib/libc-client.a
% sudo ranlib /opt/imap/lib/libc-client.a

PHP 5.2.6 Install:
Application: PHP 5.2.6
Description: PHP scripting language.
Install Path: /opt/php5
Web Site: http://www.php.net
Install Instructions:
% cd /opt
% wget http://us.php.net/get/php-5.2.6.tar.gz/from/this/mirror
% tar -xzvf /opt/php-5.2.6.tar.gz
% cd /opt/php-5.2.6
% mkdir /opt/php
% ./configure --prefix=/opt/php --with-apxs2=/usr/sbin/apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc --with-mysql-sock=/tmp --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --with-xmlrpc --with-xsl=/usr --without-pear --with-jpeg-dir=/opt/libjpeg --with-png-dir=/opt/libpng --with-freetype-dir=/opt/freetype --with-gd --with-imap=/opt/imap --with-imap-ssl
% make
% sudo make install
% cp /opt/php-5.2.6/php.ini-recommended /opt/php/lib/php.ini

logo_apache.gif


4. Install Apache Web Server:
% wget http://www.gossipcheck.com/mirrors/apache/httpd/httpd-2.2.9.tar.gz
% tar -xzvf httpd-2.2.9.tar.gz
% cd httpd-2.2.9
% ./configure --enable-layout=Darwin --enable-mods-shared=all
% make
% sudo make install

Edit /etc/apache2/httpd.conf and change:

user _www group _www

to

user group

The above will allow apache to run as your user and will avoid permissions issues when housing apache virtual hosts in your /Users//Sites folder.

Blog Category: