July 6, 2021 . 1 MIN READ
First, to get this thing going, we’ll need to resolve some dependencies. To do that, run this command from the terminal:
$ sudo apt-get install php-pear php5-dev
Next, you should easily be able to install the driver with the following command:
$ sudo pecl install mongo
What makes Ubuntu 14.04 a little different from other systems in how PHP extensions get loading when Apache/PHP starts. To make sure this extension gets loaded, we’ll need to add a .ini file to “/etc/php5/conf.d”. To do that, run the following command:
$ sudo touch /etc/php5/conf.d/mongo.ini
After creating the file, add this line of content:
extension=mongo.so
After you’ve saved your new .ini file, restart Apache and verify that the extension is loading with phpinfo().
The easiest to install the mongoDB driver for php5 in ubuntu is using the command :
sudo apt-get install php5-mongo
Attention, the driver is correctly installed but not loaded yet, so should absolutly restart the server, if using apache should do :
sudo service apache2 restart
<?php // connect to mongodb $m = new MongoClient(); echo “Connection to database successfully”; // select a database $db = $m->mydb; echo “Database mydb selected”;?>