How do I connect a second database to an environment¶
An environment on the Dropsolid Experience Platform is modelled with a single database. The platform does not natively support one environment connecting to two separate databases, so if your project needs a second database you have to set it up yourself. A common case is a Drupal multisite where one codebase serves several sites and each site needs its own database.
You can do this by creating a second environment whose only job is to host the extra database, and then pointing your live environment at it. Because both environments run on the same server, your live environment can reach the second database directly.
The setup¶
- Your live environment holds everything the site normally needs: all the domains, the deployed code, and the primary database.
- An extra "database-only" environment exists purely to provision the second database and have it backed up automatically by the platform. You never deploy a site to it — it is just a managed home for the second database.
How do I set this up¶
- Create and configure your live environment as normal. Add all the domains the project serves and deploy the code, connecting it to the primary database the way any single-database project would.
- Create a second environment for the extra database. Give it a clear, recognisable name (for example, a name ending in
-db) so it is obvious that it only exists to host a database. See Create a new environment for the steps. Once it exists, the platform provisions its database and includes it in automatic backups. - Add the second database as an extra connection in your live environment. In the live environment's
settings.php, define a second database connection using the connection details of the database-only environment. Your application (for example, each site in a Drupal multisite) can then select the database it needs.
Good to know¶
- Avoid hard-coding credentials in
settings.php. Read the connection details from the variables the platform provides for the environment instead — see Environment variables and Keeping your application code portable between environments. - This is a workaround, not a built-in feature. Because the second database lives in its own environment, that environment is what gives you automatic backups of it — keep it in place for as long as the database is in use.