OS X comes prepackaged with PHP but it is normally a little behind the latest stable. Mavericks has 5.4.17, Yosemite 5.5.9, El Capitan 5.5.29 and Sierra 5.6.24, but with PHP 7.0 out that is often not good enough.

There are multiple ways to install PHP on OS X.

Install PHP via Homebrew

Homebrew is a powerful package manager for OS X, which can help you install PHP and various extensions easily. Homebrew PHP is a repository that contains PHP-related “formulae” for Homebrew, and will let you install PHP.

At this point, you can install php53php54php55php56 or php70 using the brew install command, and switch between them by modifying your PATH variable. Alternatively you can use brew-php-switcher which will switch automatically for you.

Install PHP via Macports

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the OS X operating system.

MacPorts supports pre-compiled binaries, so you don’t need to recompile every dependencies from the source tarball files, it saves your life if you don’t have any package installed on your system.

At this point, you can install php54php55php56 or php70 using the port install command, for example:

sudo port install php56

sudo port install php70

And you can run select command to switch your active php:

sudo port select --set php php70

Source: http://www.phptherightway.com/