2 / 7
Dec 2021

Hey guys, new guy here so please bear with me.
I have a plain web page hosted on hostinger.
It supports php 8.0 and has a mongdb extension which I have enabled.
I tried connecting to my atlas server with a simple test.php code. All I get is some sort of unable to load page, http 500 error. I tried different variations of the code. My impression is that this extension is not properly installed, or rather, I have to install it and maybe I have no clue how to. Any tips?
Should I have signed up for a dedicated server and installed the mongodb php driver through a shell? I have the basic hosting plan I think, not sure I get a dedicated server. But it shouldn’t be hard to make a simple php code and connect to my atlas server right? Is a dedicated server for the php page a must? Seems like overkill to me.
Thanks in advance,
Marcelo

Update: I have managed to use the ssh to connect to my host. I have succesfully installed the package with the composer. Now the problem seems to be on the code itself I guess. Although I still get the very same http 500 error.
Here’s the code nevertheless:

<?php $client = new MongoDB\Client( 'mongodb+srv://myusername:mypassw@apsan.sodk5.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'); $db = $client->test; ?>

Did I miss anything? I simply used the command composer require mongodb/mongodb and installed it through ssh.

7 months later
2 years later

I had the same problem. Solution: go to the advanced settings of website, then php configuration. Enable mongodb in PHP extensions and then install mongodb with composer

1 year later

MongoDB Driver that Hostinger uses is not the last version available. If you use a shared host, you need to downgrade to match their version, otherwise it will return messages as if it wasn’t installed.

In my website the version is 1.18.1 for example. You should use libs versions compatible with the version in your website.

If you use a VPS, then you can install the latest version.