Installing PHP 5.4+ From Source on Mac OSX Mountain Lion

Download and extract the PHP source from php.net, for me that was 5.4.14. Put it somewhere friendly, the desktop will do.

Open a terminal and install some dependancies via brew:

1
2
3
4
brew install libjpeg
brew install pcre
brew install libxml2
brew install mcrypt

Download and install ICU from http://site.icu-project.org/download/48#ICU4C-Download

1
2
3
4
5
tar xzvf icu4c-4_8_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
make
sudo make install

Rebuild IMAP, download source from ftp://ftp.cac.washington.edu/imap/

1
2
3
4
make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
sudo cp c-client/*.h /usr/local/include/
sudo cp c-client/*.c /usr/local/lib/
sudo cp c-client/c-client.a /usr/local/lib/libc-client.a

Then in the PHP source folder you downloaded:

1
2
cd ~/Desktop/php/ext/imap
phpize

Now run configure (I installed with pear):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
./configure  \
--prefix=/usr  \
--mandir=/usr/share/man  \
--infodir=/usr/share/info  \
--sysconfdir=/private/etc  \
--with-apxs2=/usr/sbin/apxs  \
--enable-cli  \
--with-config-file-path=/etc  \
--with-libxml-dir=/usr  \
--with-openssl=/usr  \
--with-kerberos=/usr  \
--with-zlib=/usr  \
--enable-bcmath  \
--with-bz2=/usr  \
--enable-calendar  \
--with-curl=/usr  \
--enable-dba  \
--enable-exif  \
--enable-ftp  \
--with-gd  \
--enable-gd-native-ttf  \
--with-icu-dir=/usr/local  \
--with-iodbc=/usr  \
--with-ldap=/usr  \
--with-ldap-sasl=/usr  \
--with-libedit=/usr  \
--enable-mbstring  \
--enable-mbregex  \
--with-mysql=mysqlnd  \
--with-mysqli=mysqlnd  \
--with-pear  \
--with-pdo-mysql=mysqlnd  \
--with-mysql-sock=/var/mysql/mysql.sock  \
--with-readline=/usr  \
--enable-shmop  \
--with-snmp=/usr  \
--enable-soap  \
--enable-sockets  \
--enable-sysvmsg  \
--enable-sysvsem  \
--enable-sysvshm  \
--with-tidy  \
--enable-wddx  \
--with-xmlrpc  \
--with-iconv-dir=/usr  \
--with-xsl=/usr  \
--enable-zip  \
--with-imap=/usr/local/imap-2007 \
--with-kerberos \
--with-imap-ssl \
--enable-intl \
--with-pcre-regex  \
--with-pgsql=/usr  \
--with-pdo-pgsql=/usr \
--with-freetype-dir=/usr/X11 \
--with-jpeg-dir=/usr  \
--with-png-dir=/usr/X11

If you want to check for errors in the build step you can run:

1
make test

This might take a while, like 30 mins.

If you’re feeling bold, or once the test has completed, run:

1
sudo make install

Done!

PS If you’re getting strange errors during configure make sure you have these libraries:

1
2
3
brew install libpng
brew install freetype
brew install openssl

Change install path

The notes above install in the default /usr folder. If you want to install in /opt instead (which is often cleaner), add this to the configure script:

1
--prefix=/opt/php-5.4.14

Here’s a cutdown configure script I just used to install 5.4.15

1
'./configure'  '--prefix=/opt/php-5.4.15' '--with-libxml-dir=/usr' '--with-openssl=/usr' '--with-zlib=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--with-curl=/usr' '--enable-dba' '--enable-exif' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-mbregex' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pear' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/mysql/mysql.sock' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--with-xmlrpc' '--with-iconv-dir=/usr' '--with-xsl=/usr' '--enable-zip' '--enable-intl' '--with-pcre-regex' '--with-pgsql=/usr' '--with-pdo-pgsql=/usr' '--with-freetype-dir=/usr/X11' '--with-jpeg-dir=/usr' '--with-png-dir=/usr/X11' '--with-apxs2=/usr/sbin/apxs'
php

Comments