Install MongoDB extension on a specific PHP version

mongodbpeclphp7

I have a Debian web server on which I installed Apache/Mysql/PHP5 around ISPConfig 3. I manually installed an additionnal PHP version (PHP 7.0.5) in order to have one website on PHP 5, and one website on PHP 7, and everything was working. (I used the following tutorial for installing PHP 7: https://www.howtoforge.com/tutorial/how-to-install-php-7-on-debian/)

Now I want to install the new MongoDB driver (PHP 7 friendly) so it works with my PHP 7 website (I got the legacy driver working on PHP 5).

To do this I used pecl install mongodb and added extension=mongodb.so to the PHP 7 ini file. The installation is OK but when I check the extension status on PHP 7, it tells me the extension is not loaded.

The reason seems to be the MongoDB driver installed on the PHP 5 version and not the PHP 7 one.

How can I tell the MongoDB driver to install on the PHP 7 version with PECL (or maybe another way to install it)?

Best Answer

When you call pecl binary without full path your shell likely runs /usr/bin/pecl, which in turn is likely installed by PHP5 from a .deb package. You need to run the pecl binary installed with PHP7. Where is it placed it can only be known for sure by you as paths are configured at compile time. Try /usr/local/bin/pecl and $PREFIX/bin/pecl ($PREFIX being another configure option).