r/PHPhelp • u/skwyckl • Sep 12 '25
Need help with multi-database Laravel setup?
So, maybe I have over-engineered this application, but I don't have the time to refactor (deadline is next week). I have the following setup:
- Laravel+Inertia+React web application + SQLite (administrators) + MariaDB (data)
- Everything is Dockerized
- Everything is initialized using Docker Compose, with additional Caddy as reverse proxy
This is deployed using Docker-in-Docker in a GitLab CI pipeline
- The web app's image is pushed to our internal container registry
Everything has been working more or less, but the pipeline keeps failing on test stage with:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'172.19.0.4' (using password: YES)The default database is the SQLite one, and these tests pertain the SQLite database. The database file exists and the database has the default config. We chose SQLite to keep our (administrators') credentials because we are just a couple of people, so we needn't a full multi-user kind of setup. However, I can't seem to manage to set it up in the right way, why is it trying to access MariaDB (I think?) even though the default is SQLite?
Outside of the Docker-in-Docker CI context it works, just FYI (even after removing old build artifacts).
8
u/cursingcucumber Sep 12 '25
So in essence, you complicated things by trying to simplify them 😂👍🏻
Why not just put the admins in the MySQL database and be done with it? Doubt it would require a refactor at all?
2
u/MateusAzevedo Sep 12 '25
It seems to me it's an issue with configuration/env values. Something is different in that context and the app is not using the settings you expect.
It's hard to tell anything more concrete without having full access to your setup. I believe you'll need to do a proper debugging to figure this out.
1
u/E3ASTWIND Sep 12 '25
Unnecessarily complicated. Just one question is docker really required? And why are you mariadb in docker is it really required?
1
u/snoogazi Sep 12 '25
How are you using Docker? Is it via Sail? If so try using the username “sail” and the password “password”. I’ve noticed that root doesn’t always seem to work for whatever reason
1
u/Anxious-Insurance-91 Sep 12 '25
that acces denied might be because you created the user but didnt grant all permissions for accesing via wildcard IP
1
u/obstreperous_troll Sep 13 '25 edited Sep 13 '25
Not related to your DB problem, but:
Have you considered using Traefik instead? You can configure that with just a handful of labels on whatever service you want to expose. For example:
Then just run Traefik with the Docker provider enabled. Traefik detects when containers are added or dropped with those labels, and reconfigures its routes accordingly.
As for the test failures, is your environment configured properly in CI? I suggest defining every environment variable that needs to be set in phpunit.xml, and not relying on .env files. Stick a
var_dump($_ENV)at the start of your failing test and eyeball it.