1 min read

Installing PHP extensions for different versions of PHP

In this example I will be using couchbase, we use this extension across 3 of our projects and each one uses a different version of PHP.

echo "Bump to sudo"
sudo -s

echo "install for php7.0"
pecl config-set php_suffix 7.0
pecl install couchbase-2.2.2

echo "install for php7.1"
pecl config-set php_suffix 7.1
pecl uninstall -r couchbase-2.2.2 # note the -r, "pretend to remove"
pecl install couchbase-2.2.2

echo "install for php7.2"
pecl config-set php_suffix 7.2
pecl uninstall -r couchbase-2.2.2
pecl install couchbase-2.2.2

As you can see, inbetween each step we executed pecl config-set php_suffix 7.x which triggers pecl to use a different API each time. This API represents the end result directory; if you seen an error about not being able to find couchbase.so within a certain dir like /usr/lib/php/20160303 then it means that you have installed couchbase, but for a different php_suffix. In that example 2016 is php71, 2017 is php72.