Chapter 2. PHP, MongoDB, and You
This chapter will provide the foundational knowledge of working with MongoDB and PHP. By the end of the chapter, you can expect to be able to install the driver and build an application in PHP that uses MongoDB as the data store.
Installing the Driver on Linux or MacOS X
As distributions and environments vary, installation instructions will also vary. It’s important to have a basic understanding of your operating system or distribution, particularly as it pertains to PHP. Hopefully, these general instructions will provide enough information for you to be able to customize them for your particular situation.
Checking for the Driver
Before you install the driver, you should first check to see if the driver is already present. A growing number of distributions include the MongoDB driver as part of the base install. The following command will return a bunch of information about the driver if it is installed:
php --re mongo
If you do not have the extension installed, you will see:
Exception: Extension mongo does not exist
Installing the Driver
There are a few different ways to install the PHP MongoDB driver. If you are using Zend Server, you are already good to go. The Zend Server ships with the MongoDB driver already installed. Some distributions maintain their own deb or rpm packages to install the driver, and while this approach works, it is not the recommended approach. It’s recommended to use PECL to install the driver, as it’s consistent across all systems, ...
Get MongoDB and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.