Database Reference
In-Depth Information
Next, open the php.ini file, scroll down to the extensions section, and add the following line to tell PHP to load
the MongoDB driver:
extension=mongo.so
The preceding step is mandatory; if you don't do this, then the MongoDB commands in php will not function.
To find the php.ini file on your system, you can use the grep command in your shell: php -i | grep Configuration .
Note
The “Confirming That Your PHP Installation Works” section later in this chapter will cover how to confirm that an
extension has been loaded successfully.
That's all, folks! You've just installed the MongoDB extension for your PHP installation, and you are now ready to
use it. Next, you will learn how to install the driver manually.
Installing the PHP Driver on Unix-Based Platforms Manually
If you would prefer to compile the driver yourself or for some reason are unable to use the PECL application as
described previously (your hosting provider might not support this option, for instance), then you can also choose to
download the source driver and compile it manually.
To download the driver, go to the github website ( http://github.com ) . This site offers the latest source package
for the PHP driver. Once you download it, you will need to extract the package, and make the driver by running the
following set of commands:
$ tar zxvf mongodb-mongdb-php-driver-<commit_id>.tar.gz
$ cd mongodb-mongodb-php-driver-<commit_id>
$ phpize
$ ./configure
$ sudo make install
This process can take a while, depending on the speed of your system. Once the process completes, your
MongoDB PHP driver is installed and ready to use! After you execute the commands, you will be shown where the
driver has been placed; typically, the output looks something like this:
Installing '/ usr/lib/php/extensions/no-debug-zts-20060613/mongo.so'
You do need to confirm that this directory is the same directory where PHP stores its extensions by default. You
can use the following command to confirm where PHP stores its extensions:
$ php -i | grep extension_dir
This line outputs the directory where all PHP extensions should be placed. If this directory doesn't match the
one where the mongo.so driver was placed, then you must move the mongo.so driver to the proper directory, so PHP
knows where to find it.
As before, you will need to tell PHP that the newly created extension has been placed in its extension directory,
and that it should load this extension. You can specify this by modifying the php.ini file's extensions section; add the
following line to that section:
extension=mongo.so
 
 
Search WWH ::




Custom Search