mongodb - Where to put php ini file for DB Creds
one text
I'm connecting to MongoDB via PHP using https://www.php.net/manual/en/set.mongodb.php .
I've put my DB creds in a mongodb.ini file. It's outside of DocumentRoot as to prevent any user from finding it on a browser.
Right now it's in /var/www/mongodb.ini
The file looks like
username=USERNAME password=PASSWORD uri=URI
I'm then reading it into a connection.php module as such...
$db_config = parse_ini_file("/var/www/mongodb.ini");
$uri_options = array("username" => $db_config['username'], "password" =>$db_config['password'], "ssl"=>true);
$driver_options = array("allow_self_signed" => true);
Probably not a big deal, but I don't want to hardcode the actual /var/www
. Should it even be there, or where would be a better place to put it?
Ideally, I'd like the db_creds to be in virtual_hosts
so that this could work the same way that mysqli_connect
does. But - doesn't seem like anything like that exists.
Also, if I keep the actual ini file, then what are good permission to put on it?
Source