how to upgrade php in mac OSX | compiling from source

Mac OSX  come with pre-installed php  , but many time you will find that its old version or you want to upgrade for your project specific needs then use this guide to download and install most up to date php in your mac OSX

Test your php installation 
open terminal and type

php --version

you will see something like this

or if you will check with phpinfo function you will see your php installation info

phpinfo 

Tested on mac OSX snow leopard and mountain lion ( intel )


Prerequisite knowledge and software for compiling php : 

  • Basic Unix skills (being able to operate “make” and a C compiler)
  • An ANSI C compiler
  • A web server
  • Any module specific components (such as GD, PDF libs, etc.)

Install XCODE and XCODE command lines tools before start compiling

Steps : 
1:  Download PHP source codes 
2 : extract source code 
3 : open terminal and change directory to extracted folder 
4: complie with


install dependencies first 

  • brew install libjpeg
  • brew install pcre
  • brew install libxml2
  • brew install mcrypt
  • brew install openssl 
  • brew install libpng 

now customise and configure php installation according to your need

./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
--with-iodbc=/usr
--with-ldap=/usr
--with-ldap-sasl=/usr
--with-libedit=/usr
--enable-mbstring
--enable-mbregex
--with-mysql=mysqlnd
--with-mysqli=mysqlnd
--without-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

Now test and install if all is good

  • make test 
  • sudo make install

after installation again type

php --version
  if above method dont work for you use
  http://php-osx.liip.ch/

Settting up php mysql and apache on mac osx see this guide >>