I'll try to make it as simple and fast as i can, to help you out with this awkward installation procedure
There is always the MAMP Solution (http://mamp.info), which i know it's pretty cool, but a former linux guy like me can't compromise, plus, current version of MAMP (up to today at least) doesn't include PHP 5.3.0, which i really needed to install, in order to start porting my huge web projects. The basic PHP 5.3.0 features/changes i wanted to work with were namespaces and some deprecated functions (of course there are others, but too minor to even mention). Installin by compiling the source was one-way solution for me, and it reminded me of back in the day i was always tweaking my linux box.
Note: I cheated: I installed a binary version of MySQL because of the neat auto-start features and the "System Preferences" PrefPane. You can find MySQL in this address: http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg Of course, if you want, you can always switch to source distribution and proceed with a simple configure, make, make install (configure options are up to you)
So, i started by downloading the source code for Apache and PHP. First things first: Apache web server
You can download the source code in the following url: http://httpd.apache.org/download.cgi . The file you downloaded looks something like httpd-2.2.14.tar.bz2 so you'd probably want to untar it by using in the Terminal
bzip2 -cd httpd-2.2.14.tar.bz2 | tar x
After that, you enter the dir, and start configuring by using the following command:
./configure --prefix=/usr/local --enable-mods-shared=all --enable-cache --enable-mem-cache --enable-mime-magic --enable-headers --enable-ssl --enable-dav --enable-suexec --enable-vhost-alias --enable-rewrite --enable-so --with-sslport=443
The configure options are up to you and you can edit/add more by using
./configure --help
After the configure process is done, we can run
make
make install
Now we have apache installed into /usr/local so we can start the server by running
/usr/local/bin/apachectl -k start
Same procedure for PHP. Download PHP 5.3.0 using this address http://www.php.net/downloads.php#v5 and select the "Complete Source Code" section. You'll probably end
up with an archive that looks like php-5.3.0.tar.bz2
Untar it, enter the directory and DO NOTHING! That's because you can't just run configure by using a simple configure command. Let me be more specific on that:
PHP need some libraries. Example if you want to configure it using the --with-readline option (if your scripts need the readline library), or if you do extensive use of XML like me, you can't just configure it without installing the libraries. Linux users have the priviledge of downloading, installing etc. Mac users on the other hand, have to use the MacPorts tool (http://www.macports.org).
Download and install MacPorts by using the dmg provided. MacPorts is installed into /opt/local so in terminal you can run the command
/opt/local/bin/port search libxml2
The program outputs results that are based on your search (here, is libxml2), you pick the title that matches your needs and you run
/opt/local/bin/port install libxml2
Now that you have installed all the libraries you need, you can run the configure command by using this (of course you can add/remove options you like/don't like). IMPORTANT: You must include the --with-config-file-path directive beacuse otherwise you won't be able to use php.ini, Be careful on the paths that are related to apache (apache, apxs):
./configure --prefix=/usr/local --with-apxs2=/usr/local/bin/apxs --with-config-file-path=/usr/local/lib --with-bz2 --with-zlib=/opt/local --enable-ftp --with-gd --enable-gd-native-ttf --with-mcrypt --with-mysql --with-readline=/opt/local --enable-soap --enable-zip --enable-bcmath --enable-calendar --enable-exif --enable-magic-quotes --enable-mbstring --enable-sockets --enable-wddx --enable-zend-multibyte --with-jpeg-dir=/usr/X11R6 --with-png-dir=/usr/X11R6 --with-pdo-mysql=/usr/local/mysql --with-curl=/opt/local --enable-mbregex --with-libxml-dir=/opt/local --with-gettext=/opt/local --with-iconv-dir=/opt/local --with-freetype-dir=/usr/X11R6
The jpeg, freetype and png libraries that came with your mac, are not only compatible, but it's recommended to use them, that's why in some of the options above are using the /usr/X11R6 path.
If you've correctly installed by using MacPorts all the libraries you need the configure process ends normally and you'll se the "Creating files" section
If you run make now, you'll probably get the following error (If not, WOW! you can proceed :D ):
Undefined symbols for architecture i386:
"_xmlTextReaderSchemaValidate", referenced from:
_zim_xmlreader_setSchema in php_xmlreader.o
"_xmlTextReaderSetup", referenced from:
_zim_xmlreader_XML in php_xmlreader.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Undefined symbols for architecture x86_64:
"_xmlTextReaderSchemaValidate", referenced from:
_zim_xmlreader_setSchema in php_xmlreader.o
"_xmlTextReaderSetup", referenced from:
_zim_xmlreader_XML in php_xmlreader.o
ld: symbol(s) not found for architecture x86_64
It may seem weird and difficult to cure, but it's not actually. The makefile generated by the configure process contains some wrong variables and all you have to do is open it, go straight to line that contains the following line:
MH_BUNDLE_FLAGS = -bundle -bundle_loader /usr/sbin/httpd -L/usr/lib\
-L/usr/lib -laprutil-1 -lsqlite3 -lexpat -liconv -L/usr/lib -lapr-1 -lpthread
Delete the duplicate -L/usr/lib nd before every occurence of the -L/usr/lib add -L/opt/local/lib as described in this blog post: http://blog.yimingliu.com/2009/02/24/missing-library-symbols-while-compiling-php-528/
so you'll end up with something that looks like that:
MH_BUNDLE_FLAGS = -bundle -bundle_loader /usr/sbin/httpd -L/opt/local/lib \
-L/usr/lib -laprutil-1 -lsqlite3 -lexpat -liconv -L/opt/local/lib -L/usr/lib -lapr-1 -lpthread
You are now ready to hit make again. If another error occures, it means you messed up this line. Be sure to have as many -L/opt/local/lib occurences as -L/usr/lib. You can also add two occurences of -L/usr/local/lib
At this point, make should give you a clean, fresh build of PHP 5.3.0. You may now make install and start tweaking your httpd.conf located in /usr/local/conf
You must add the line
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
And also tweak the DirectoryIndex by adding index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
If you now try to restart (or start) apache for the first time. you'll probably face another error that has to do with some undefined symbol "_iconv" or something related to libiconv.2.dylib
This is the second fix you have to take care: You open up envvars file inside the apache bin directory. (In our case: /usr/local/bin/envvars) and tweak this line
DYLD_LIBRARY_PATH="/usr/local/lib:/usr/lib:$DYLD_LIBRARY_PATH"
To look something like that, which includes your macports libraries
DYLD_LIBRARY_PATH="/opt/local/lib:/usr/local/lib:/usr/lib:$DYLD_LIBRARY_PATH"
There you go! You are now ready to start your apache web server (/usr/local/bin/apachectl -k start) and work on your PHP 5.3.0 projects.
Have fun!