Databases Reference
In-Depth Information
comments). This will involve creating a tree of comments and implementing a voting
system.
Installing the PHP Driver
The MongoDB PHP driver is a PHP extension. It is easy to install on almost any system.
It should work on any system with PHP 5.1 or newer installed.
Windows install
Look at the output of
phpinfo()
and determine the version of PHP you are running
(PHP 5.2 and 5.3 are supported on Windows; 5.1 is not), including VC version, if
shown. If you are using Apache, you should use VC6; otherwise, you're probably run-
ning a VC9 build. Some obscure Zend installs use VC8. Also notice whether it is thread-
safe (usually abbreviated “ts”).
While you're looking at
phpinfo()
, make a note of the
extension_dir
value, which is
where we'll need to put the extension.
Now that you know what you're looking for, go to
Github
. Download the package that
matches your PHP version, VC version, and thread safety. Unzip the package, and move
php_mongo.dll
to the
extension_dir
directory.
Finally, add the following line to your
php.ini
file:
extension=php_mongo.dll
If you are running an application server (Apache, WAMPP, and so on), restart it. The
next time you start PHP, it will automatically load the Mongo extension.
Mac OS X Install
It is easiest to install the extension through PECL, if you have it available. Try running
the following:
$ pecl install mongo
Some Macs do not, however, come with PECL or the correct PHP libraries to install
extensions.
If PECL does not work, you can download binary builds for OS X, available at
see what version of PHP you are running and what the value of
extension_dir
is, and
then download the correct version. (It will have “osx” in the filename.) Unarchive the
extension, and move
mongo.so
to the directory specified by
extension_dir
.
After the extension is installed via either method, add the following line to your
php.ini
file:
extension=mongo.so