Compiling PHP on Mac OS X
Getting Started
You may want to recompile PHP on your Mac for a number reasons such as need a newer version, missing some features you need, testing, or whatever. Some of the most common reasons I found were people needing GD support because the version of PHP that comes with Mac OS X doesn't have it. In this I'll let you know what you need and how to get it done.
Apache
We'll need to recompile Apache even though it already comes with our system because for some unknown reason (to me) the compiled version of Apache that comes with our systems doesn't play too well when we compile PHP. Anyways without going into further details, read through this article real quick, Compiling Apache on Mac OS X, and come back here. Should only take ya like 5 minutes...
Time for PHP
Welcome back! Next, download the latest copy of the PHP source (5.2.5 as of this writting) compressed in tar.gz format from this URL, http://www.php.net/downloads.php. Once complete and you don't care about compiling PHP with any other options such as GD Support, MySQL, etc, and you just want the basic PHP then you can go back to your Terminal, cd into the directory where you downloaded PHP and run the following commands:
$ tar -xvzf php-5.2.5.tar.gz
$ cd php-5.2.5
$ ./configure --enable-layout=Darwin --enable-mods-shared=all --prefix=/usr --mandir=/usr/share/man --localstatedir=/var --infodir=/usr/share/info --disable-dependency-tracking --with-apxs2=/usr/sbin/apxs --with-kerberos=/usr --enable-cli
$ make
$ sudo make install
Like Apache, you would need your root password to install PHP with the last command. Once everything is complete you can go into Sharing from your System Preferences and restart Web Sharing and you will notice you are running the version of PHP that you downloaded!
Note: Whenever editing your apache configuration you will need to restart it in order to see the new changes.
If you do want to build PHP with additional features then proceed below and follow the setup of instructions for each and either feature. For starters we can unpack PHP.
$ tar -xvzf php-5.2.5.tar.gz
Later when I say to build PHP with whatever ./configure command I just mean running the command from your Terminal while being in the directory where you unpacked PHP.
GD Support?
I won't leave you hanging wondering how to install GD since I brought it up earlier and its quite easy so lets do it! If you want jpeg support with GD then you need to install libjpeg. You can download the latest stable source code from http://www.ijg.org/files/. Once you get it go back to your terminal and run the following commands:
$ tar -zxvf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ cp /usr/share/libtool/config.sub .
$ cp /usr/share/libtool/config.guess .
$ env CFLAGS="-O -g -arch i386 -arch ppc" LDFLAGS="-arch i386 -arch ppc" ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --enable-shared --enable-static
$ make
$ sudo make install
$ sudo ranlib /usr/local/lib/libjpeg.a
That's that for libjpeg. Now if you also want png support we need to grab libpng from http://www.libpng.org/pub/png/libpng.html. When done, lets go back into our terminal and run the following commands:
$ tar -xvzf libpng-1.2.22.tar.gz
$ cd libpng-1.2.22
$ env CFLAGS="-O -g -arch i386 -arch ppc" LDFLAGS="-arch i386 -arch ppc" ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --disable-dependency-tracking
$ make
$ sudo make install
$ sudo ranlib /usr/local/lib/libpng.a
Alright all set! Now we just have to go back to PHP and configure it with the options for GD. Below is the command:
$ ./configure --enable-layout=Darwin --enable-mods-shared=all --prefix=/usr --mandir=/usr/share/man --localstatedir=/var --infodir=/usr/share/info --disable-dependency-tracking --with-apxs2=/usr/sbin/apxs --with-kerberos=/usr --enable-cli --with-jpeg-dir=/usr/local/bin --with-png-dir=/usr/local/bin --with-gd
All I added were the last 3 options. If you didn't add libjpeg or libpng then you can remove them from the options respectively. After done configuring just remember to make and make install and your done!
MySQL
What PHP build would be complete without MySQL support? This step is super easy, simply go to http://www.mysql.com and download the latest stable version (5.0.45 as of this writing) for your platform and install it. The installation will place the files in a mysql directory in /usr/local. You can see which directory it was installed in by running the following command:
$ ls -lah /usr/local | grep mysql
Now that you've got the MySQL installation directory its helpful to create an alias directory without the version number at the end that will point to your current working version. This is also helpful so you can install multiple versions of software and when you want to switch between them you could simply change where the alias points to. If your MySQL directory was installed to /usr/local/mysql-5.0.45-osx10.4-i686 then this would be your command to create an alias:
$ sudo ln -s /usr/local/mysql-5.0.45-osx10.4-i686 /usr/local/mysql
Also, if you would like to access MySQL from the command line without having to type the full path to the binaries each them then I'd recommend appending your MySQL path to your $PATH environment variable:
$ echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.profile
The above line appends MySQL to your $PATH environment variable and from here on every Terminal window you open will find its way to MySQL.
Continuing on with PHP, depending which MySQL support you want (MySQL, MySQLi, PDO, or all) then just pick out whatever you want and don't want from the line below:
--with-mysql-sock=/var/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql
Conclusion
There are many more options you can add to the configure script to set certain features. To view all the options available you can run ./configure --help and that will spit out just about all the ways you can configure your build. Below is the configure command I used:
$ ./configure --enable-layout=Darwin --enable-mods-shared=all --prefix=/usr --mandir=/usr/share/man --localstatedir=/var --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/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-xmlrpc --with-xsl=/usr --with-pdo-mysql=/usr/local/mysql --enable-soap --with-pear --with-jpeg-dir=/usr/local/bin
--with-png-dir=/usr/local/bin --with-gd
Its also important to note that when doing system updates, not just little security updates or other application updates, but big critical system updates that brings you from something like 10.5.0 to 10.5.1 might rid your Apache and/or PHP setup. Nothing bad will happen, they will just overwrite your setup with their update. If you happened to keep your build then you can just go back and run sudo make install or you can just download the latest versions of the software we used here and redo the steps.
April 19th, 2008 at 6:36 pm
Hi Richard, first Thanks for the how to most excellent. I am having a problem with the mysql though.
checking for MySQL support for PDO… yes
checking for mysql_config… /usr/local/mysql/bin/mysql_config
checking for mysql_query in -lmysqlclient… no
checking for mysql_query in -lmysqlclient… (cached) no
configure: error: PDO_MYSQL configure failed. Please check config.log for more information.
This is the end of config.log :
configure:71760: gcc -o conftest -I/usr/include -g -O2 -no-cpp-precomp -Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib -liconv $
ld: warning in /usr/local/mysql/lib/libmysqlclient.dylib, file is not of required architecture
Undefined symbols:
“_mysql_query”, referenced from:
_main in ccypYIpb.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
configure: failed program was:
#line 71749 “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_query();
mysql version is: mysql-5.0.51a-osx10.5-x86_64
Also I had to change sudo ranlib /usr/local/lib/libjpeg.a to sudo ranlib /usr/lib/libjpeg.a
and sudo ranlib /usr/local/lib/libpng.a to sudo ranlib /usr/lib/libpng.a
I would be very grateful if you could help me get pdo_msql working.
kind regards,
lee.
April 19th, 2008 at 6:57 pm
Hi again, I fixed the pdo problem by uninstalling the 64 bit version of mysql and installing a 32bit version.
I haven’t tested it yet but it all complied ok and phpinfo reports the gd and pdo_mysql.
Thanks again.
lee.
April 25th, 2008 at 6:19 pm
Thanks very much for this write up. I tried in vain to change the directory that apache would be placed into to
/usr/local/apache2
I did this by using different layouts and by trying to change the –prefix=/path/to/where/I/wanted/It
Each time I did this, it compiled as expected, but I could not get it to talk with php. I gave up after several attempts. After all I wanted my server up and the directory location is not that important.
One thing with your location I see as a disadvantage though, is that the server process *is* controlled by the GUI Sharing Control Panel. Is there a command line way of changing the “on” to “off” and back again?
Again,
Thanks.
Dan LaSota
April 28th, 2008 at 5:43 pm
Re: Dan LaSota
Since you changed the build location of your Apache Webserver then you must specify the appropriate location of apxs when building PHP which in your case should be somewhere in /usr/local/apache2.
You can also restart Apache from the command line, you don’t have to use the Sharing applet in your System Preferences. To do so please read apachectl(8).
Thanks for reading and stay tuned for more soon
Regards,
Richard Sumilang
April 29th, 2008 at 12:36 pm
Fantastic - I was pulling my hair out trying to get this going a few days ago - now I’m up and running. Thanks for taking the time to document this.
Do you have any ideas on how to get a full 64bit Apache/PHP/mySQL stack running on 10.5?
Regards,
Tony.
May 10th, 2008 at 10:19 am
Orthopedic Wrist Braces…
I found your site on technorati and read a few of your other posts. Keep up the good work. I just added your RSS feed to my Google News Reader. Looking forward to reading more from you….
May 11th, 2008 at 8:47 am
anybody here know of a good site to find more info on Local Mysql Server Through Usr? I’ve got this site bookmarked and im gonna keep checking it out, but i still would like to find a site that covers Local Mysql Server Through Usr a little more thoroughly..thanks
May 29th, 2008 at 11:01 am
Hopefully not a dumb question - do I have to build PHP first, then add the jpeg/gif libraries and recompile, as you have above, or can I build the libraries first, then just build PHP once at the end? Thanks!
May 29th, 2008 at 11:36 am
Hi Matt,
Sorry for the confusion. You only have to build PHP once which would be at the end after you install the other libraries you want it to support. The sub-sections under PHP just show you what to do if you want GD/MySQL support along with what to add to your configure command for the PHP build. I guess it could be a little confusing so I think I’ll reorder the article to make more sense later tonight.
Thanks for your post!
Regards,
Richard Sumilang
June 1st, 2008 at 9:32 pm
I couldn’t understand some parts of this article Compiling PHP on Mac OS X, but I guess I just need to check some more resources regarding this, because it sounds interesting.
June 9th, 2008 at 12:20 pm
Thanks for the great article.
I am running into problems with the jpeg and png.
It goves me an error after the make install , and of course when I
sudo ranlib /usr/local/lib/libjpeg.a
It tells me it can not find it ..
Do you have any idea why this could be happening?
June 10th, 2008 at 11:36 am
Hi. First thank you very much for this. Second, I have a problem and I hope you can help me please!
I want to install Oracle Client 10g on Mac OS X 10.5.2 and have the php recompiled to talk to it (via oci). To start with, I have system installed Apache and php enabled and working. If I put a phpinfo page in my website, it renders correct.
I followed your tutorials on compiling Apache and PHP (5.2.6, cause I could not find the 5.2.5!). To your php configure parameters, I just added –with-oci8=/Applications/Oracle/ohome
The php and httpd folders which I have downloaded and unzipped and run the command over, are in Library. Now, the http://localhost in Safari gives back “can’t connect to the server”.
Any suggestions please?
And what if I also want to add the PEAR to the configuration please?
Thank you very much for your time and support.
PS: I have set all the Oracle Client installation variables already.
June 16th, 2008 at 6:13 am
I have successfully installed php 5.2.6 on OS X 10.5.2 with the followinf options :
LDFLAGS=’-arch x86_64′ ./configure \
…
–with-mysql=/usr/local/mysql \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
…
June 24th, 2008 at 3:05 pm
I’ve tried this again. I’m up to this command
sudo ranlib /usr/local/lib/libpng.a
and I’m receiving this error
ranlib: can’t open file: /usr/local/lib/libpng.a (No such file or directory)
I’m installing libpnt-1.2.29. This seems to be the most current version.
Thanks for all the help.
July 2nd, 2008 at 3:09 pm
For those whose libpng.a and libjpeg.a aren’t in /usr/local/lib, try instead sudo ranlib /usr/lib/libjpeg.a and sudo ranlib /usr/lib/libpng.a
July 9th, 2008 at 2:05 pm
car spurs…
buy car spurs online…
July 27th, 2008 at 3:46 pm
Your site- http://www.richard-sumilang.com is cool resource, thanks, webmaster. But see this [url=http://tudkoay4.netfirms.com/index.html] ipod nana problem [/url]
Good buy.
July 29th, 2008 at 6:46 pm
Your site- http://www.richard-sumilang.com is interesting site, respect, admin.
August 13th, 2008 at 12:52 pm
Richard, many thanks for your description. I was pulling my hair out with a bug in the Entropy.ch PHP build. Finally uninstalled it and followed your guidelines. It worked immediately. Terrific. And I have no the confidence that I have a solid, maintenable install. Thanks again !
August 17th, 2008 at 8:07 pm
Your blog is interesting!
Keep up the good work!
August 26th, 2008 at 1:53 am
Cool blog
Thanks, webmaster.
August 26th, 2008 at 2:35 am
Nice site
Thanks, webmaster.
August 26th, 2008 at 5:00 am
Amazine site
Thanks, webmaster.
August 26th, 2008 at 5:41 am
Beautifull design
Thanks, webmaster.
August 26th, 2008 at 12:18 pm
Amazine site
Thanks, webmaster.
August 27th, 2008 at 9:51 am
Nice site.
Thanks, webmaster.
August 27th, 2008 at 10:24 am
Amazing site.
Thanks, webmaster.
August 30th, 2008 at 9:07 am
read up on the acai berry\’s orac value http://acaiberrydiet.iinetwork.net Thanks ACAI NUT
December 30th, 2008 at 8:41 am
everest poker…
everest poker…
December 30th, 2008 at 9:43 am
code cd poker…
code cd poker…
December 30th, 2008 at 10:43 am
spiel kostenlos blackjack online…
spiel kostenlos blackjack online…
December 30th, 2008 at 11:43 am
casinos en france…
casinos en france…
December 30th, 2008 at 12:43 pm
internet craps…
internet craps…
December 30th, 2008 at 1:44 pm
online casino bonus…
online casino bonus…
December 30th, 2008 at 2:43 pm
slots spillemaskiner spil…
slots spillemaskiner spil…
December 30th, 2008 at 3:40 pm
gratis roulette…
gratis roulette…
December 30th, 2008 at 4:37 pm
online casino bonus…
online casino bonus…
December 30th, 2008 at 5:34 pm
online casino bonus…
online casino bonus…
January 1st, 2009 at 6:51 pm
map…
Take things easier ! :)…
January 1st, 2009 at 6:55 pm
map…
Do it by yourself! Take a chance!…
January 1st, 2009 at 11:46 pm
map…
Whats the problem? I cant see any problem….
January 2nd, 2009 at 10:27 am
map…
Nowadays its not rare :/…
January 2nd, 2009 at 11:41 pm
map…
I cant see the case Explain yourself plz….
January 3rd, 2009 at 5:54 am
map…
Im not an expert, too. But look who’s talking….
January 3rd, 2009 at 3:17 pm
map…
Big Brother is watching ;)…
January 3rd, 2009 at 9:25 pm
map…
I cant help, but good luck!…
January 4th, 2009 at 2:10 am
map…
Never give up! Keep on trying! :D…
January 4th, 2009 at 4:48 am
map…
Whos over here? 8-)…
January 4th, 2009 at 9:40 am
map…
Its very serious. Try to read books on the topic….
January 5th, 2009 at 3:35 am
بروكر…
بروكر…
January 5th, 2009 at 4:57 am
spielautomaten…
spielautomaten…
January 5th, 2009 at 6:06 am
telecharger everest poker…
telecharger everest poker…