Upgrade Your PHP

Anyone who is writing PHP code, should be using an modern version of PHP. Today, that means 7.0 or higher. As of today — 2017 Jul 30 — here are the active PHP versions. PHP 5.6 is in the security fixes only phase. PHP 7.0 and 7.1 are actively supported. PHP 7.2 is being developed, and will probably be released 2017 Nov 30, if not sooner. Look at php.net to check the latest version of PHP.

Before we get started, let’s check the version of PHP you have installed.

$ php --version

If this command returns 7.0. or higher, you don’t have to continue. But you should, so keep reading!

Are you an OS X user? Do you just want a standard PHP install? Would you like to avoid compiling PHP? You’re in luck!

Upgrading your PHP version is easy. You just need to type a few things on the command line.

On the command line type:

$ which brew

This tells you if the homebrew application is currently installed. If you see a path like /usr/local/bin/brew you’re good. If nothing returns, you’ll need to install it. To install homebrew, follow their directions. Then come back here.

It may have been a while since you last used homebrew. Maybe not. Either way, it’s good to make sure your version of homebrew is up to date. To update it, type the following:

$ brew update

This will update your version of homebrew, and the packages that are currently installed.

Depending on how many packages need to be updated, this could take several minutes. This is the longest part of the process, which isn’t that long.

To install PHP 7.0

$ brew install php70

To install PHP 7.1

$ brew install php71

It’s worth pointing out, that you don’t have to pick just one. you can install multiple version of php. There’s a great program homebrew provides — brew-php-switcher — that you can use to swap out the current version of PHP

If you were running PHP 7.1, you can easily switch to 7.0 instead. You might use this to ensure your project — like a WordPress plugin — works with multiple PHP versions. Maybe you’re creating a project for a client, or a friend, who is running an older version of PHP. The closer you can match their system, the better. Whatever the reason, the switcher makes it simple.

To do this, check if the switcher is installed

$ which brew-php-switcher

If you see a path, it’s installed. If it’s not installed, run this command:

$ brew install brew-php-switcher

Now to switch the version, just run this:

$ brew-php-switcher php70

Now you know how to upgrade your PHP version. Take a few minutes, to set your next project up for success.

Sorry, but comments are closed. I hope you enjoyed the article