Before you start, make sure your CentOS system is up-to-date and that PHP is already installed. You can check the current PHP version using the following command:
If PHP is not installed, you can install it using the following command:
Next, you need to configure the MongoDB repository. You can set up the MongoDB YUM repository using the following command:
Then, install MongoDB using the following command:
Once installation is complete, you can start the MongoDB service using the following command:
To ensure that MongoDB starts automatically after a system reboot, use the following command:
To enable PHP to interact with MongoDB, you need to install the MongoDB PHP extension. Install it using the following command:
After installation, add the following configuration to your PHP configuration file:
After restarting the PHP service, verify that the MongoDB PHP extension is successfully loaded using the following command:
If you see "mongodb" in the output, then PHP and MongoDB are successfully configured.
By following this guide, you have successfully configured PHP with MongoDB on CentOS. This setup will provide strong support for your development projects and enable you to leverage the advantages of both technologies. If you encounter any issues, you can refer to the official documentation or community resources for assistance.