How to remove preinstalled Apache and PHP from Mac OS Sierra

Solution 1:

Removing system macOS binaries is not a good idea, they will be reinstalled during a next system upgrade and they could be needed by some system scripts.

To enable the homebrew php from the command line, read the output of brew info php70:

If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file: export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"

If you have installed php 7.2, check the output of brew info php72.

Solution 2:

I've tried this

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

and it works, php -v is showing me the correct version, see https://php-osx.liip.ch/#faq

!!! Note that you need to add export PATH=/usr/local/php5/bin:$PATH to your ~/.bash_profile file in order to have this change permanent, otherwise it will go away on first reboot and you'll have to run this command every time you reboot.

Solution 3:

Export your PATH with some like this (check your php version):

export PATH=/usr/local/Cellar/php71/7.1.14_25/bin:$PATH

Solution 4:

Expanding on the answer of @Lokni, to use the php version of 'whatever homebrew installed' instead of /usr/bin/php, I added this as the first line of my ~/.bash_profile (or ~/.zprofile on some macs):

export PATH="$(brew --prefix php)/bin:$PATH"

In my case, brew --prefix php returns

/usr/local/opt/php

So now, if I open new terminal and type which php it says

/usr/local/opt/php/bin/php