PHP 5.6 and PHP 7 on same Mac with Liip

So the other day I wanted to upgrade to php7 but didn’t want to completely remove php56 as I still have legacy projects to maintain and I’m not ‘dockerized’ yet..

You can install php with liip here.

Liip doesn’t overwrite Apple’s php binaries, it installs it under a php5 folder under /usr/local/php5 and then creates the link.

All you now need is this handy bash script to switch from one php version to the other.

#!/bin/bash

#usage:
#./switch-php.sh
#./switch-php.sh php5
#./switch-php.sh php7

#activate php56
if [ "$1" == "php5" ]; then
sudo rm /usr/local/php5
sudo ln -s /usr/local/php5-5.6.29-20170114-210819 /usr/local/php5
sudo pkill php-fpm && sudo php-fpm
echo "activated php5;"
sudo apachectl restart
elif [ "$1" == "php7" ]; then
sudo rm /usr/local/php5
sudo ln -s /usr/local/php5-7.1.9-20170914-100859 /usr/local/php5
sudo pkill php-fpm && sudo php-fpm
echo "activated php7;"
sudo apachectl restart
else
echo "parameter expected: php5 | php7"
fi

PS: You’ll have to obviously adapt the version to the one you installed!


Originally published at Joey Masip Romeu.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.