How to use the php that brew installed?
You have to make your Apache use the PHP that you just downloaded.
Open your
httpd.conf
(mine is at/etc/apache2/httpd.conf
) and look for the line that loads the PHP module, something like:LoadModule php5_module path/to/php
Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.
/usr/local/Cellar/php54/5.4.21/libexec/apache2/libphp5.so
Finally you will need to restart your Apache server to load the new configuration:
sudo apachectl restart
Installing PHP using Homebrew on MAC
Update
In February 2018, the php72
formula (the current version of PHP at that time) has been moved into the core Homebrew tap and renamed as php
.
The homebrew/php
tap has been deprecated in January 2018 and then archived on March 31, 2018. The formulas it contained are not available any more.
Since February 2018, installing PHP using Homebrew is as easy as:
$ brew install php
The older PHP versions that are still maintained can be installed using the new @
convention for versions (PHP 7.1 is php@7.1
).
The original answer (not usable any more)
The PHP ecosystem lives in the homebrew/php
tap. You can find there six versions of the interpreter (from 5.3
to 7.1
), extensions for them and some PHP-related tools.
In order to install PHP you have to install the homebrew/php
tap first (this is needed only once):
$ brew tap homebrew/php
$ brew install php70
Or you can do both operations in a single step by running:
$ brew install homebrew/php/php70
You could discover all these by searching php
first:
$ brew search php
Where does homebrew install PHP on Mac High Sierra?
EDIT:
As of 2018 and the latest updates to Brew your php formula names have the following format php@7.2
.
When you run brew info php@7.2
your path should be /usr/local/Cellar/php@7.2/
And there will be a symbolic link to /usr/local/bin/opt/php@7.2/
So in order to change your php installation you just need to run this in terminal:
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile
or put it manually in your .bash_profile
like this:
export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/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"
How to install PHP 7.2 on macOS Big Sur using Homebrew?
Since PHP 7.2 is not supported anymore, it's got delisted from the Hombrew core repository.
You've to find a third-party repository that still contains an older PHP version, such as the shivammathur/php
repository.
You need to tap the repository like this in your Homebrew:
brew tap shivammathur/php
Then you can install PHP 7.2 like this:
brew install shivammathur/php/php@7.2
You can find more information around the above tap and available versions on its GitHub repository.
Brew on MacOs for PhP version
Homebrew is normally installed in /usr/local
(or if you're using an M1 Mac, /opt/homebrew
).
Try running /usr/local/bin/brew
or /opt/homebrew/bin/brew
. If neither of those work, there was most likely a failure during the installation of Homebrew. What was the output you got when you ran the install command?
How can I easily switch between PHP versions on Mac OSX?
If you have both versions of PHP installed, you can switch between versions using the link
and unlink
brew
commands.
For example, to switch between PHP 7.4 and PHP 7.3
brew unlink php@7.4
brew link php@7.3
PS: both versions of PHP have be installed for these commands to work.
Related Topics
Shortcomings of MySQL_Real_Escape_String
Insert Query on Page Load, Inserts Twice
How to Convert Many Statement MySQL to Laravel Eloquent
Create a Folder If It Doesn't Already Exist
Upstream Sent Too Big Header While Reading Response Header from Upstream
Add a Custom Attribute to a Laravel/Eloquent Model on Load
Path of Assets in CSS Files in Symfony 2
What Is Causing "Unable to Allocate Memory For Pool" in PHP
Warning: Cannot Modify Header Information - Headers Already Sent by Error
PHP Mkdir: Permission Denied Problem
How to Get Current Route in Symfony 2
PHP Post_Max_Size Overrides Upload_Max_Filesize
How to Get Last Key in an Array
When to Use Strtr VS Str_Replace
How to Sort a Multidimensional Array by One of the Fields of the Inner Array in PHP