To install PHP on Mac OS X there are, just as with Apache, several options one could use. I’ve chosen the most simple setup that will get most PHP based applications running that we need for the mailserver and such.
You can start by downloading the latest source archive from www.php.net. Extract the source archive into a directory and use the Terminal to execute the following commands. Please note the difference when having an Intel or PowerPC based Mac:
For Intel on Tiger:
./configure --prefix=/usr/local/php5 \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-zlib \
--with-zlib-dir=/usr \
--with-openssl \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
For PowerPC on Tiger:
./configure --prefix=/usr/local/php5 \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-zlib \
--with-zlib-dir=/usr \
--with-openssl \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
For both CPU types on Leopard:
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc \
--with-zlib \
--with-zlib-dir=/usr \
--with-openssl \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-mbregex \
--enable-sockets \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2/bin/apxs
For all:
sudo make install
If the install fails because of a PEAR error like:
[PEAR] Console_Getopt: upgrade to a newer version (1.2 is not newer than 1.2)
warning: pear/PEAR dependency package “pear/Archive_Tar” installed version 1.1 is not the recommended version 1.3.1
[PEAR] PEAR: commit failed
You’ll need to upgrade the PEAR package on your machine. Save the script at http://pear.php.net/go-pear to your desktop as go-pear.php and execute ’sudo php go-pear.php’. Just answer the questions when needed, most can be answered by just pressing the enter button. The most important one is to change the installation prefix from ‘/usr‘ to ‘/usr/local/php5‘ and that is it. Try to rerun the ’sudo make install’ in the PHP source directory and it should work.
After installation, please check if the your ‘httpd.conf’ has been updated for the PHP extension and if the module is being loaded. Your ‘httpd.conf’ file should have the following lines:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Restart Apache and your ready to go.
As you might have seen from the ‘./configure‘ settings, your ‘php.ini‘ file will be located in ‘/etc‘.
Next step: Installing the Mailserver



12:02 am
after the install, there is no php.ini file located in the /etc directory. Do I have to copy this from the source directory?
9:43 am
I am also having the same problem. There is no php.ini file in the /etc directory. When i created the classic phpinfo.php file and placed it in the web root directory - Configuration File (php.ini) Path is given as “/usr/local/php5/lib/php.ini” but there is no php.ini file there too.
very worried. did i screw my box.
regards
11:01 am
No real problem, just copy the php.ini from the source directory in that location.
8:29 pm
i added the classic to the webserver root and i got Configuration File (php.ini) Path = /usr/local/php5/lib but the Configure Command gives –sysconfdir=/etc.
upon placing the php.ini file in /usr/local/php5/lib and making some changes it reflected.
so why cant it read the php.ini file i placed in /etc where its suppose to be.
regards
3:01 am
I’m getting this error when I run make:
make: *** [ext/libxml/libxml.lo] Error 1
also higher up:
/usr/include/stdarg.h:4:25: error: no include path in which to search for stdarg.h
3:32 am
I’m trying to install PEAR and I’m getting a very weird error:
I’ve done several Google searches trying to figure out why this is failing, but I’m coming up short. Any ideas?
5:31 am
My problems couldn’t be corrected. I ended up re-installing both my subsystem and Developer Tools. Then following these instructions worked for me. If you run out of options, that is probably the best thing to do.
3:09 pm
There still is a problem with pear. I’d install it but it says this:
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Console_Getopt - already installed: 1.2.2
[PEAR] Archive_Tar - already installed: 1.3.2
[PEAR] Structures_Graph- already installed: 1.0.2
[PEAR] PEAR - already installed: 1.5.3
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
what should I do now?
3:24 pm
Looks good to me ? Just add the line `/usr/local/php5/lib/php` to your php.ini and you’ll be fine.
4:31 pm
But there ain’t no php.ini… Or where can I find this? What should I edit?
5:46 pm
If you get a CFLAGS error, be sure you’re in the bash shell and not tcsh (and have the latest XCODE installed)
9:26 pm
FWIW - this page should mention that the install will fail if you have not installed MySQL from source as per the “compiling mysql” page: http://diymacserver.com/installing-mysql/compiling-mysql/
4:55 pm
Good news; I was finally able to install PEAR, but to do so I had to install via the website.
When I tried to run it via the directions here, I kept getting the following:
—–
PHP Fatal error: Call to undefined method PEAR_Error::set() in /Users/vbush/Desktop/Server_Software/go-pear.php on line 783
—–
I put the go-pear.php file into a temporary directory on my website, and ran the installer via the web (I already had .php files set up as cgi scripts). By temporarily giving full write access to /usr/local/php5, /usr/local/php5/bin, and /usr/local/php/temp, everything worked perfectly when it didn’t from the command line. So I’m guessing the problem was really something to do with access privileges, although that makes little sense as I ran it as sudo.
Of course, you must set privileges back as they were for the three directories listed.
2:54 am
Ok, I have spent the past few hours trawling google search results and reading through various blogs and the such to discover the solution to my problem. I’ll be quite frank here, I am a noob when it comes to compiling applications. I suppose I fit nicly into the catagory of ‘Do what Im told by the guide’.
That said I have followed your instructions thus far without incident. I have MySQL installed, secured and running, the same with Apache 2 (a first for me under OS X). My issue is with php, as you may have guessed. When I run the config command; “CFLAGS=”-arch i686 -isysroot /Developer/SDKs/MacOSX10.4u.sdk” ./configure….(shortened for sake of space)” I get the following error;
checking whether the C compiler (gcc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk ) works… no
configure: error: installation or configuration problem: C compiler cannot create executables.
I am pretty much stuck now so any help would be welcomed
3:19 pm
Really nice guide
I have make my owns script for install apache / mysql & php (i will share this stuff when it will be fixed).
Sadly the PHP configuration is minimal here.
For exemple soap & gd are a must have ^^
I have atm some issue with the libpng etc… to compile php with gd, if anyone have some docs about, this would be nice
10:21 pm
if you follow this guide using the Leopard apache layout, the path to apxs is slightly different that posted here. the correct configure syntax should read:
–with-apxs2=/usr/sbin/apxs
at the end, instead of:
–with-apxs2=/usr/local/apache2/bin/apxs
best regards
10:25 pm
You are correct, but that wasn’t the purpose of this install document.
8:11 pm
So I’m having an odd error when I try to ./configure. The last few lines of the ./configure output are:
—————————-
checking for MySQL support… yes
checking for specified location of the MySQL UNIX socket… no
checking for MySQL UNIX socket location… no
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.
—————————-
I look at the config.log file and here are the last few entries:
—————————–
configure:59313: checking for MySQL support
configure:59360: checking for specified location of the MySQL UNIX socket
configure:59418: checking for MySQL UNIX socket location
configure:59609: checking for mysql_close in -lmysqlclient
configure:59628: gcc -o conftest -I/usr/include -g -O2 -no-cpp-precomp -Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib -liconv -L/usr/lib conftest.c -lmysqlclient -liconv -liconv -lssl -lcrypto -lz -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm 1>&5
ld: warning in /usr/local/mysql/lib/libmysqlclient.dylib, file is not of required architecture
Undefined symbols:
“_mysql_close”, referenced from:
_main in ccQ1BPTe.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
configure: failed program was:
#line 59617 “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:59851: checking for mysql_error in -lmysqlclient
configure:59870: gcc -o conftest -I/usr/include -g -O2 -no-cpp-precomp -Wl,-rpath,/usr/local/mysql/lib -L/usr/local/mysql/lib -liconv -L/usr/lib -Wl,-rpath,/usr -L/usr conftest.c -lmysqlclient -lz -liconv -liconv -lssl -lcrypto -lz -lssl -lcrypto -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm 1>&5
ld: warning in /usr/local/mysql/lib/libmysqlclient.dylib, file is not of required architecture
Undefined symbols:
“_mysql_error”, referenced from:
_main in ccdjjJ0Z.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
configure: failed program was:
#line 59859 “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; }
—————————–
I compiled and installed MySQL exactly per the instructions, with the exception that I used the current version 5.0.51b (there is no installer package from MySQL.com for 5.045 and I thought it unwise to install 5.0.45 from source over a 5.0.51b install…)
It appears the problem is with the file /usr/local/mysql/lib/libmysqlclient.dylib but I don’t know how that is.
Any suggestions?
FYI: Configuration: Mac Mini running 10.5.4 brand new install
11:14 am
Jeff installed the 64 bit version of MySQL on a 32 bit Mac. He re-installed the 32 bit and it all works again…
1:17 am
I am hoping I can impose again for an install question:
I am not all that familiar with make, so I want to ask what I might encounter before I end up with untraceable errors (that is, by me
):
I installed PHP per these instructions (and a bit of extra help, thank you!) and all is working fine.
Now I’m trying to re-compile and install, adding a few extensions, first is GD.
I’ve successfully compiled and installed the GD requirements (jpglib, pnglib) and recompiled PHP with those included (–with-gd –with-jpg-dir=/usr/local/php5 –with-png-dir=/usr/local/php5)
Now I’m ready to “make install”.
I am concerned that the installer won’t copy all the files over the existing ones (it’s the same version of everything other than the ./configure parameters). And if not, then I won’t see the behavior change I want.
Is there a way to make sure that everything gets copied over and installed with the new compile?
Thank you!!
12:41 pm
Just do a “sudo make install” and it will overwrite the previous version.
12:07 pm
“Just do a “sudo make install” and it will overwrite the previous version.”
It’s not working out this way for me.
I’ve recompiled/installed several times and while I still have PHP 5.2.6 (the version I downloaded), the build date is several months ago and the configuration changes I’ve made are not taking.
In frustration, I deleted my /usr/local/php5 directory.
Nothing changed.
I really need to get some control over this so I can load the extensions (Soap) I need for a project I’ve been assigned.
Any tips?
8:46 pm
I got it.
Re-compiled/installed MySQL 5.0.45, re-compiled/installed PHP 5.2.6.
httpd.conf was looking for the libphp5.so file in the wrong place.
Updated the path and voila, perfection!
Thanks Richard!
6:28 am
how do I configure php to support imap?
8:42 pm
That is more difficult than it looks but I’m working on it….
1:38 pm
I had a problem linking iconv. I have iconv installed with Fink in /sw. PHP would only compile for me if I added the following to ./configure:
–with-iconv=shared,/sw
See: http://www.keeny.co.uk/2008/11/iconv-will-not-link-when-compiling-php.html
2:27 am
Hi, I got this error message when configuring PHP 5.2.8 on Mac OS X 10.4.11 (Intel):
configure: error: Cannot find OpenSSL’s
It seems I need to compile OpenSSL from source, right?