Homebrew recently deprecated the repo https://github.com/Homebrew/homebrew-php as of March 31st, 2018.
So, how do you install PHP@5.6, and/or PHP@7.2 (or @7.0, or @7.1, these are untested, but I assume will work).
I work on some legacy sites, that require switching between the versions.
So, lets run through this… I’m going to assume you cleaned up the old version of PHP.
# clean up the old PHPs.
$> brew uninstall uninstall php72 php56
# append whatever options you may want. maybe –with-httpd
$> brew install php@7.2
$> brew unlink php@7.2 –force
$> brew install php@5.6
$> brew unlink php@5.6 –force
modify you’re httpd conf, to accept your desired version of PHP you want to run.
/usr/local/etc/httpd/httpd.conf
#LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
If you run
$> php -v
it will fail.
$> php -v
-bash: /usr/local/bin/php: No such file or directory
This is because we unlinked both versions.
Say we want to use PHP version 5.6
$> brew link php@5.6 --force
Now when we php 5.6 as our cli PHP.
$> php -v
PHP 5.6.35 (cli) (built: Mar 31 2018 20:21:31)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
If you want php5 to run in apache.
ensure that php5 module is enabled in httpd.conf, and restart apache/httpd deamon.
$> sudo brew services httpd restart
NOTE: You need to run with sudo, if your http port is below 1000, or was that 1024… I forget.
If you want to switch back to php@7.2,
- unlink,
- change httpd.conf to use php7.2
- restart apache
Also, if you want to install xdebug,or memcached use pecl.
for PHP@5.6
$> pecl install xdebug-2.2.0
for PHP@7.2
$> pecl install xdebug
If you want memcached:
with PHP@5.6 (as of writing this, 2018-04-10)
brew install libmemcached
brew install pkg-config<
pecl install memcached-2.2.0
use: /usr/local/Cellar/libmemcached/1.0.18_2 for the memcached location.
Leave a Reply