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
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.
Can't install PHP using Homebrew on macOS
Posting the answer from https://githubmemory.com/repo/Homebrew/homebrew-core/issues/77629 in case it gets deleted/removed.
Your core tap is missing. Do:
rm -rf $(brew --repo homebrew/core)
brew tap homebrew/core
brew update
All due credits to the original poster. :)
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
Update PHP to 7.4 macOS Catalina with brew
try:
brew update
brew upgrade php
php -v
brew services start php
or
brew services restart php
if you use apache server:
sudo apachectl restart
if you use ngnix
sudo nginx -s reload
Edit:
brew unlink php@7.3
brew link php@7.4
Homebrew: How install disabled package(php7.1)?
Start by making sure brew is up-to-date:
brew update
Normal upgrade
brew upgrade PHP
Normal upgrade does not work in many macOS old Versions.
Upgrade with shivammathur/homebrew-php
brew tap shivammathur/php
brew install shivammathur/php/php@7.1
To switch between versions, use the following command:
brew link --overwrite --force php@7.1
Next steps
Check the current version by running php -v
:
If you can then, Restart Nginx or Apache
also:
refer Link
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?
Related Topics
Update Data on a Page Without Refreshing
Cron Job to Delete Files Created Before a Specific Time
General Error: 1364 Field 'User_Id' Doesn't Have a Default Value
Regex for No More Than 5 Digits or Contain String
How to Count Columns With the Same Value in a Specific Row in MySQL
How to Echo Selected Value of Dropdown in PHP
Php Warning: Mysqli_Connect(): (Hy000/2002): Connection Refused
How to Add a Space Between Every Sequence of Four Characters (Like a Credit Card Number)
Passing an Array to a Query Using a Where Clause
How to Show Checkboxes as Checked When Values Are Set in the Database in Laravel
How to Run a PHP Script in the Background After a Form Is Submitted
What Is the Default Username and Password of Phpmyadmin
How to Stop PHP Code Execution
Removing Specific Elements from Json Encoded Array by Use of PHP
Curl (7): Failed to Connect to Localhost Port 8000: Connection Refused
Can PHP Pdo Statements Accept the Table or Column Name as Parameter