Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@n8jadams
Copy link

n8jadams commented Jul 15, 2017

Thanks for this! I tried a million other ways and this is what eventually got it to work.

@coulon-xyz
Copy link

coulon-xyz commented Aug 24, 2017

brilliant

@TomMuc1
Copy link

TomMuc1 commented Sep 17, 2017

thanks for sharing - worked instantly :)

@vaske
Copy link

vaske commented Oct 5, 2017

Thanks for this one, I followed up instructions and after sudo apachectl restart I keep getting this kind of error:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using vaske-mbp.local. Set the 'ServerName' directive globally to suppress this message

Can't find solution for it, if I revert back to php56 it works, but php71 or php70 runs into this issue, any idea what might cause it?
I already added ServerName localhost to httpd.conf

Also apache use /etc/php.ini which is ini file of php56 default one.

@adnauseum
Copy link

adnauseum commented Oct 9, 2017

Thanks for your time and effort!

@gusbemacbe
Copy link

gusbemacbe commented Oct 12, 2017

If you use macOS High Sierra, it comes already with php71. If you want to upgrade to php72, and in these commands, change from php71 to php72. And you have to write brew install homebrew/php/php72-mcrypt and brew install homebrew/php/php72-imagick.

@TechNinjaWeb
Copy link

TechNinjaWeb commented Oct 25, 2017

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

amrutjadhav commented Nov 16, 2017

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

@bibibaonam
Copy link

bibibaonam commented Dec 14, 2017

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

varshaan0sharma commented Mar 24, 2018

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

@marknt15
Copy link

marknt15 commented Mar 30, 2018

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

ToniTonish commented Apr 9, 2018

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

heberfomin commented Apr 11, 2018

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

artcoholic commented Apr 12, 2018

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!

@clozed2u
Copy link

clozed2u 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

EugenMayer commented Apr 13, 2018

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

@w0rd-driven
Copy link

w0rd-driven commented Apr 14, 2018

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

smartworld-dm commented Apr 20, 2018

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

ViktorPontinen commented May 2, 2018

@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

niketpathak commented Aug 12, 2018

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

@kunalkumarofficial
Copy link

kunalkumarofficial commented Jan 21, 2019

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