Upgrade to PHP 5.6 or 7 on Mac OSX 10.11 El Capitan and OSX 10.6 – 10.10

by Admin


Posted on August 24, 2014 at 9:00 PM

Tags : : MacOsX PHP


OSX 10.11 El Capitan ships with PHP 5.5.x and OSX 10.8 Mountain Lion ships with PHP version 5.3, there is an easy upgrade method to either the newer stable version 5.6 or an older stable PHP version or even the latest PHP version 7.

OSX 10.11 El Capitan ships with PHP 5.5.x and OSX 10.8 Mountain Lion ships with PHP version 5.3, there is an easy upgrade method to either the newer stable version 5.6 or an older stable PHP version or even the latest PHP version 7.

The latest PHP version in this guide is from this PHP Packaged site  which is being maintained for OSX and is known as a reliable source.

Download and Install PHP 5.6

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:

/usr/local/php5/

The install script will also disable the previous PHP5.5 if it was enabled in the Apache configuration file httpd.conf . The new 5.6 version is enabled in Apache right off the bat.

 

Download and Upgrade to PHP 7.0

Open Terminal and run…

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

You get a warning error for El Capitan

Detected OS X El Capitan 10.11. As this is quite new, there may be issues still. Your mileage may vary.

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.

php7-osx

 

So as mentioned earlier by installing a different version than the one OSX is shipped with, the new install will comment out the PHP module inside the apache web config in /etc/apache2/httpd.conf

#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.

As noted in my posts on Installing Apache, PHP and MySQL on Mac OS X, OS X comes pre-installed with Apache and PHP. Unfortunately, as of Mac OS X 10.11 (El Capitan) the pre-installed version of PHP is still 5.5.

As PHP 5.5 has reached end of life, I imagine the pre-installed version of PHP will be updated with Mac OS 10.12 (Sierra). However, it may only be PHP 5.6.

So what do you do if you want to upgrade or install a different PHP version on your Mac? Well, you could use Homebrew. But I found a pre-packaged alternative - PHP OSX.

PHP OSX is a package installer for PHP versions 5.3 to 7.1 (current). It’s available for Mac OS 10.6+ (Snow Leopard to El Capitan). While installing PHP OSX is just a few steps, I will walk you through them to add this post to my others.

Installing PHP

First, choose the version of PHP you want to install. In this example, I will install PHP 7 as that is the latest stable version of PHP.

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0

If you are not comfortable executing scripts from the Internet, you can do the install by hand.

Configuring Apache

Provided you are using the pre-installed version of Apache, PHP OSX will automatically configure Apache to use the new PHP module.

Otherwise, you will need to configure Apache to load the newly installed PHP module.

LoadModule php5_module /usr/local/php5/libphp5.so

Updating your PATH

While Apache will now run the new version of PHP, the command line will not. In order for the command line to use the new version of PHP you will need to update your PATH.

export PATH=/usr/local/php5/bin:$PATH

If you don’t want to run the command above every time you open a new command line, you can update the PATH in your .bash_profile.

vi ~/.bash_profile

Configuring PHP

Finally, you will want to update some of the PHP configuration values. PHP OSX installs a PHP INI file for you to change. To edit this file, run:

sudo vi /usr/local/php5/php.d/99-liip-developer.ini

If you kept all of your local PHP configuration within a single INI file (as I did), you can simply append it to the PHP OSX file with:

sudo cat /Library/Server/Web/Config/php/local.ini >> /usr/local/php5/php.d/99-liip-developer.ini

That’s it! Now you’ll just need to review your PHP code to ensure it’s compatible with your newly installed PHP version. And for that, I recommend PHP Shift.

Find this interesting? Continue the conversation on Twitter or in a comment.

Find this helpful? Consider making a donation.

Need more? Let's team up!

Schedule 1-on-1 coaching or hire me for your project.


 

Courtesy: Unknown



Comments


You must be loged to add a comment !