Database Reference
In-Depth Information
Installing the PHP Driver on Windows
You have seen previously how to install MongoDB on your Windows operating system.
Now let's look at how to implement the MongoDB driver for PHP on Windows.
For Windows, there are precompiled binaries available for each release of the PHP
driver for MongoDB. You can get these binaries from the previously mentioned github
website ( http://github.com ) . The biggest challenge in this case is choosing the correct
package to install for your version of PHP (a wide variety of packages are available). If
you aren't certain which package version you need, you can use the <? phpinfo(); ?>
command in a PHP page to learn exactly which one suits your specific environment. We'll
take a closer look at the phpinfo() command in the next section.
After downloading the correct package and extracting its contents, all you need to
do is copy the driver file (called php_mongo.dll ) to your PHP's extension directory; this
enables PHP to pick it up.
Depending on your version of PHP, the extension directory may be called either Ext
or Extensions . If you aren't certain which directory it should be, you can review the PHP
documentation that came with the version of PHP installed on your system.
Once you place the driver DLL into the PHP extensions directory, you still need to
tell PHP to load the driver. Do this by altering the php.ini file and adding the following
line in the extensions section:
extension=php_mongo.dll
When done, restart the HTTP service on your system, and you are now ready to use
the MongoDB driver in PHP. Before you start leveraging the magic of MongoDB with PHP,
however, you need to confirm that the extension is loaded correctly.
Confirming That Your PHP Installation Works
So far you've successfully installed both MongoDB and the MongoDB driver in PHP.
Now it's time to do a quick check to confirm whether the driver is being loaded correctly
by PHP. PHP gives you a simple and straightforward method to accomplish this: the
phpinfo() command. This command shows you an extended overview of all the modules
loaded, including version numbers, compilation options, server information, OS
information, and so on.
To use the phpinfo() command, open a text or HTML editor and type the following:
<? phpinfo(); ?>
Next, save the document in your webserver's www directory and call it whatever you
like. For example, you might call it test.php or phpinfo.php . Now open your browser and
go to your localhost or external server (that is, go to whatever server you are working on)
and look at the page you just created. You will see a good overview of all PHP components
and all sorts of other relevant information. The thing you need to focus on here is the
section that displays your MongoDB information. This section will list the version
number, port numbers, hostname, and so on (see Figure 2-3 ).
 
Search WWH ::




Custom Search