Connect to a DDEV database in PHPStorm
To connect to the DDEV database from within PHPStorm, the first step is to define the database container port. This is needed to ensure the connection credentials don't change between restarts of DDEV.
ddev config --host-db-port=33009
You will need to manage this personally, as the host_db_port in ddev. Unfortunately, it needs to be unique, making it tricky to manage if you share projects with different teams.
You can pick something like 33004 or 33005, but if someone sets another project to the same one, then you may need to juggle the ports around.
In PHPStorm you open the Database window and add a datasource.
Click on the Data sources and choose to add a Mariadb source.
I usually Name the Connection "DDEV" but that can be anything you like.
Change the connection type to be URL only
Enter the URL:
jdbc:mariadb://127.0.0.1:33009/db?user=db&password=db
(change the port to be whatever you setup in DDEV)
Now you should be able to apply those settings and then test the connection.
Add new comment