How to install php-mongodb module for PHP 7 on CentOS 7


Example for PHP 7.2.34

Step 1:

[root@tutorialspots ~]# yum install -y php72-php-pecl-mongodb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     |  23 kB     00:00
 * base: mirror.checkdomain.de
 * epel: mirror.imt-systems.com
 * extras: centosmirror.netcup.net
 * remi-php72: mirror.23m.com
 * remi-safe: mirror.23m.com
 * updates: linux.darkpenguin.net
base                                                     | 3.6 kB     00:00
epel                                                     | 4.7 kB     00:00
extras                                                   | 2.9 kB     00:00
mariadb                                                  | 3.4 kB     00:00
nginx                                                    | 2.9 kB     00:00
nodesource                                               | 2.5 kB     00:00
remi-php72                                               | 3.0 kB     00:00
remi-safe                                                | 3.0 kB     00:00
updates                                                  | 2.9 kB     00:00
(1/8): nginx/x86_64/primary_db                             |  71 kB   00:00
(2/8): epel/x86_64/updateinfo                              | 1.0 MB   00:00
(3/8): mariadb/updateinfo                                  | 5.7 kB   00:00
(4/8): epel/x86_64/primary_db                              | 7.0 MB   00:00
(5/8): remi-php72/primary_db                               | 260 kB   00:00
(6/8): remi-safe/primary_db                                | 2.1 MB   00:00
(7/8): mariadb/primary_db                                  |  57 kB   00:00
(8/8): updates/7/x86_64/primary_db                         |  13 MB   00:00
Resolving Dependencies
--> Running transaction check
---> Package php72-php-pecl-mongodb.x86_64 0:1.12.0-1.el7.remi will be instal
--> Processing Dependency: php72-php(api) = 20170718-64 for package: php72-ph
ecl-mongodb-1.12.0-1.el7.remi.x86_64
--> Processing Dependency: php72-php(zend-abi) = 20170718-64 for package: php
php-pecl-mongodb-1.12.0-1.el7.remi.x86_64
--> Processing Dependency: php72-php-json(x86-64) for package: php72-php-pecl
ngodb-1.12.0-1.el7.remi.x86_64
--> Processing Dependency: php72-runtime for package: php72-php-pecl-mongodb-
2.0-1.el7.remi.x86_64
--> Processing Dependency: php72-runtime(remi)(x86-64) for package: php72-php
cl-mongodb-1.12.0-1.el7.remi.x86_64
--> Processing Dependency: libicudata.so.69()(64bit) for package: php72-php-p
-mongodb-1.12.0-1.el7.remi.x86_64
--> Processing Dependency: libicuuc.so.69()(64bit) for package: php72-php-pec
ongodb-1.12.0-1.el7.remi.x86_64
--> Running transaction check
---> Package libicu69.x86_64 0:69.1-2.el7.remi will be installed
---> Package php72-php-common.x86_64 0:7.2.34-10.el7.remi will be installed
---> Package php72-php-json.x86_64 0:7.2.34-10.el7.remi will be installed
---> Package php72-runtime.x86_64 0:2.0-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                   Arch      Version                 Repository    Si
=============================================================================
Installing:
 php72-php-pecl-mongodb    x86_64    1.12.0-1.el7.remi       remi-safe    605
Installing for dependencies:
 libicu69                  x86_64    69.1-2.el7.remi         remi-safe    9.6
 php72-php-common          x86_64    7.2.34-10.el7.remi      remi-safe    645
 php72-php-json            x86_64    7.2.34-10.el7.remi      remi-safe     71
 php72-runtime             x86_64    2.0-1.el7.remi          remi-safe    1.1

Transaction Summary
=============================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 12 M
Installed size: 41 M
Downloading packages:
(1/5): php72-php-common-7.2.34-10.el7.remi.x86_64.rpm      | 645 kB   00:00
(2/5): php72-php-json-7.2.34-10.el7.remi.x86_64.rpm        |  71 kB   00:00
(3/5): php72-php-pecl-mongodb-1.12.0-1.el7.remi.x86_64.rpm | 605 kB   00:00
(4/5): libicu69-69.1-2.el7.remi.x86_64.rpm                 | 9.6 MB   00:00
(5/5): php72-runtime-2.0-1.el7.remi.x86_64.rpm             | 1.1 MB   00:00
-----------------------------------------------------------------------------
Total                                               35 MB/s |  12 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php72-runtime-2.0-1.el7.remi.x86_64                          1
  Installing : php72-php-json-7.2.34-10.el7.remi.x86_64                     2
  Installing : php72-php-common-7.2.34-10.el7.remi.x86_64                   3
  Installing : libicu69-69.1-2.el7.remi.x86_64                              4
  Installing : php72-php-pecl-mongodb-1.12.0-1.el7.remi.x86_64              5
=====================================================================

  WARNING : PHP 7.2 have reached its "End of Life" in
  November 2020. Even, if this package includes some of
  the important security fix, backported from 7.3, the
  UPGRADE to a maintained version is very strongly RECOMMENDED.

=====================================================================
  Verifying  : php72-runtime-2.0-1.el7.remi.x86_64                          1
  Verifying  : php72-php-common-7.2.34-10.el7.remi.x86_64                   2
  Verifying  : libicu69-69.1-2.el7.remi.x86_64                              3
  Verifying  : php72-php-pecl-mongodb-1.12.0-1.el7.remi.x86_64              4
  Verifying  : php72-php-json-7.2.34-10.el7.remi.x86_64                     5

Installed:
  php72-php-pecl-mongodb.x86_64 0:1.12.0-1.el7.remi

Dependency Installed:
  libicu69.x86_64 0:69.1-2.el7.remi
  php72-php-common.x86_64 0:7.2.34-10.el7.remi
  php72-php-json.x86_64 0:7.2.34-10.el7.remi
  php72-runtime.x86_64 0:2.0-1.el7.remi

Complete!

Step 2: make symbolic link for mongodb.so
ln -s /opt/remi/php72/root/usr/lib64/php/modules/mongodb.so /usr/lib64/php/modules/mongodb.so

Step 3: copy file 50-mongodb.ini
cp /etc/opt/remi/php72/php.d/50-mongodb.ini /etc/php.d

Step 4: restart PHP-fpm
service php-fpm restart

Leave a Reply