Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup PHP and Composer on OSX via Brew

First install Brew on your MAC

  • Setup Brew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • brew update
  • brew tap homebrew/dupes
  • brew tap homebrew/php
  • Install PHP 7.0.+ brew install php70
  • Install mcrypt: brew install mcrypt php70-mcrypt
  • Finally, install composer: brew install composer

Now if you run $ php -v, you will get PHP 5.5 or something. This is the default PHP version that is shipped with OSX and cannot be removed. You just need to edit your path to ensure that PHP 7.0 is picked up.

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

To debug any issue with any package, you can run brew info php70 etc.

Also, if you are getting seemingly unrelated errors, make sure to update bash/zsh: brew upgrade bash and brew upgrade zsh.

If everything is setup correctly, running $ php -v should give you 7.0.+.

@Tjarko-Holtjer

This comment has been minimized.

Copy link

@Tjarko-Holtjer Tjarko-Holtjer commented Dec 23, 2017

I think brew upgrade is useful between brew update & brew tap homebrew/dupes.

@Tjarko-Holtjer

This comment has been minimized.

Copy link

@Tjarko-Holtjer Tjarko-Holtjer commented Dec 23, 2017

TjarkoPetras-iMac:appy tenp$ brew tap homebrew/dupes
Warning: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.

@Tjarko-Holtjer

This comment has been minimized.

Copy link

@Tjarko-Holtjer Tjarko-Holtjer commented Dec 23, 2017

TjarkoPetras-iMac:appy tenp$ brew unlink php71
Unlinking /usr/local/Cellar/php71/7.1.12_23... 17 symlinks removed

Then brew install php72

to upgrade

@Tjarko-Holtjer

This comment has been minimized.

Copy link

@Tjarko-Holtjer Tjarko-Holtjer commented Dec 23, 2017

git -C "$(brew --repo homebrew/core)" fetch --unshallow

Download more from homebrew / mac

@cristopher-rodrigues

This comment has been minimized.

Copy link

@cristopher-rodrigues cristopher-rodrigues commented Feb 23, 2018

It may be necessary configure git buffer: git config --global http.postBuffer 1048576000

@nulllpointer

This comment has been minimized.

Copy link

@nulllpointer nulllpointer commented Mar 6, 2018

Thank you man, it works perfectly.

@dinigo

This comment has been minimized.

Copy link

@dinigo dinigo commented Mar 8, 2018

macOS already has a working php installation, so only composer is needed

@dinigo

This comment has been minimized.

Copy link

@dinigo dinigo commented Mar 8, 2018

php comes preinstalled in macOS, so in my case it wasn't necessary. I will go with:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap homebrew/php
brew install composer
@avil13

This comment has been minimized.

Copy link

@avil13 avil13 commented Apr 11, 2018

To add php of brew you can use the command

brew services start php
@deepkamal

This comment has been minimized.

Copy link

@deepkamal deepkamal commented Jun 7, 2018

PHP is moved to homebrew/core ,
brew tap homebrew/php gives this error
Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.

instead do brew tap homebrew/core

@brysem

This comment has been minimized.

Copy link

@brysem brysem commented Jun 29, 2018

@deepkamal, You can use brew install php@7.0.

@en1tan

This comment has been minimized.

Copy link

@en1tan en1tan commented Nov 4, 2018

php is updated
to install php7.2
brew install php@7.2

@duckonwater

This comment has been minimized.

Copy link

@duckonwater duckonwater commented Jan 3, 2019

For those unable to get mcrypt to install, try this:

brew install mcrypt php@7.2

@ezequielalba

This comment has been minimized.

Copy link

@ezequielalba ezequielalba commented Dec 4, 2019

brew install mcrypt php@7.2
brew services start php@7.2
brew link php@7.2 --force
php -v --> should give you 7.2 now on terminal if not, close session of term and open a new one (Restart)
brew install mcrypt php@7.2
brew install composer

@abumalick

This comment has been minimized.

Copy link

@abumalick abumalick commented Jul 30, 2020

Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.

@abumalick

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.