Install Apache2 and PHP5 with GD on Mac OS X
Many people (newbies and advanced users) don’t like the re-built version of Apache and PHP on Mac OS X 10.4 because of hundreds of raisons: PHP4 will not be continued anymore; A lot of Libraries and Modules were not installed on the re-built PHP 4.4, for example, GD image Library; The re-built Apache and PHP was not installed as default, so we can’t find the dictionaries and configurations facilely…
Well, anyone that has been wishing to switch Apache2 and PHP5 on your mac, that’s the time to do this:
Requirement and Environment:
- Mac OS X 10.4.10 Tiger
- Apache 2.2.6
- PHP 5.2.4
You must have a C compiler engine and gcc. That means you have to install Apple Xcode 2.4 (I don’t know if Xcode 2.3 runs well on Tiger, so 2.3 version is unrecommended ). You can download Apple Xcode 2.4 in Apple Developer Connection or find it in your Mac OS X DVD.
1. Download Apache2
First step, go to Apache’s offical website download Apache-2.2.6.tar.gz and unzip it ( Apache-2.2.6 is the highest version so far as known ).
2.Build and install Apache2
Open you Terminal and run the following line to build and install it.
% cd /the/path/you/uncompressed/httpd-2.2.6
% sudo ./configure \
% --prefix=/usr/local/apache2 \
% --enable-module=most \
% --enable-shared=max
% sudo make
% sudo make install
3.Building and installing PHP5 for Apache2
—- 3.1 Downloading PHP5
Go to The official website of PHP and download the last version of PHP (php-5.2.4 currently is the last version).
—- 3.2 Download libraries you want to enable ( optional but highly recommended, please read. ).
——– 3.2.1 Installing libjpeg and libpng
The official php documentation points out that GD library is completely in the php-5.2.4 package, and that’s right, but you cannot fully install GD support without libjpeg and libpng. You can also download and install the libjpeg and libpng by using binaries installer for Mac OS X, check here!
Double click the package you have downloaded (binaries package) to install. the libjpeg and libpng will be installed in “/usr/local/lib”
——– 3.2.2 installing and using fink (optional)
Some tutorials said that you can install libjepg and libpng by using fink, but as I know, there’s no libpng in fink’s libraries index, but you can use it to install some libraries useful , for example FreeType 2.
Download the Fink binary package and double click to install. Fink will be install in “/sw” dictionary.
Open your Terminal and type:
% sudo fink install libjpeg // libjpeg is what you want to install
—- 3.3 Building & Installing PHP5
Uncompress php-5.2.4.tar.gz. and type:
% cd /path/to/php-5.2.4/
% ./configure \
% --prefix=/usr/local/php5 \
% --with-zlib \
% --with-xml \
% --with-ldap=/usr \
% --enable-cli \
% --with-zlib-dir=/usr \
% --enable-exif \
% --enable-ftp \
% --enable-mbstring \
% --enable-mbregex \
% --enable-dbx \
% --enable-sockets \
% --with-iodbc=/usr \
% --with-curl=/usr \
% --with-mysql=/usr/local/mysql \ (optional, required MySQL)
% --with-gd \ (optional, requires jpeg + png)
% --with-jpeg-dir=/usr/local \ (optional)
% --with-png-dir=/usr/local \ (optional)
% --with-apxs2=/usr/local/apache2/bin/apxs
% sudo make
% sudo make install
4. Configuring Apache
—- 4.1 Add php5 module for apache
We just installed Apache2 in “/usr/local/Apache2″. So, open “/usr/local/Apache2/conf” and edit the file httpd.conf. Make sure to use a flat text editor like BBEdit or Pico in the command line. Add these lines to your httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
Save file httpd.conf. (type you password if necessary)
—-4.2 Testing apache and php
Use you text editor to create a *.php file named test.php with the code:
<?php
phpinfo();
?>
copy test.php file to “/usr/local/apache2/htdocs” dictionary and start apache server:
sudo /apache2/bin/apachectl start
to stop
sudo /apache2/bin/apachectl stop
OK, hoping every step goes well and this acticle can help you…








Hi! Thanks for the “how-to”, it worked perfect. I have just changed from Win to Mac and I’m having trouble getting xslt to work with my apache-installation. Do you think you could help me? I’m lost!
Best regards.
to jonas
Hi I’m really glad that my article can give you some help. I am just a newbie in Unix area and if you have any problem, just mail me webmaster@veola.net. hoping we can figure it out together.
Thanks for the post! I’ve been having trouble getting GD installed on my mac, so I thought I’d upgrade everything.
I get this hangup when running the ./config…etc for php5:
configure: error: Problem with libpng.(a|so) or libz.(a|so). Please check config.log for more information.
the last few lines in config.log say:
configure:35723: checking for png_write_image in -lpng
configure:35742: gcc -o conftest -g -O2 -no-cpp-precomp -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -lz conftest.c -lpng -ljpeg -lcurl -lz -lm -lxml2 -lz -liconv -lm -lcurl -lssl -lcrypto -lz -lxml2 -lz -liconv -lm 1>&5
/usr/bin/ld: /usr/local/lib/libpng.dylib load command 4 unknown cmd field
collect2: ld returned 1 exit status
configure: failed program was:
#line 35731 “configure”
#include “confdefs.h”
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char png_write_image();
int main() {
png_write_image()
; return 0; }
So it looks like the libpng is the root of the problem, but I used the installation package listed above. Any ideas or suggestions?
@nick
thank you very much for your reply. I think that you use a 64 bit machine makes this problem.
I’m really sorry I didn’t point out that the libpng and linjpeg binaries packages are for the 32 bit installation.
So, please try install them with terminal.
1.download libjpeg and libpng source package and uncompress them in /sourcecache folder (or other dictionary).
2.install them in your 64 bit mac
cd /SourceCache/jpeg-6bcp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
For 64-bit use:
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load" ./configure --enable-sharedand type this to install:
makemkdir -p /usr/local/include
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
mkdir -p /usr/local/man/man1
make install
and for libpng is the same way. but please pay attention, first of all, run “make clean” to clean your 32 bit installation.
thank you
Thanks for the extra instructions! Unfortunately I haven’t gotten it yet
Here goes my story:
started installing jpeg library, but got a “C compiler cannot create executables” when I ran the “MACOSX_DEPLOYMENT_TARGET=…”. So I REINSTALLED XCODE AND THE SAME ERROR CAME UP. UGH!
Anyway, I finally just tried building jpeg and png with “./configure –enable-shared –enable-static” and got them installed ok, I think. (with “make clean” - thanks)
Then I tried running the ./configure script again for PHP5 and I get a problem with MYSQL. From ./configure:
...
checking for mysql_close in -lmysqlclient... no
checking for mysql_error in -lmysqlclient... no
configure: error: mysql configure failed. Please check config.log for more information.
config.log:
configure:59413: checking for MySQL UNIX socket location
configure:59604: checking for mysql_close in -lmysqlclient
configure:59623: gcc -o conftest -I/usr/include -g -O2 -no-cpp-precomp -L/usr/local/mysql/lib -L/usr/local/mysql/lib -liconv -L/usr/lib -L/usr/local/lib -L/usr/local/lib conftest.c -lmysqlclient -lldap -llber -liconv -lpng -lz -ljpeg -lcurl -lz -lm -lxml2 -lz -liconv -lm -lcurl -lssl -lcrypto -lz -lxml2 -lz -liconv -lm 1>&5
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: Undefined symbols:
_mysql_close
collect2: ld returned 1 exit status
configure: failed program was:
#line 59612 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char mysql_close();
int main() {
mysql_close()
; return 0; }
configure:59846: checking for mysql_error in -lmysqlclient
configure:59865: gcc -o conftest -I/usr/include -g -O2 -no-cpp-precomp -L/usr/local/mysql/lib -L/usr/local/mysql/lib -liconv -L/usr/lib -L/usr/local/lib -L/usr/local/lib -L/usr -L/usr conftest.c -lmysqlclient -lz -lldap -llber -liconv -lpng -lz -ljpeg -lcurl -lz -lm -lxml2 -lz -liconv -lm -lcurl -lssl -lcrypto -lz -lxml2 -lz -liconv -lm 1>&5
/usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld: Undefined symbols:
_mysql_error
collect2: ld returned 1 exit status
configure: failed program was:
#line 59854 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char mysql_error();
int main() {
mysql_error()
; return 0; }
- hope all that helps
On some other forums, I’ve read things like “you need to get the mysql developer tools” or even “change your /sw folder if you have fink”. I also recompiled mysql from source.
-Any thoughts would help
Imagine czk4490 loop. Froogle has an abcba15c81 items checker.
i hope. abcba15c81 thanks
Hi great site, I just have two problems I need to ask for. The first one is when I’ve installed apache2, it still says that my version is 1.3.41 when I use “httpd -v”. I’ve tried to restart apache2 but then I get this:
dyld: Symbol not found: _XmlParseXmlDeclNS
Referenced from: /usr/local/apache2/lib/libexpat.0.dylib
Expected in: flat namespace
/usr/local/apache2/bin/apachectl: line 102: 26652 Trace/BPT trap $HTTPD -k $ARGV
My next problem is that when I try to install php5 I get an error which I think leads to that I can’t configure it later on. Haven’t find anyone else with that problem..
I would be grateful with any help
@Fredrik
1st question: It is normal that your Terminal said your version is 1.3.41, because the command httpd -v will ask the MAC’s rebuilt in apache. That’s OK, that will not make any issues for apahe2. for why you cannot restart apache, the error is what terminal tell you right? can you provide the apache2’s error log please?
2nd: could you tell me what error you got please?