Saturday, 4 July 2020

[Linux] Install PHP mongodb extension for PHP 7.2 and higher

This article will guide you to install php mongodb extension for PHP7 on linux operating system platform. The operating system we use is Centos, but it is also true for other linux distributions like Ubuntu, Redhat, Fedora ....

When upgrading to PHP7 we often encounter problems when we cannot install the php-mongo extension. You may encounter the following error message:

Package: php-pecl-mongo-1.6.14-1.el7.remi.5.4.x86_64 (remi)
Requires: php(zend-abi) = 20100525-64
* Reason: 
We have 2 mongo extensions for PHP: php-mongo and php-mongodb. Php-mongo only supports php 5.6, but php-mongodb supports the latest version 7.4. That's why you have an error when trying to install php-mongo for PHP7.
php-mongo is older and has been discontinued, but it is currently available as a library in remi repos. And php-mongodb is Pecl's latest library but it is not available and you have to install it yourself via php-pear.

* Solving problems: install php-mongodb extension for PHP7 

Step 1: Install apache(httpd) and php 7
Step 2: Install php-pear
install gcc php-pear php-devel
Step 3: Install mongodb extension 
pecl install mongodb
Step 4: Enable php-mongodb extension 
open php.ini file, then add the following line
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
extension=mongodb

Step 5: Verify PHP Mongodb extension is enabled
php -m
Done !

* Note: The syntax used in previous PHP versions ('extension=<ext>.so' and 'extension='php_<ext>.dll') is supported for legacy reasons and may be deprecated in a future PHP major version. So, when it is possible, please move to the new ('extension=<ext>) syntax.

* Refer: https://blog.remirepo.net/pages/PECL-extensions-RPM-status



0 nhận xét:

Post a comment