Lando is an excellent tool to setup development environments using docker in a really easy way to setup, maintain and reuse. It provides an uniform way to work in a company with multiple projects from different kinds, not need to reinvent the wheel on each project on each team.
In 42mate we have been using Lando for a long time, before that we were using Vagrant, Homestead, Docker4Drupal, Docker compose and others. However Lando has prove that is the best fit for us.
One thing that I want to improve in my dev workflow is to get better visibility and accessibility for the Database using some kind of visual tool.
In Lando is super easy to access to the database with the mysql console, you just need to run
And that’s it, you are in. However, if you want to access with tools like SequelPro, SQLace, Beekeper, MySQL workench and other visual tools is not so easy.
In Lando by default the Database does not export the port to connect via TCP, if you want to connect via TCP you need to expose the database port, to do that you need to manually setup in the lando config the port that you want to expose to connect.
In MySQL the connection port is 3306 by default, you can setup this port and everything will looks normal, although, in order to use the port you need to be sure that is free in your host machine, otherwise Lando wont be able to make the port forwarding.
In order to avoid this problems Lando recommends to use a different port, such as 3307, that will work and you can document that in your Readme.md to all your team knows about it. But, what if you company has two projects, and you have members that are working in two projects, and they need to start the both lando environment at the same time? … bum!, port conflicts again.
So the next idea is to use different ports on different projects, what brings a new problem, how we can assign different ports to different projects, how we will make know everybody in the team which port are we using in this project, the answer will writing a documentation, however you know that Nobody wants to read the documentation and the documentation gets obsolete very fast! That’s why in 42mate we prefer convention over documentation, is easier to transmit conventions rather than documentations.
That’s how I decided to find alternatives to get an standard way to access to the database with a graphical tool. My best finding so far is to use PhpMyAdmin, why?
- PhpMyAdmin is a well know and full featured tool
- It comes out of the box as a Lando service
- No need to install extra tools, it comes in the lando file
- It will provide the visual insights and access that I’m looking for
Lets see how to setup the PhpMySQL service. Lets go to your .lando.yml file, where all magic happens
We need to add a new service for phpmysql, so in the service branch of the yml, add a new entry called whatever you want from the type phpmyadmin. We are going to use as convention the name sql<project-name> for this service.
service: sqlmyproject: type: phpmyadmin
Now, in order to access to this service I needed to add an entry in the proxy. In the proxy branch, add this entry
proxy: sqlmyproject: - sqlmyproject.lndo.site
Where sqlmyproject it must be the name of the service, and sqlmyproject.lndo.site the url that we be using to access to the phpMyAdmin, here we are using the same naming of the service.
That’s it, you can now run lando rebuild to recreate your services and once the process is done, access to the url defined in the proxy to manage your database with PhpMyAdmin.
What if I have multiple databases?
In the case you have multiple databases instances on your project, you’ll have to add the host entry on the phpmyadmin service in order to be able to access. Add a new host entry with the name of the services that are actually databases.
services: db_main: type: mariadb:10.3.27 portforward: false creds: user: dbuser password: dbpass database: db_main db_logistics: type: mariadb:10.3.27 portforward: false creds: user: dbuser password: dbpass database: db_logistics db_reporting: type: mariadb:10.3.27 portforward: false creds: user: dbuser password: dbpass database: db_reporting sqlmyproject: type: phpmyadmin hosts: - db_main - db_logistics - db_reporting
That’s it, you will see a drop down in sidebar to change between the databases.
Originally posted on 42mate