A következő címkéjű bejegyzések mutatása: driver. Összes bejegyzés megjelenítése
A következő címkéjű bejegyzések mutatása: driver. Összes bejegyzés megjelenítése

2012. július 30., hétfő

Installing MongoDB driver for PHP Ubuntu Server 12.04

This article is about connecting PHP with MongoDB.

Before you start, make sure you have apache2 and PHP5+ installed in your server:
$ sudo apt-get install apache2 php5 libapache2-mod-php5


You will also need to install some dependencies for the driver. Do it this way:
$ sudo apt-get install php-pear php5-dev


Okay, let's find this driver!
$ pecl search mongo


And install it:
$ sudo pecl install mongo


If you wouldn't have the make package installed, install and reinstall mongo:
$ sudo apt-get install make
$ sudo pecl install mongo


Now, let's hack that php.ini too, located at /etc/php5/apache2/ path. Do that by adding mongo.so extension somewhere after the extensions part:
$ sudo vim /etc/php5/apache2/php.ini

extension = mongo.so


Since I have run my database server on a separate MongoDB server, I have also changed to path to the database for the extension. I have added the following lines after MySQL block:
[Mongo]
; default host 127.0.0.1
; custom host: the IP address of the database server
mongo.default_host = "xxx.xxx.xxx.xxx"
Further infos at in the PHP - MongoDB documentation.