Docs Menu
Docs Home
/ / /
PHP Library Manual
/

Download and Install

1

Before you begin developing, ensure that you have the following dependencies installed on your local machine:

  • PHP version 7.4 or later

  • Composer version 2.0 or later

2

Run the following command to install the mongodb PHP extension:

sudo pecl install mongodb
3

To enable the mongodb extension in your PHP configuration file, add the following line to the top of your php.ini file:

extension=mongodb.so

Tip

You can locate your php.ini file by running the following command in your shell:

php --ini
4

From your root directory, run the following command in your shell to create a directory called php-quickstart for this project:

mkdir php-quickstart

Select the tab corresponding to your operating system and run the following commands to create a quickstart.php application file in the php-quickstart directory:

cd php-quickstart
touch quickstart.php
cd php-quickstart
type nul > quickstart.php
5

To install the MongoDB PHP Library, run the following command in your php-quickstart directory:

composer require mongodb/mongodb

After installing the library, include Composer's autoload.php file by adding the following code to the top of your quickstart.php file:

<?php
require_once __DIR__ . '/vendor/autoload.php';

After you complete these steps, you have a new project directory, a new application file, and the library dependencies installed.

Note

If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.

Back

Get Started