The More Interesting Combo More Difficult to Apply !
Well choosing to go with PHP and MONGO DB is an interesting stack, and thus applying it has it's own hardships! Mongo DB is a NoSQL cloud based database which is generally used with Node JS as the Server side language and PHP is a server side language generally used with MySQL database.
And even for doing a localhost project we have to make a lot of changes inside php.ini file and connecting to MongoDB Atlas using MONGODB PHP driver and PHP MONGODB library is a lot of hard work. Thus, a pat on your back because this blog assumes that you are done with those steps and now is ready to Upload your files into cpanel file manager. This blog is also for those who simply wants to install mongodb on cpanel. So let's get to it !!
Step 1 : Locating the Terminal
Yes, this is also an important step! Every Blog or StackOverflow answer just goes with the terminal command yet many can't find the terminal in the first place. So here it is.
If you are using cpanel for adding mongodb :
cpanel main -> Advanced -> Terminal
If you are using WHM( Web Hosting Manager ) for the same :
WHM -> Search Terminal -> Enter Terminal
Step 2 : Installing Repo
These are the two commands you need to enter.
The first line accesses your etc directory inside cpanel File Manager ( outside public_html ).
The second command opens a file named mongodb.repo in the nano editor, there are other editors available also for which you just have to replace nano with that editor name like vi, vim.
In the next we have to write into this editor.
Step 3 : Add the Code. Save the File.
In the file that was opened, use the code and press Ctrl + X to Exit and Hit Enter to Save Changes.
You can do the same by typing " :qw " at the bottom of the code.
Step 4 : Installing the package MongoDB
After hitting to the above command you will be asked :
Is this ok [y/N]:
Simply type y and then hit the enter key. And the download will resume. And thus your Mongo DB is now installed. It just needs to be prompted to start automatically. Thus the next step.
Step 5 : Configure it to automatically start after reboots
After this mongodb is installed on your server and now you are good to go.
The next steps is for installing PHP Mongodb Extension in the cpanel.
Step 6 : Installing MongoDB PHP Extension
This is like the step where you have look for your PHP version.
You can find the PHP version using the command :
Above, the first code is for PHP version 5.6 and the later one is for PHP version 7.4 and yes according to your version you have to change the
" ea-php__ " folder name. Another important point, for PHP versions ≤ 5.99 we have to use package "mongo" and above that we have to use package "mongodb".
Step 7 : Verifying library is installed
And here also, php version matters in the folder name. This command should return name of the package. " mongodb " and this verifies it's existance.
Well it's done and you should upload the code and test it. If you are stuck at any point feel free to comment.
Good Day !