Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Debian 8 - Install MongoDB PHP Driver

Install pear and the php dev tools necessary for compiliation if you haven't already.

sudo apt-get install php5-dev php5-cli php-pear -y

Install the mongo driver

sudo pecl install mongo

This will ask you inf you want to install Enterprise authentcation and the default is 'no';

Add the extension to the php.ini files by running the script below with BASH. This assumes you are using apache.

#!/bin/bash
SEARCH='; If you wish to have an extension loaded automatically, use the following'
REPLACE='extension=mongo.so\n; If you wish to have an extension loaded automatically, use the following'
FILEPATH="/etc/php5/apache2/php.ini"
CLI_FILEPATH="/etc/php5/cli/php.ini"
sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH
sudo sed -i "s:$SEARCH:$REPLACE:" $CLI_FILEPATH

# Restart Apache to take effect
sudo service apache2 restart

At the time of writing this tutorial using a Debian 8 box with PHP 5.6, this resulted installing version 1.6.11

Check Driver Version

php --ri mongo | grep Version
Last updated: 16th September 2021
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch