mautic / docker-mautic

Docker Image for Mautic
https://www.mautic.org
362 stars 274 forks source link

Database Enviroment variables not working #221

Closed MarioP-Dev closed 2 years ago

MarioP-Dev commented 2 years ago

Mautic Version

4.0.0

PHP version

7.4.25

What browsers are you seeing the problem on?

Not relevant

What happened?

I don´t know why Mautic's Docker container is not grabbing the MAUTIC_DB_HOST environment variable. It's grabbing all the other variables except that. So an exception throws indicating the impossibility to connect to the database because it continuously tries to connect to my VPS's address instead of the one I gave.

How can we reproduce this issue?

Step 1: Setup an external database (not in the same network as the Mautic Container) Step 2: Create a Mautic Docker Container with the database IP and other environment variables Step 3: Wait until the error appears

Relevant log output

Mautic not found in /var/www/html - copying now...
Complete! Mautic has been successfully copied to /var/www/html

Ensuring Mautic database is present

MySQL Connection Error: (1045) Access denied for user 'dbuser'@'MYVPSIP' (using password: YES)

MySQL Connection Error: (1045) Access denied for user 'dbuser'@'MYVPSIP' (using password: YES)

MySQL Connection Error: (1045) Access denied for user 'dbuser'@'MYVPSIP' (using password: YES)

MySQL Connection Error: (1045) Access denied for user 'dbuser'@'MYVPSIP' (using password: YES)

Code of Conduct

wget commented 2 years ago

I have been facing the same issue in my previous Docker deployment. This is due to a configuration issue on the database side.

Let's take an example to illustrate. You can connect on MariaDB via a UNIX socket or a TCP/IP socket.

This is what is called the domain of the user, which is materialized by the Host column in the mysql.user table. The latter is either be localhost (meaning UNIX socket) or % (meaning TCP/IP).

You may have a connection only for one type of connection not the other. The solution would be to edit that table manually if your provider is to giving you the choice to change the connection type using a GUI.

ALTER USER 'mautic-user'@'%' IDENTIFIED BY 'mypassword';
MariaDB [mysql]> select host,user from mysql.user;
+-----------+-------------+
| Host      | User        |
+-----------+-------------+
| %         | mautic-user |
| %         | root        |
| localhost | mariadb.sys |
| localhost | root        |
+-----------+-------------+
4 rows in set (0.002 sec)

During my Mautic migration this is what I had to do. Here in my example since mautic-user only existed via a TCP/IP connection (usage of % as host), we needed to use the right alter user command:

MariaDB [mysql]> ALTER USER 'mautic-user'@'localhost' IDENTIFIED BY '<SEE PASSWORD MANAGER>';

I can reassure you the Docker Host is working (e.g. here a production Docker Compose v2 based deployment at Collabora Productivity =) :arrow_heading_down:

Screenshot_20220425_164317

Closing.