Macos – How to upgrade PHP on Mac OS X

macmacososx-snow-leopardPHP

So i did simple thing:

php -i | head
./configure --prefix=/usr --with-snmp
make
sudo make install

But phpinfo() still showing me 5.3.15. Here some results of investigations:

  • PHP_BINDIR = /usr/bin
  • phpversion() = 5.3.15
  • 192-168-0-100:$ /usr/bin/php -v
    PHP 5.4.8 (cli) (built: Nov 8 2012 09:30:58)
  • 192-168-0-100:$ /usr/local/bin/php -v
    PHP 5.4.8 (cli) (built: Nov 7 2012 22:09:56)
  • 192-168-0-100:$ which php
    /usr/bin/php

Also tried plying with different ln -s. May be some suggestions?

P.S.
php is working fine on localhost, but it is still 5.3 (tried some new features from php 5.4)

Best Answer

Instead of building yourself and potentially wreaking havoc in your /bin directory—this might kill your original PHP installation—do yourself a favor and use prebuilt installations like those below.


MAMP

MAMP currently ships with PHP 5.2 and 5.4.4. It'll run standalone and you can switch anytime.

MAMP is installed in the typical Mac fashion: very easily. MAMP will not compromise any existing Apache installation already running with your OS X. You can install Apache, PHP and MySQL without starting a script or having to change any configuration files!

 

PHP Binary Packages

You can also try the PHP 5.3/5.4 for OS X as binary packages:

This package installs the (usually) latest PHP 5.3.x/5.4.x […] in /usr/local/php5. It installs many useful extensions […]. It also provides a decent php.ini with all settings configured according to "Best Practices".

For PHP 5.4, installation is as easy as running:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4
Related Question