For developers using Nginx and PHP with MongoDB database in the backend, MongoDB PHP drivers will be required to enable PHP support. Without the drivers, PHP-based applications and websites using MongoDB will be able to interact with the database. MongoDB packages are included in Ubuntu default repositories, however, the versions in Ubuntu repositories aren’t the latest. To install the latest, you will have to install the MongoDB package repository on Ubuntu Linux, and this tutorial will show you how. Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. When you’re ready to get MongoDB setup on Ubuntu with Nginx and PHP support, continue with the steps below:

How to install Nginx on Ubuntu Linux

To install Nginx HTTP on the Ubuntu server, run the commands below… After installing Nginx, the commands below can be used to stop, start and enable the Nginx service to always start up with the server boots. To test the Nginx setup, open your browser and browse to the server hostname or IP address and you should see the Nginx default test page as shown below. http://localhost

How to install MongoDB on Ubuntu Linux

We have written a great tutorial on how to install and configure MongoDB on Ubuntu Linux. To read that post, click on the link below: How to install MongoDB on Ubuntu Linux After reading the post above and installing MongoDB on Ubuntu, continue below with the setup.

How to install PHP on Ubuntu Linux

PHP 7.4 isn’t available on Ubuntu’s default repositories. To install it, you will have to get it from third-party repositories. Run the commands below to add the below third party repository to upgrade to PHP 7.4 Then update and upgrade to PHP 7.4 Next, run the commands below to install PHP 7.2 and related modules. After installing PHP 7.4-FPM, run the commands below to open the PHP default config file for Nginx…

How to install MongoDB PHP drivers

MongoDB PHP drivers provide exceptionally thin glue between MongoDB and PHP. run the commands below to install it. After that, run the commands below to enable the drivers

Configure Nginx to enable PHP support

If you have a custom site file, then edit it to enable Nginx PHP support. Or run the commands below to open Nginx’s default site configuration file. Then uncomment or remove the # symbol on the highlighted lines below to enable Nginx PHP support. Also, add the highlighted index.php to the index line. Restart Nginx and PHP-FPM services To verify the MongoDB PHP driver is installed and enabled, continue below. Create a phpinfo.php file in the Nginx root directory by running the commands below Then type the content below and save the file. Save the file. then browse to your server hostname followed by /phpinfo.php You should see the PHP default test page… That’s it! This post showed you how to use MongoDB with Nginx and PHP support. If you find any error above or have something to add, please use the comment form below.