In order to use MongoDB for our projects, we will first need to install it on our system along with its dependencies and some other tools. In this post, we will learn to install and set up Apache, PHP, and MongoDB on Ubuntu and Debian operating systems.

Installing Apache

First of all, we will install Apache on our system. Apache is a web server software and a popular HTTP client; it helps in creating virtual hosts. To install Apache on our system we will use the below-given command: Note: The commands given in this article will work on both Ubuntu and Debian as both of them use the same package manager.

Installing PHP

To install PHP along with its common modules on our system we just need to run a simple command: We have installed PHP 7.4 on our system. You can install the version and the modules that you require for your project.

Installing MongoDB

Unfortunately, MongoDB is not available in the default repositories of Ubuntu and Debian. So we will have to first import the public key which will be used by the package management system: If the terminal gives an error while executing the above-given command then you will have to install GnuPG on your system before executing this command again. The next step is to create a list file for your version of the operating system. As I am running Ubuntu 20.04, I will run the following command: For Debian 10: Next, we need to reload the local package database and then install the latest stable release of Mongodb: This will install the MongoDB server on your system.

Installing MongoDB PHP Module

For the last step, we need to install the MongoDB PHP module which is required for connecting PHP with MongoDB. Make sure to install the MongoDB module for the same version of PHP. Run the following command to check the MongoDB module is enabled for the PHP CLI environment. Next, restart the Apache server to apply changes. You can also create a phpinfo() file at the Apache document root. When you access this file in web broser,


MongoDB is a well-known, high-performance, NoSQL database. It is highly scalable and is different from Relational Database Systems such as MySQL and PostgreSQL. In this post, we learned how to install it along with its dependencies and other related tools.

How To Setup Apache  PHP   MongoDB in Ubuntu   Debian   TecAdmin - 53