Skip to content

Instantly share code, notes, and snippets.

@pixeline
Last active March 16, 2023 16:49
Show Gist options
  • Star 92 You must be signed in to star a gist
  • Fork 22 You must be signed in to fork a gist
  • Save pixeline/51c43c787f51b018d484597f30be3d2b to your computer and use it in GitHub Desktop.
Save pixeline/51c43c787f51b018d484597f30be3d2b to your computer and use it in GitHub Desktop.
Update Mac Os X's php version to php 7.1 using homebrew. Includes curl and mcrypt
# 1. Install brew --> http://brew.sh/
# 2. run the following commands in your Terminal
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install --with-openssl curl
brew install --with-homebrew-curl --with-apache php71
brew install php71-mcrypt php71-imagick
# 3. Follow these instructions to make Apache and php-cli use the newer php executable and make the change persist after reboot.
brew info php71
# restart apache
sudo apachectl restart
# apply PATH changes without relogging
source ~/.profile
@TechNinjaWeb
Copy link

This was the solution for me. Thanks for your help!

@wbswjc
Copy link

wbswjc commented Oct 25, 2017

@vaske Try add 127.0.0.1 vaske-mbp.local to /etc/hosts.

@Narven
Copy link

Narven commented Nov 3, 2017

brew tap homebrew/dupes deprecated

@Peneheals
Copy link

Peneheals commented Nov 15, 2017

If you are using AMPPS or any other solution not just pure Apache, and imagick or other php extensions are not important, just use this:

# 1. Install brew  --> http://brew.sh/
# 2. Run the following commands in your terminal
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew install --with-openssl curl
# 2.5 Don't forget to unlink your php 7.0
brew unlink php70
brew install --with-homebrew-curl php71
brew install php71-mcrypt
# 3. Follow these instructions to make php-cli use the newer php executable and make the change persist after reboot.
brew info php71
# apply PATH changes without relogging
source ~/.profile

@amrutjadhav
Copy link

Saved me lot of time. Thanx for this gist.

@COil
Copy link

COil commented Dec 2, 2017

Yeah thanks, I always forget the --with-apache stuff.

@alemol
Copy link

alemol commented Dec 11, 2017

In case of facing this warning:

$ brew install --with-homebrew-curl --with-apache php71
Warning: homebrew/php/php71 7.1.12_23 is already installed, it's just not linked.
You can use brew link php71 to link this version.

Then this error:

$ brew link php71
Linking /usr/local/Cellar/php71/7.1.12_23...
Error: Could not symlink sbin/php-fpm
/usr/local/sbin is not writable.

The solution is this:

$ sudo mkdir /usr/local/sbin
$ sudo chown -R whoami:admin /usr/local/sbin
$ brew link php71
Linking /usr/local/Cellar/php71/7.1.12_23... 17 symlinks created

@bnamnguyen
Copy link

thank you so much, it works great.

@latheva
Copy link

latheva commented Jan 25, 2018

Thanks, it helped me a lot.

@dib258
Copy link

dib258 commented Feb 12, 2018

I had to make some modification to make gist work ! :)

# 1. Install brew  --> http://brew.sh/
# 2. run the following commands in your Terminal
# brew tap homebrew/dupes
# brew tap homebrew/versions
# Thoses tap where merged into the homebrew/cores tap
brew tap homebrew/core
brew tap homebrew/homebrew-php
brew install --with-openssl curl
# Had to change from --with-apache to --with-httpd since apache command was deprecated
# Had a problem with zlib config error, I did this command and it fixed everything : xcode-select --install
brew install --with-homebrew-curl --with-httpd php71
brew install php71-mcrypt php71-imagick
# 3. Follow these instructions to make Apache and php-cli use the newer php executable and make the change persist after reboot.
brew info php71
# restart apache
sudo apachectl restart
# apply PATH changes without relogging
source ~/.profile

@varshaan0sharma
Copy link

brew install homebrew/php/php71-mcrypt worked for me

@marknt15
Copy link

At first I tried to make it work but there are errors and I thought of another way. The MAMP way.
Add this in you .bash_profile

export PATH=/Applications/MAMP/bin/php/php7.1.6/bin:$PATH

I will try the brew php71 way some other time

@huebs
Copy link

huebs commented Apr 2, 2018

I believe I just ran into a related issue:

If you're seeing this error when opening a new terminal:

Warning: Use php@7.1 instead of deprecated php71

Check your ~/.profile, ~/.bash_profile, or ~/.bashrc for a line that looks like this:

PATH="${PATH}:$(brew --prefix homebrew/core/php71)/bin"

And change it to this:

PATH="${PATH}:$(brew --prefix homebrew/core/php@7.1)/bin"

If you're seeing this error when opening a new terminal:

Warning: Use php@7.1 instead of deprecated homebrew/php/php71

Check your ~/.profile, ~/.bash_profile, or ~/.bashrc for a line that looks like this:

PATH="${PATH}:$(brew --prefix homebrew/php/php71)/bin"

And change it to this:

PATH="${PATH}:$(brew --prefix homebrew/core/php@7.1)/bin"

@ToniTonish
Copy link

Good afternoon,

i'm sorry if this isn't the correct section where report errors.
i got this when brew install --with-homebrew-curl php71
the error is Warning: php@7.1: this formula has no --with-homebrew-curl option so it will be ignored!

any advice on how to solve it? i need to change from SSL Version => SecureTransport to SSL Version => OpenSSL/1.0.2j

@heberfomin
Copy link

Hello Guys,
First of all, I'm sorry, I'm not an expert in linux environment, worst in MacOs so, if I made any stupid question, please forgive me.
I'm trying to install extension for MACOS php mcrypt. My environment is MacOs High Sierra with 7.1.1 php.
I've tryed this:
$ brew install php71-mcrypt php71-imagick

But I received these errors:
Error: No available formula with the name "php71-mcrypt"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

it seems that i'm trying to install something that doesn't exist anymore.

Does anybody knows how could I resolve this?

@artcoholic
Copy link

Hi Guys,

I have the same problem as heberfomin. Any help would be appreciated. Thank you!

@gotraveltoworld
Copy link

gotraveltoworld commented Apr 12, 2018

Good afternoon,

In fact, Homebrew/php is deprecated, so you can not use this command to install php71.

see: weprovide/valet-plus#127

Today, I also find this problem, I still search for solutions.

You could see origin information from this: https://github.com/Homebrew/homebrew-php

@aoberoi
Copy link

aoberoi commented Apr 13, 2018

thanks @huebs!

@bylatt
Copy link

bylatt commented Apr 13, 2018

@gotraveltoworld You can still install older version of PHP via homebrew by using php@{version} eg. php@7.1. For extensions I recommend pecl.

@EugenMayer
Copy link

@clozed2u problematic right now is xdebug though, but well, i do not need it.

@w0rd-driven
Copy link

Ran into the depreciation today and the recommendation is buried at the end of Homebrew/homebrew-core#26362, to use pecl.

My need is fortunately only for imagick and xdebug and it was relatively trivial to run pecl install package but it just jams the extensions into php.ini haphazardly which don't even point to the right location.

I was able to salvage the old files in /usr/local/etc/php/7.1/conf.d and for imagick the file is:

[imagick]
extension="/usr/local/Cellar/php@7.1/7.1.16_1/pecl/20160303/imagick.so"

Where the directory /usr/local/Cellar/php@7.1/7.1.16_1/pecl/20160303/ is not /usr/local/Cellar/php@7.1/7.1.16_1/lib/php/20160303/ as it expects. I was getting errors like the following, repeated for each extension installed this way:

Failed loading /usr/local/Cellar/php@7.1/7.1.16_1/lib/php/20160303/xdebug.so:  dlopen(/usr/local/Cellar/php@7.1/7.1.16_1/lib/php/20160303/xdebug.so, 9): image not found

Fortunately it isn't a huge manual change but this totally breaks the normal expected workflow and I sincerely hope I don't have to do this manual hackery every time or I'm going to learn to stop updating php real quick.

@sicaboy
Copy link

sicaboy commented Apr 16, 2018

Homebrew has changed its way of installing PHP and php-mcrypt

@einkoro
Copy link

einkoro commented Apr 16, 2018

@ToniTonish Did you have any luck working around the removal of --with-homebrew-curl in the new core php packages?

@smartworld-dm
Copy link

brew install php71
brew link php71
export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH" // it is wrong
echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile . // it works for me
source ~/.bash_profile

@ViktorPontinen
Copy link

@ToniTonish @einkoro - Got same issue. Any luck?

@markhughes
Copy link

markhughes commented Jun 12, 2018

@ToniTonish @einkoro @ViktorPontinen
update SSL:

brew reinstall curl --with-libssh2 --with-openssl

then edit php:

brew edit php

line 20, make it always depend on curl:
depends_on "curl"

scroll down to line ~145

    args << "--with-curl=#{Formula["curl"].opt_prefix}"

make sure we are always using the homebrew curl

now build form source:

brew reinstall --build-from-source php

@niketpathak
Copy link

What worked for me was to simply executebrew install php@7.0

@kunalkumarofficial
Copy link

Don't forget to
brew unlink php70
That's the main part

@dodync
Copy link

dodync commented Feb 17, 2020

This work for me to make it as the default command line
echo 'export PATH="/usr/local/Cellar/php/7.4.2/bin:$PATH"' >> ~/.bash_profile

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