Morpheus
Morpheus

Reputation: 997

Updating php version on mac

I want to update php version, currently I have 5.5.38 and I want 7.1

What I tried so far is using this command:

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1

I tried several different versions but none of them worked. It opens bash_profile for a second and then I get Received SIGHUP or SIGTERM and message below:

Buffer written to /Users/Morpheus/.bash_profile.save.6

Not sure what went wrong and why it won't update...

Any ideas?

Thanks.

Upvotes: 54

Views: 159811

Answers (12)

KKSINGLA
KKSINGLA

Reputation: 1344

brew install [email protected]

brew link --overwrite --force [email protected]

For Mac remember this is the last step & don't forget to kill & restart the terminal

echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc

Upvotes: 1

Mark
Mark

Reputation: 18184

The solutions above did not work for me on Big Sur I kept on getting:

WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies

To fix this I used the following steps:

Step 1 | Tap into another repository of formulae

brew tap shivammathur/php

Step 2 | Install the desired PHP version

brew install shivammathur/php/[email protected]

Other options are:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected] 
[email protected] or known as just PHP

Step 3 | Link the PHP Version

brew link --overwrite --force [email protected]

Step 4 | Restart Terminal

Step 5 | Check PHP version

php -v

You should now see the new version.

PHP 7.4.25 (cli) (built: Oct 21 2021 00:29:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies

This also solved my issues with PHP syntax in Visual Studio Code.

Upvotes: 16

Cristea
Cristea

Reputation: 1077

For me none of the mentioned worked. So to upgrade from [email protected] to [email protected] I had to install

brew update
brew install [email protected]
export PATH=/usr/local/php7.4/bin:$PATH

Then force overwrite as following:

brew link --overwrite --force [email protected]

then

php -v 

output: PHP 7.4.24

Upvotes: 9

Surfo
Surfo

Reputation: 1

Im running Mac OS 10.13.8 and this worked all the way to PHP version 7.3

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3.8-20190811-205217

Upvotes: 0

Joel Ambu
Joel Ambu

Reputation: 115

Try to use below command

brew update 
brew upgrade php

or

brew reinstall php

Upvotes: 4

Đặng Quốc Anh
Đặng Quốc Anh

Reputation: 99

Try to use below command

brew update
brew install php@72

If it shows below error,

"Error: No available formula with the name "php"

try

brew install [email protected]

Upvotes: 5

Duy Nguyen
Duy Nguyen

Reputation: 364

In case you guys run all install commands above but when checking the PHP version, it is still linking to the old version. So you guys may want to update the PATH.

In my case, I open the .bash_profile which located in HOME directory by command:

nano ~/.bash_profile

Then, I add the path to the new version of PHP:

PATH=/usr/local/Cellar/php/7.4.4/bin:<other_paths>

Finally, run source ~/.bash_profile command to refresh the terminal window and checking the PHP version again.

Hope this helps.

Upvotes: 3

Viktor
Viktor

Reputation: 722

Use Homebrew:

I would probably recommend installing homebrew to manage such installations for you. With that installed you can just run the following command to install php7.1

brew update
brew install php@71

Upvotes: 43

Prashant Barve
Prashant Barve

Reputation: 4315

The simplest way to update the version of php on Mac is via Homebrew.

If you do not have brew please visit https://brew.sh/ or install via command in terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

When finished installing Homebrew, run the following commands:

brew update && brew upgrade
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew unlink php@56  
brew install php@71

You might get an error if PHP 5.6 has not been installed by brew previously, but don't worry, you can simply continue.

You can also change the version to 7.0 by replacing the command from above commands from brew install php@71 to brew install php@70.

You can check the output by command.

php -v

If the output of php -v still doesn’t echoes the version 7, simply type this command and hit enter in terminal.

export PATH=/usr/local/php5/bin:$PATH

Upvotes: 38

Sajjad Aljileezi
Sajjad Aljileezi

Reputation: 794

try to use the command, its working fine with me

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3

Upvotes: 3

matinict
matinict

Reputation: 2490

Install php

brew install [email protected]

Install the required PHP to your PATH

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

Then make sure it's all working

php -v
php --version

This command will show you where your ini file is loaded

php --ini

Upvotes: 92

gzchen
gzchen

Reputation: 62

You can brew upgrade php7 or brew uninstall old php version.

Last, I recommend you brew install php-version, php-version can help you change your php version

Upvotes: 2

Related Questions