Can two DDEV Laravel projects share a single database?

73 views Asked by At

I have 2 separate Laravel projects configured to use a common database.

Reasons are mostly related to separating concerns:

  • project A is related to handling the core tables via REST APIs;
  • project B reads the core tables and operates on another set of tables by using jobs/queues/etc...

I'm using DDEV for local environment and I'm struggling to find a solution to share a single db instance between the two projects. I want to be able to run ddev start from project A OR project B and have a single reference for the db container, as well as run both projects together at the same time.

Is that even possible with DDEV, maybe with a docker-compose.db-override.yaml on project B?

Other SO questions didn't help me that much... Thank you

1

There are 1 answers

6
rfay On

This is very easy to do and is documented in the DDEV FAQ:

Yes, this is commonly required for situations like Drupal migrations. For the web container to access the db container of another project, use ddev-<projectname>-db as the hostname of the other project.

Let’s say we have two projects, for example: project A, and project B. In project A, use mysql -h ddev-projectb-db to access the database server of project B.