Something that I'd like to share with you!

Saturday, July 23, 2022

How to connect phpMyAdmin to MariaDB under Red Hat OpenShift

No comments :


It is a container platform built for an open hybrid cloud.

Get your trial account from https://www.redhat.com/en/technologies/cloud-computing/openshift if you haven't do so.

Like me, I'm getting myself a developer sandbox with a trial length of 30 days just to understand how to play around with it.

First step is to add a database:


Pick MariaDB (Ephemeral), it is a database without persistent storage & data stored will be lost upon pod destruction. Good enough for testing:


Hit "Create" to continue:


For phpMyAdmin we will be using docker image from https://hub.docker.com/r/startxfr/openshift-phpmyadmin/

Copy the docker image name below:
startxfr/openshift-phpmyadmin

 

Now, add "Container Images" for phpMyAdmin


Paste the docker image name & hit "Create"


Now, get back to the MariaDB and verify the environment settings.



 

sh-4.4$ env|grep MARIA
MARIADB_SERVICE_HOST=172.30.1.41
MARIADB_PORT=tcp://172.30.1.41:3306
MARIADB_PORT_3306_TCP_ADDR=172.30.1.41
MARIADB_PORT_3306_TCP_PROTO=tcp
MARIADB_SERVICE_PORT_MARIADB=3306
MARIADB_PORT_3306_TCP=tcp://172.30.1.41:3306
MARIADB_SERVICE_PORT=3306
MARIADB_PORT_3306_TCP_PORT=3306
sh-4.4$ 

Verify the ConfigMap. This is where the database username & password being shared to the ConfigMap. From below we can see that they are being shared to mariadb, database-user & database-password.


Now check the environment variables use by the phpMyAdmin to connect to the MariaDB



Look into the "config.inc.php" file on how it is getting the database user & password from the environment variables.


Scroll down until to get see below section

if(getenv('MARIADB_SERVICE_USER') != '') {
$i++;
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['auth_type'] = 'config';
    $cfg['Servers'][$i]['host'] = getenv('MARIADB_SERVICE_HOST');
    $cfg['Servers'][$i]['port'] = getenv('MARIADB_SERVICE_PORT');
    $cfg['Servers'][$i]['user'] = getenv('MARIADB_SERVICE_USER');
    $cfg['Servers'][$i]['password'] = getenv('MARIADB_SERVICE_PWD');
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
}

So we now know that phpMyAdmin is getting database username & password from  MARIADB_SERVICE_USER for database username & MARIADB_SERVICE_PWD as database password.

Add both MARIADB_SERVICE_USER and MARIADB_SERVICE_PWD to phpMyAdmin environment variables by linking them to ConfigMap.



Now try to open the phpMyAdmin web page.



Good luck trying!

No comments :