Make WordPress Core

Opened 7 weeks ago

Closed 4 weeks ago

#64014 closed enhancement (fixed)

Optionally expose non-ephemeral MySQL port

Reported by: westonruter's profile westonruter Owned by: westonruter's profile westonruter
Milestone: 6.9 Priority: normal
Severity: normal Version: 5.4
Component: Build/Test Tools Keywords: has-patch commit
Focuses: Cc:

Description (last modified by westonruter)

I've finally sat down to try to get PhpStorm to connect to the MySQL database in the wordpress-develop Docker environment. To do so, I needed to supply the port number for the mysql container. As noted in #48281, this can be done via:

docker-compose port mysql 3306

But it is annoying to have to re-run this to update the port in the PhpStorm database properties each time I start the wordpress-develop environment. Therefore, as with the LOCAL_PORT environment variable in .env for the web server, I suggest there be a LOCAL_DB_PORTS environment variable supported which allows a persistent port mapping to be established for the database:

  • docker-compose.yml

    a b services: 
    7070      - wpdevnet
    7171
    7272    ports:
    73       - "3306"
     73      - "${LOCAL_DB_PORTS-3306}"
    7474
    7575    environment:
    7676      MYSQL_ROOT_PASSWORD: password

With this change in place, I can update my .env to contain:

LOCAL_DB_PORTS="33060:3306"

And then my wordpress-develop mysql container is always accessible from the same 33060 port.

Change History (7)

#1 @westonruter
7 weeks ago

  • Description modified (diff)

This ticket was mentioned in PR #9968 on WordPress/wordpress-develop by @westonruter.


7 weeks ago
#2

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/64014

Given an .env updated to append:

LOCAL_DB_PORTS="33060:3306"

I'm able to configure PhpStorm as follows:

https://github.com/user-attachments/assets/7c62af98-773d-4a78-817d-f860e483dfbb

And I'm then able to access the database:

https://github.com/user-attachments/assets/f661a7ed-056e-41e7-9ae4-775e021c2dd2

@mindctrl commented on PR #9968:


7 weeks ago
#3

Nice, I've confirmed this works as intended. I had done a couple one-off database ops inside the container, and this makes it more pleasurable.

PhpStorm
https://github.com/user-attachments/assets/c239f252-1a4d-4c55-931e-f0844cb1a684

VS Code
https://github.com/user-attachments/assets/9e9214a9-2f4a-46e8-bb9e-912b76604bc2

This ticket was mentioned in Slack in #core by wildworks. View the logs.


4 weeks ago

#5 @wildworks
4 weeks ago

This ticket was featured on today's 6.9 Bug Scrub. The PR has been reviewed, but can we move this ticket forward?

#6 @westonruter
4 weeks ago

  • Keywords commit added

I'll go ahead and commit.

#7 @westonruter
4 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 60926:

Build/Test Tools: Introduce LOCAL_DB_PORTS environment variable.

This change introduces a LOCAL_DB_PORTS environment variable to the wordpress-develop Docker environment. This allows users to establish a persistent port mapping for the MySQL database, making it easier to connect to with development tools like PhpStorm. Otherwise, the default database port is ephemeral.

For example, setting LOCAL_DB_PORTS="33060:3306" in the .env file will make the MySQL container consistently accessible on port 33060.

Developed in https://github.com/WordPress/wordpress-develop/pull/9968.

Props westonruter, mindctrl.
See #48281.
Fixes #64014.

Note: See TracTickets for help on using tickets.