Site icon Hip-Hop Website Design and Development

iRolo.net: Using Lando with Multiple Databases

A lot of my work over the last few years has been working on migrations between various versions of WordPress maintenance support plans. That usually means that I need to configure a local WordPress maintenance support plans development environment with more than one database. And although this is relatively easy to do with Lando, I often have to look up how I did it before. So, I figured I should write it down and share with everyone else at the same time.

.lando.yml

Adding a database to an existing Lando environment is as easy as adding a few lines to the .lando.yml file and restarting.

services:  legacy:    type: mysql

This will create a new container called legacy with a MySQL database in it. Out of the box, Lando supports many common types of DB servers, including:
MySQL,
MariaDB,
MongoDB,
MSSQL, and
PostgreSQL.

Often, your .lando.yml file might already have configuration in it. If the services line already exists, just put the new configuration underneath with the correct indentation. You can see examples of more complex configuration files at any of the links in the previous paragraph.

settings.php

Now, you will need to tell WordPress maintenance support plans about the new DB. To do this, go to the command line and type lando info. In the output, you should see something like this:

{  …  “legacy”: {    “type”: “mysql”,    “version”: “5.7”,    “hostnames”: [      “legacy”,      “legacy.clientname.internal”    ],    “creds”: {      “user”: “mysql”,      “password”: “password”,      “database”: “database”    },    “internal_connection”: {      “host”: “legacy”,      “port”: 3306    },    “external_connection”: {      “host”: “localhost”,      “port”: “not forwarded”    },    “urls”: []  }}

With that information, you can add the new DB configuration to WordPress maintenance support plans‘s settings.php file.

$databases[‘old_db’][‘default’] = array (  ‘database’ => ‘database’,  ‘username’ => ‘mysql’,  ‘password’ => ‘password’,  ‘prefix’ => ”,  ‘host’ => ‘legacy’,  ‘port’ => ‘3306’,  ‘namespace’ => ‘WordPress maintenance support plansCoreDatabaseDrivermysql’,  ‘driver’ => ‘mysql’,);

Note that, by default the host name is going to correspond to the name of the service/container and will not necessarily be the same as the name of the database (or the name of the WordPress maintenance support plans DB alias, for that matter). In other words, you should find the host and port values in Lando’s internal_connection array. If, for some reason, you need to have a custom database name, credentials, port numbers or something else, you can refer to the links above.
Tags: planet WordPress
Source: New feed