macOS Sierra ships with PHP 5.6, OSX 10.11 El Capitan with PHP 5.5.x and OSX 10.8 Mountain Lion ships with PHP version 5.3, there is an easy upgrade method to the stable version 5.6 or an older stable PHP version or even the latest PHP version 7.2.
PHP versions 5.5 and older are now considered end of life.
With the new macOS High Sierra it already comes shipped with PHP7.1.
The latest PHP version in this guide is from this PHP Packaged site which is being maintained for macOS and is known as a reliable source.
Download and Install PHP 7.0, 7.1 or 7.2
Open Terminal and run…
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
or for 7.1
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
or for 7.1
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.2
You get a warning error for if the php is a newer version
The version is filed in /usr/local/php5 – Test the php version by creating a php file named phpinfo.php in your web root with the single function:
Browse to that file and see the version displayed.
If instead you just want to just update to the latest 5.6 PHP…
Open the Terminal and issue one command –
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6
That’s it! One line command in the terminal, this will download and install PHP5.6 in:
For either PHP version install 7.2, 7.1 or 5.6 etc, the install script will also disable the previous PHP5.5 if it was enabled in the Apache configuration file /etc/apache2/httpd.conf . The new version is enabled in Apache right off the bat, the new install will comment out the older PHP module.
#LoadModule php5_module libexec/apache2/libphp5.so
It will load the new PHP version via the /etc/apache2/other/+php-osx.conf file.
So to reverse the behaviour uncomment the older PHP module in httpd.conf and remove the new config in other.