posted by kevin on July 1, 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.

 
sudo -s [It will then prompt you for your password, this is your OSX password]
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/bin
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 5.3

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.3.0  &&
./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 \ 
    --with-mysql=/usr/local/mysql-5.1.35-osx10.5-x86
 
 

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.3.0
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.

28 comments to "Install PHP 5.3, Apache2, GD, MySQL 5.1 on OSX Leopard (10.5.7)"

#28
rsvirani says:
July 8, 2009 at 02:00 pm
I am having a lot of issues using mysqli as opposed to mysql. Can you write up how to use mysql instead? When running the php configure script, simply specifying mysql instead results in the error: Note that the MySQL client library is not bundled anymore!. Maybe you could write up how to download and compile the headers also?
#30
July 8, 2009 at 06:27 pm
@rsvirani I have updated the config line to compile PHP with MySQL AND with MySQLi. Obviously you can omit the MySQLi if you want... Let me know if you have any issues.
#32
rsvirani says:
July 10, 2009 at 08:36 am
Works great! I have to say that this is the best guide I have encountered for installing the stack. I have one issue that is not related to the install method you have written, but you may have some insight. When I look at phpinfo, the php.ini path is /usr/local/lib and there is no php.ini file there. I copied php.ini-development to /usr/local/lib/php.ini and chmodded it, then restarted apache. Now, php doesnt load altogether. As soon as I remove the php.ini file, it works perfectly fine again. Any ideas? Here is the final configure options I used if anyone would like an example with mbstring:
 
./configure \
    --without-iconv \
    --with-apxs2 \
    --enable-pdo \
    --with-gd \
    --with-jpeg-dir=/usr/local \
    --with-png-dir=/usr/local \
    --with-curl \
    --with-mcrypt \
    --with-pdo_mysql=/usr/local/mysql/ \
    --with-mysql=/usr/local/mysql \
    --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --enable-mbstring \
    --with-config-file-path=/usr/local/lib
 
#34
July 12, 2009 at 05:20 pm
look at your apache error log.
 
/usr/local/apache2/logs/error_log
 
If it's with your php.ini file, then you should get an error or at least a warning. For example I added loading the extension fatalerror.so just to emulate an error with the php ini file, and it does give me feedback on what the error was.
 
[Sun Jul 12 17:17:33 2009] [notice] caught SIGTERM, shutting down
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/fatalerror.so' - dlopen(/usr/local/lib/php/extensions/no-debug-non-zts-20090626/fatalerror.so, 9): image not found in Unknown on line 0
 
Hopefully that will help you out.
#36
Luke says:
July 15, 2009 at 11:38 am
I'm getting http://pastebin.ca/1495951 when trying to compile PHP. I had to change your configure command to this to get it to configure:
 
cd php-5.3.0  &&
./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-mysql=/usr/local/mysql \
    --with-pdo-mysql=/usr/local/mysql/bin/mysql_config \
    --with-mysql-sock=/tmp/mysql.sock \
 
any ideas?
#37
July 15, 2009 at 12:15 pm
@Luke, What were the errors you were getting while trying to compile PHP using my config command. Just a little more background, are you using the lastest OSX version, intel hardware? Thanks.
#39
UncoolJohn says:
July 20, 2009 at 04:33 pm
Hi Kevin, Great tutorial. I'm having some problems compiling php. It looks like errors with the zend framework.
 
Undefined symbols:
  "_zend_mh_bundle_error", referenced from:
      _php_load_extension in dl.o
      _php_load_extension in dl.o
  "_zend_mh_bundle_unload", referenced from:
      _php_load_extension in dl.o
      _php_load_extension in dl.o
      _php_load_extension in dl.o
      _php_load_extension in dl.o
      _php_load_extension in dl.o
  "_zend_mh_bundle_symbol", referenced from:
      _php_load_extension in dl.o
      _php_load_extension in dl.o
  "_zend_mh_bundle_load", referenced from:
      _php_load_extension in dl.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libs/libphp5.bundle] Error 1
 
 
Can I leave zend out (guessing it's zlib)?
#40
July 20, 2009 at 05:00 pm
@UncoolJohn,

The zend framework is actually just PHP code and is not installed with the tutorial. ZLib is a compression utility that is required by many packages.

The zend refrences above are to 'Zend Core' which makes up the heart of PHP. So hopefully that partly answered your question. Did you install everything in the tutorial or just the PHP part? If you skipped the Apache part it might have something to do with this. If you can supply just a little more background I'll try to help you out. What kind of mac are you using, are you running 10.5.7?

Thanks.
#41
UncoolJohn says:
July 20, 2009 at 05:13 pm
Kevin, I already had MySQL 5.1.36 installed so I skipped that, but everything else I have done verbatim. I am running 10.5.7 on the new 13" MacBook Pro. I had already been trying to setup PHP and Apache using the versions that came with Leopard, but I couldn't get GD2 to work, so I started on your strategy to get the newest version of PHP installed with GD2 included. Do I need to remove the existing versions before continuing? Thanks.
#42
July 20, 2009 at 05:33 pm
@UncoolJohn,

Try disabling your web sharing before running your make command. If that still doesn't work (I wouldn't be horribly suprised if that was the case) try starting with a very minimal configure statement to see if you're able to compile the most basic PHP. Also after running your configure statement run 'make clean' before running 'make'.

If you can get the minimal PHP compiled then add in a few of the config parameters and recompile and eventually you'll find the statement that is screwing things up.

Let me know what you find out, it might really come in handy for another person having the same issue. Thanks.
#43
UncoolJohn says:
July 20, 2009 at 08:54 pm
Kevin, just did that and I also ran "make clean" in the php-5.3.0 directory and then re-ran the php_install.php and compiled. It worked. Thanks so much for your help and the great tutorial.
#46
Eric says:
July 22, 2009 at 12:54 am
kevin.. i followed your directions almost perfectly, and got no errors, but GD isn't showing up when i get php's -info
#47
July 22, 2009 at 08:43 am
@Eric,

What does it say for your build date on your phpInfo page? Also what is your config command according to your phpinfo page?
#48
Eric says:
July 22, 2009 at 09:25 am
i feel like the old apache is still being loaded from /etc/apache2. when i started from a completely fresh install, ran software update to get to 10.5.7 and downloaded the newest iphon/xcode dev tools, there was no httpd or apachectl in /apache2 at step 4. i looked around and found them in /apache2/bin and just modified those two lines to point to the files. did i mess that up?
 
Build Date
Feb 5 2009 21:17:28
 
Configure Command
'/SourceCache/apache_mod_php/apache_mod_php-44.2/php/configure' '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear'
 
#49
July 22, 2009 at 09:38 am
@Eric,

Since the build date is from February, you're seeing the PHP that came with Leopard.

Thanks for pointing that out. That was a typo on my part.

Now it seems that everything might be good, you just need to copy your libphp5.so from your /usr/local/src/php-5.3.0/libs/ (assuming it's there) to: /usr/libexec/apache2/libphp5.so

 
cp /usr/local/src/php-5.3.0/libs/libphp5.so /usr/libexec/apache2/libphp5.so
 
Then start apache and hopefully you'll see the build date was from today (or yesterday) depending on when you compiled it.

Let me know if that fixes it.
#50
Eric Gibb says:
July 22, 2009 at 01:47 pm
:/ I copied that file, but I'm still getting an early build date.... looking in usr/libexec/apache2/ i see that libphp5.so was created/opened/modified today, but my php -info output looks like this:
 
Build Date => Feb  5 2009 21:17:28
Configure Command =>  '/SourceCache/apache_mod_php/apache_mod_php-44.2/php/configure'  '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-dependency-tracking' '--with-apxs2=/usr/sbin/apxs' '--with-ldap=/usr' '--with-kerberos=/usr' '--enable-cli' '--with-zlib-dir=/usr' '--enable-trans-sid' '--with-xml' '--enable-exif' '--enable-ftp' '--enable-mbstring' '--enable-mbregex' '--enable-dbx' '--enable-sockets' '--with-iodbc=/usr' '--with-curl=/usr' '--with-config-file-path=/etc' '--sysconfdir=/private/etc' '--with-mysql-sock=/var/mysql' '--with-mysqli=/usr/bin/mysql_config' '--with-mysql=/usr' '--with-openssl' '--with-xmlrpc' '--with-xsl=/usr' '--without-pear'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
additional .ini files parsed => (none)
PHP API => 20041225
PHP Extension => 20060613
Zend Extension => 220060519
Debug Build => no
Thread Safety => disabled
Zend Memory Manager => enabled
IPv6 Support => enabled
Registered PHP Streams => php, file, data, http, ftp, compress.zlib, https, ftps  
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters => string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, convert.iconv.*, zlib.*
 
do i have to specify a different php.ini?
#51
July 22, 2009 at 02:09 pm
@Eric Gibb,

I might have given you the wrong directory to put it in. Sorry about that:

try it in: /usr/local/apache2/modules/libphp5.so

Now restart web sharing again and see if the new one comes up. If it doesn't check your httpd.conf to see where it's looking for your .so files.

I believe there might be a extension_dir or something like that, and if not specified it defaults to the current apache dir.

Hope that helps..
#56
yvan says:
August 1, 2009 at 10:19 am
In php-5.3.0 make && make install fails with mysql-5.1.36. ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [libs/libphp5.bundle] Error 1 Any advice ? Cheers, _y
#57
yvan says:
August 1, 2009 at 10:39 am
Hello Kevin. (sorry about my previous comment, please ignore). Now I managed to build php-5.3.0 but I skipped the virtual hosts part. I wanna use http://192.168.0.102/~username to access to Sites but I have a 403 Forbidden error when pointing to it. Thanks for your help and for your great tutorial ! Cheers, _yvan
#58
droid says:
August 29, 2009 at 07:04 pm
chmod 777 /usr/local/apache2/conf !!!
chmod 777 /private/etc/hosts !!!

That is a security risk! Make sure you change the permissions back once you are done editing, otherwise any user can rewrite or delete them. It wouldn't surprise me if it caused permission issues with Apache or PHP either.

A safer & more sensible way is to:

sudo pico file-to-be-edited & use the pico text editor or use a decent text editor that can handle files with restrictive permisions such as TextMate or BBEdit, then open the files from the command line…

eg mate /etc/hosts or bbedit /etc/hosts

you'll be prompted for an admin password to save them.

Thanks for the write up, I plan to modify it to install PHP 5.2.10 on Snow Leopard because PHP 5.3 breaks Drupal.

#60
September 3, 2009 at 06:42 pm
@droid, You're absolutely correct. This tutorial wasn't meant for a production ready server, but rather just a local install to use for development. I just set it to 777's so a more novice user wouldn't be caught up in any permission issues. I'm sure somebody will find your comment useful. :)
#68
marc says:
October 19, 2009 at 06:35 pm
Hello Kevin Everything worked perfectly but when compiling php5, I got the same errors than Luke (http://pastebin.ca/1495951) Do you know what's happening? Can I disable some module in the ./configure file to make it work? Thanks
#69
October 20, 2009 at 05:10 pm
@Marc, Did you try Luke's adjusted config statement to see if it worked?

One thing I'd reccommend would be to start with more of a bare config and keep adding an option until you find the troublesome command.

I looked at the pastbin but it seems it expired. I'm happy to help you out further if you need it, just let me know what you've done and where you're stuck.

Thanks.

-Kevin
#70
Marc says:
October 20, 2009 at 06:10 pm
Hi Kevin I cannot try it today, but if you want to take a look at the pastebin, there's a copy in google's cache: http://209.85.229.132/search?q=cache:Wvldin89aHIJ:https://ja.pastebin.ca/1495951+pastebin.ca/1495951&cd=2&hl=es&ct=clnk Those are exactly the same errors that I got, something related to the DNS (?) Thanks for your reply marc
#123
Davide Ganz says:
April 28, 2010 at 05:17 am
Thanks Kevin, one Note is that don't need... the last line of php_install.php: --with-mysql=/usr/local/mysql-5.1.35-osx10.5-x86 In my case I had to Erase that line to succeed in Installing 5.3.2...
#124
May 1, 2010 at 07:40 pm
Thank you for this excellent guide, Kevin. How different would it be to do it on a Mac OS X Server 10.5.8?
#148
Hristo says:
June 14, 2010 at 07:41 pm
Can you please make one of these for Snow Leopard? Snow Leopard has been known for causing troubles for simple installations and even worse with a 64-bit system... would you be able to make a Snow Leopard version of this tutorial... I'm specifically interested in MySQL 5.1.47, PHP 5.3.2, and Apache 2.2.15
#149
June 14, 2010 at 07:52 pm
@Hristo, I will put together a guide for Snow Leopard, I just have to upgrade one of my machines and time has been tight lately... I'll let you know once I get around to it.
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.