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
@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