avatar

Andres Jaimes

Installing MongoDB/PHP Driver on CentOS 6

By Andres Jaimes

Since the module is not included with the default PHP installation, you have to download it from the official repository:

cd
mkdir mongo-php-driver
cd mongo-php-driver
curl https://codeload.github.com/mongodb/mongo-php-driver/zip/master > mongo-php-driver-master.zip

Unzip it

unzip mongo-php-driver-master.zip
cd mongo-php-driver-master

You need _phpize _to build the module. You can install it from the remi repository:

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm
yum --enablerepo=remi install php-devel

Configure and build

phpize
./configure
make all
sudo make install

Make sure the installation directory is the same as the PHP extension directory by running:

php -i | grep extension_dir
  extension_dir => /usr/lib64/php/modules/

and then ls on that extension_dir

ls /usr/lib64/php/modules/

and verify you see the mongo.so file module.

If it’s not, change the extension_dir in php.ini or move mongo.so.

Make the mongo module available to php by creating the following file:

nano /etc/php.d/mongo.ini

And copy the following contents into it:

; Enable mongo extension
extension=mongo.so

Restart apache, nginx or php-fpm. Check with phpinfo() if the module was correctly installed.

Enjoy