Skip to content

Instantly share code, notes, and snippets.

@shashankmehta
Last active January 7, 2024 11:57
Show Gist options
  • Save shashankmehta/6ff13acd60f449eea6311cba4aae900a to your computer and use it in GitHub Desktop.
Save shashankmehta/6ff13acd60f449eea6311cba4aae900a to your computer and use it in GitHub Desktop.
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.+.

@dinigo
Copy link

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
Copy link

avil13 commented Apr 11, 2018

To add php of brew you can use the command

brew services start php

@deepkamal
Copy link

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
Copy link

brysem commented Jun 29, 2018

@deepkamal, You can use brew install [email protected].

@tekpriest
Copy link

tekpriest commented Nov 4, 2018

php is updated
to install php7.2
brew install [email protected]

@outbravedigital
Copy link

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

brew install mcrypt [email protected]

@ezequielalba
Copy link

ezequielalba commented Dec 4, 2019

brew install mcrypt [email protected]
brew services start [email protected]
brew link [email protected] --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 [email protected]
brew install composer

@abumalick
Copy link

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

@abumalick
Copy link

@adibpwd
Copy link

adibpwd commented Dec 5, 2021

i want to install laravel with composer, but i have error, could not found composer.json, why?
Screen Shot 2021-12-05 at 10 42 15
Screen Shot 2021-12-05 at 10 42 36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment