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.
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.
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
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, ...