Where does homebrew install PHP on Mac High Sierra?
Asked Answered
F

3

6

I'm using Mac High Sierra. I installed PHP (with GMP) using

brew install php72-gmp

Everything installed successfully, per the messages given, but it would seem I still have an old version of PHP 7.1 somewhere on my machine because when I run

localhost:php-7.2.1 davea$ which php
/usr/bin/php
localhost:php-7.2.1 davea$ /usr/bin/php -v
PHP 7.1.7 (cli) (built: Jul 15 2017 18:08:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

So I'd like to figure out where to put the homebrew version of PHP ahead in my PATH so that that version gets picked up first.

Fireplug answered 2/2, 2018 at 15:11 Comment(0)
T
19

EDIT:

As of 2018 and the latest updates to Brew your php formula names have the following format [email protected].

When you run brew info [email protected] your path should be /usr/local/Cellar/[email protected]/

And there will be a symbolic link to /usr/local/bin/opt/[email protected]/

So in order to change your php installation you just need to run this in terminal:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile

or put it manually in your .bash_profile like this:

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

===========================================================================

The location of your Homebrew installed php should be /usr/local/Cellar/php72

These are the steps you need to do to setup your PHP on macOS:

After you install php with brew run this in terminal:

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

Then run:

source ~/.bash_profile

To check your current active version of php run this in terminal:

which php

EDIT:

run brew info php72 in console to get all info, hints and caveats for php, it is really useful, for example this comes from brew info:

✩✩✩✩ PHP CLI ✩✩✩✩

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"
Texture answered 5/2, 2018 at 19:17 Comment(0)
F
1

As you are familiar with linux, homebrew has its own /opt and /etc path

# > echo $(brew --prefix)
# /opt/homebrew

so the paths are (for Apple Silicon):

/opt/homebrew/opt
/opt/homebrew/etc

in linux, php is installed in /etc/php/7.4

in mac homebrew, php is installed in /opt/homebrew/etc/php/7.4.

Please find the homebrew document on the default installation path for Apple Silicon 1

ref 2

Faretheewell answered 26/7, 2022 at 6:43 Comment(0)
R
0

Check if you have two php directories in '/usr/bin/' or '/usr/local/bin/'. If yes do a link to the good directory. See this link, may be it helps you.

Rhododendron answered 2/2, 2018 at 15:18 Comment(2)
I have a "/usr/bin/php" executable but in /usr/local/bin I only have "/usr/local/bin/php-cgi", "/usr/local/bin/php-config," "/usr/local/bin/phpdbg," and "/usr/local/bin/phpize."Fireplug
I have installed brew and « homebrew/php/php72 ». « php -v » return « 5.6 ». You have just to open a new version of terminal. Otherwise, check your PATH with echo « $PATH ». Have you « /usr/local/bin » ? Check « /usr/local/Cellar ». Have you a php72 directory ?Rhododendron

© 2022 - 2024 — McMap. All rights reserved.