posted by kevin on June 14, 2009

Step 1 - Install Apple XCode

Apple Developer Tools (XCode) includes the the compiler you'll need to get everything compiled. You find this on your Leopard install disc, or you can download the latest version from apple.

Download Apple XCode Developer Tools

Step 2 - Download and install wGet

You should run all of this in superuser mode:
To enter superuser mode, in the terminal type:
sudo -s
It will then prompt you to enter your password, this is your OSX password.

WGet is a simple command line utility that will download files from the web.

As of the writing 1.11.4 is the current version and can be downloaded at:

Download wget 1.11.4

Now once you have this downloaded you need to install it. In the terminal, go to where you downloaded the file and run these commands.

 
tar xvfz wget-1.11.4.tar.gz
cd wget-1.11.4
./configure
make
make install
 

When you do this you'll be compiling c code and you'll see the compiler outputting lots of information that you don't really need to pay attention to unless there is an error.

Once this is done wget will be install on your system and you can use it to download files from the command line.

Step 3 - Downloading and installing MySQL

MySQL AB provides a simple installer for Mac OSX that you can/should use to get MySQL up and running.

This link will take you to the download page, just look under the Download MySQL For Mac Just pick the package that fits your system.

After downloading and opening the .dmg file, install the MySQL, then the startup item, and then the preferences pane. Once you install the preferences pane it should bring up a button to start MySQL. Go Ahead and start it to make sure it starts.

Now we'll go ahead and set a root password for MySQL. (Substitute your password for newpassword but keep the quotes.)

 
cd /usr/local/mysql/bin
mysqladmin -u root password “newpassword”
 

Step 4 - Compile Apache HTTP Server

 
wget http://apache.mirror.facebook.com/httpd/httpd-2.2.11.tar.gz
tar xvfz httpd-2.2.11.tar.gz 
cd httpd-2.2.11
./configure --prefix=/usr/local/apache2 --enable-module=so --enable-module-rewrite
make
make install
cd /usr/local/apache2
cp httpd /usr/sbin/
cp apachectl /usr/sbin/
 

Step 5 - Install GD Dependent Packages

Download And Compile libJpeg
 
cd /usr/local/src/
wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
tar xvfz jpegsrc.v6b.tar.gz 
cd jpeg-6b/
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared
make
make install
 
Download And Compile libPng
 
cd /usr/local/src/
wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.37.tar.gz
tar xvfz libpng-1.2.37.tar.gz
cd libpng-1.2.37
./configure
make
make install
 

Step 6 - Install Mcrypt dependencies

Download And Compile libMcrypt
 
cd /usr/local/src/
wget http://internap.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar xvfz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads --enable-dynamic-loading
make
make install
 

Step 7 - Install PHP

PHP Configuration File: I always just create a php_install file that I use to save my configuration and run the configuration.

First copy this code and put it in a file named: /usr/local/src/php_install.sh

 
cd php-5.2.9  &&
./configure \
    --without-iconv \
    --with-apxs2 \
    --enable-pdo \
    --with-gd \
    --with-zlib \
    --with-jpeg-dir=/usr/local \
    --with-png-dir=/usr/local \
    --with-curl \
    --with-mcrypt \
    --with-pdo_mysql=/usr/local/mysql/ \
    --with-mysqli=/usr/local/mysql-5.1.35-osx10.5-x86/bin/mysql_config 
 

Now run these commands to make your php configuration script executable:

 
cd /usr/local/src
chmod 775 php_install.sh
 

Now we'll run our configuration script:

 
./php_install.sh
 

It should run through the PHP Configuration process and end with something like this:

 
Generating files
creating ./config.status
creating php5.spec
creating main/build-defs.h
creating scripts/phpize
creating scripts/man1/phpize.1
creating scripts/php-config
creating scripts/man1/php-config.1
creating sapi/cli/php.1
creating main/php_config.h
main/php_config.h is unchanged
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+
 
Thank you for using PHP.
 
 

Now we're going to make and install our PHP.

 
cd php-5.2.9
make && make install
 

This will compile and install php.

We're getting close now...

Configure Apache

Changes To Our httpd.conf file:

Run this command to make your configuration files writable by all users.

 
cd /usr/local/apache2/conf
chmod -R 777 *
 

No open TextEdit, or your favorite text editor and open: /usr/local/apache2/conf/httpd.conf

Search for AddType and add these lines to the configuration file:

 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
 

Now search for '# Virtual hosts' and uncomment the following line so it looks like this:

 
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
 

Search for 'LoadModule'

Add these two lines in that section:

 
LoadModule php5_module /usr/libexec/apache2/libphp5.so
LoadModule rewrite_module /usr/libexec/apache2/mod_rewrite.so
 

Now search for 'IfModule dir_module' Add index.php so it looks like this:

 
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
 

Now search for 'DocumentRoot' and change it to:

 
DocumentRoot "/data/web/vhosts"
 

And just a little below that you'll see another directory tag and the comments will say to change that line to the same value as your document root:

 
<Directory "/data/web/vhosts">
 

Step 6 - Install phpMyAdmin

The reason I'm doing this is we need to administer our database and probably 90% of the people use phpMyAdmin to get the job done.

 
mkdir -p /data/web/vhosts
cd /data/web/vhosts
wget http://superb-east.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.1.5-all-languages.tar.gz
tar xvfz phpMyAdmin-3.1.5-all-languages.tar.gz
mv phpMyAdmin-3.1.5-all-languages local.mysql
 
Add Virtual Hosts:

Open up /usr/local/apache2/conf/extra/httpd-vhosts.conf in Textedit:

Now at the bottom of that file you'll see the vhosts configuration section:

Change it to:

 
<VirtualHost *:80>
    ServerAdmin youremail@example.com
    DocumentRoot /data/web/vhosts/example.com
    ServerName local.example.com
    ErrorLog logs/example.com-error_log
    TransferLog logs/example.com-access_log
</VirtualHost>
 
<VirtualHost *:80>
    ServerAdmin youremail@example.com
    DocumentRoot /data/web/vhosts/local.mysql
    ServerName local.mysql
    ErrorLog logs/local.mysql-error_log
    TransferLog logs/local.mysql-access_log
</VirtualHost>
 

Now you'll see we set up two virtual hosts. One for local.example.com which would be one of your sites and it would respond to when you typed in local.example.com into your browser as long as the DNS resolved to your local box.

Now lets go ahead and modify your hosts file to make local.mysql resolve to your loopback address (127.0.0.1)

 
chmod 777 /private/etc/hosts
 

Now open up /private/etc/hosts in your text editor and add a line to the bottom so your file would look something like this:

 
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0    localhost
127.0.0.1   local.kevinkorb.com
127.0.0.1   local.mysql
 

Your computer will check this file first to resolve hosts before it goes to DNS to try to resolve the hostname.

Now you'll want to stop apache if it's running and start it again.

Open up 'System Preferences' and click on 'Sharing'.

Now turn off 'Web Sharing' if it was already checked and then click it again to turn it on.

Now point your browser to: http://local.mysql

And your phpMyAdmin should come up.

Just type in your username as root, the password whatever you set up earlier in this tutorial and you should see that you can now set up your databases.

Also if you setup other domains in your vhosts than check to make sure they are working.

There you go, you're all setup now.

One comment to "Install PHP 5.2.9+MySQL 5.1+Apache 2+GD+PDO_MySQL+cURL on OSX Leopard 10.5.7"

#35
Shinzies says:
July 13, 2009 at 03:48 pm
Great tutorial.. To be on the safe side and also to help newbies you could explain how to patch php with suhosin. The search for libmcrypt brought me here. Bookmarked you on Stumble! Oh, by the way very clean design
Bookmark and Share

Leave a Comment

Your email address will not be published.

(You can enclose code in <php></php> blocks.)

You may use Markdown syntax.

Please enter the letters as they are shown in the image above.
Letters are not case-sensitive.