Database Reference
In-Depth Information
Next, select PHP from the list of languages and follow the links to download the
latest (stable) version of the driver. Different operating systems will require different
approaches for installing the MongoDB extension for PHP automatically. That's right; just
as you were able to install MongoDB on Ubuntu automatically, you can do the same for
the PHP driver. And just as when installing MongoDB under Ubuntu, you can also choose
to install the PHP language driver manually. Let's look at the two options available to you.
Installing the PHP Driver on Unix-Based Platforms Automatically
The developers of PHP came up with a great solution that allows you to expand your
PHP installation with other popular extensions: PECL . PECL is a repository solely
designed for PHP; it provides a directory of all known extensions that you can use to
download, install, and even develop PHP extensions. If you are already acquainted
with the package-management system called aptitude (which you used previously to
install MongoDB), then you will be pleased by how similar PECL's interface is to the
one in aptitude.
Assuming that you have PECL installed on your system, open up a console and type
the following command to install the MongoDB extension:
$ sudo pecl install mongo
Entering this command causes PECL to download and install the MongoDB
extension for PHP automatically. In other words, PECL will download the extension for
your PHP version and place it in the PHP extensions directory. There's just one catch:
PECL does not automatically add the extension to the list of loaded extensions; you will
need to do this step manually. To do so, open a text editor (vim, nano, or whichever text
editor you prefer) and alter the file called php.ini , which is the main configuration file
PHP uses to control its behavior, including the extensions it should load.
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.
 
 
Search WWH ::




Custom Search