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


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


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

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