How to update PHP version on Mac OS X

How to update PHP version on Mac OS X

This was written in 2018. Now, all the brew taps in this blog have been deprecated.

Image for postPhoto by Caspar Rubin on Unsplash

Using Homebrew

First, make sure that your homebrew is up to date

brew update && brew upgrade

If you didn?t have homebrew, install it right away!

Using Brew Tap command allows Homebrew to tap into another repository of formula.

brew tap homebrew/dupesThese formulae were those that duplicated software provided by macOS.

brew tap homebrew/versionsThese formulae provided multiple versions of existing packages or newer versions of packages that were too incompatible to go in homebrew/core.

brew tap homebrew/homebrew-phpA centralized repository for PHP-related brews.

Checking php version using the following commands

php -v(same as php –version)

To unlink the last version

brew unlink php<<php_version>>[depends on the current version on your computer]

For instance, your current php version is 5.5brew unlink php55

To install the new version of php

brew install php<<php_version>>[If you need another version just change the version number]

If you need php 7.1brew install php71

then check php version again

php -v

If everything looks fine then congratulation! you?ve finished the php updated.

But If you find the following errorsError:Could not symlink file: /urs/local/Cellar/php…

you need to run the following commands

sudo chown -R$(whoami) /usr/local/* brew list | while read f; do brew unlink f; brew link $f; done brew unlink php<<current_php_version>> brew link –overwrite php<<new_php_version>>

check php version again

php -v

linked to the old version?

So open you .profile or .bash_profile like nano or vim

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

Source your file with source ~/.bash_profile or source ~/.profile(same as close and reopen your terminal).

Using one line install

curl -s | bash -s <<php.version>>


No Responses

Write a response