How to access the hostname of mariadb in the nginx server

the mariadb and phpnginx are the service. I can see in the docs it is saying to use mariadb_password with prefix. But not working. It is in the same project, both service, how to connect/reference the hostname for now? I'm beginner, pardon for inconvenience
$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = getenv('MOODLE_DB_HOST') ?: 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'mariadb'; // your database username
$CFG->dbtype = 'mariadb'; // 'pgsql', 'mariadb', 'mysqli', 'auroramysql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = getenv('MOODLE_DB_HOST') ?: 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'mariadb'; // your database username
this is the config.php file ^ and I have this in the run
envVariables:
MOODLE_DB_TYPE: mariadb
MOODLE_DB_HOST: mariadb
MOODLE_DB_PORT: 3306
MOODLE_DB_NAME: moodle
MOODLE_DB_USER: mariadb
envVariables:
MOODLE_DB_TYPE: mariadb
MOODLE_DB_HOST: mariadb
MOODLE_DB_PORT: 3306
MOODLE_DB_NAME: moodle
MOODLE_DB_USER: mariadb
No description
2 Replies
Michal Saloň
Michal Saloň4w ago
Hi, if you want to use env variable of a different service, it must be prefixed by a name of that service. E.g. you have phpnginx and mariadb services and want to use vairables from mariadb in phpnginx, this would be in your zerops.yaml
envVariables:
MOODLE_DB_TYPE: mariadb
MOODLE_DB_HOST: ${mariadb_hostname}
MOODLE_DB_PORT: ${mariadb_port}
MOODLE_DB_NAME: ${mariadb_dbName}
MOODLE_DB_USER: ${mariadb_user}
MOODLE_DB_PASSWORD: ${mariadb_password}
envVariables:
MOODLE_DB_TYPE: mariadb
MOODLE_DB_HOST: ${mariadb_hostname}
MOODLE_DB_PORT: ${mariadb_port}
MOODLE_DB_NAME: ${mariadb_dbName}
MOODLE_DB_USER: ${mariadb_user}
MOODLE_DB_PASSWORD: ${mariadb_password}
If you go to the mariadb service and scroll in the left menu to Environment variables, you will find all variables you can reference there. And if you want to use env variable from the current service, e.g. from phpnginx inside of phpnginx, you can use it directly without a prefix, like so:
envVariables:
MOODLE_WWWROOT: ${documentRoot}
envVariables:
MOODLE_WWWROOT: ${documentRoot}
See: https://docs.zerops.io/features/env-variables#referencing-variables
No description
minsomai
minsomaiOP4w ago
thank you

Did you find this page helpful?