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
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:
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)"
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.
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.
What does it say for your build date on your phpInfo page? Also what is your config command according to your phpinfo page?
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
Let me know if that fixes it.
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..
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/hostsorbbedit /etc/hostsyou'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.
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
Leave a Comment