run a wordpress app (Error establishing a database connection)

Trying to run a wordpress app, https://flywptest.fly.dev/, but cannot figure out how to connect to a fly my-sql database.

In wp-config.php what should the database hostname be if my database app is https://flywordpressdb.fly.dev?

I’ve tried these variations with no luck

/** Database hostname */
define( 'DB_HOST', 'https://flywordpressdb.fly.dev' );

/** Database hostname */
define( 'DB_HOST', 'flywordpressdb.internal' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

fly.toml for https://flywptest.fly.dev/ is:

# fly.toml app configuration file generated for flywptest on 2025-04-14T09:55:23-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'flywptest'
primary_region = 'lax'

[build]
  image = 'wordpress'

[http_service]
  internal_port = 80
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ['app']

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

[env]
  WORDPRESS_DB_NAME= "local"
  WORDPRESS_DB_HOST= "flywordpressdb.internal"
  WORDPRESS_CONFIG_EXTRA = "define( 'WP_HOME', 'https://flywptest.fly.dev' );define( 'WP_SITEURL', 'https://flywptest.fly.dev');"

fly.toml for https://flywordpressdb.fly.dev](https://flywordpressdb.fly.dev is

# fly.toml app configuration file generated for flywordpressdb on 2025-04-14T09:36:24-07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'flywordpressdb'
primary_region = 'lax'

[build]
  image = 'mysql:8'

[[vm]]
  memory = '1gb'
  cpu_kind = 'shared'
  cpus = 1

[processes]
  app = """--datadir /data/mysql \
    --default-authentication-plugin mysql_native_password"""

[mounts]
  source = "mysqldata"
  destination = "/data"

[env]
  MYSQL_DATABASE = "local"
  MYSQL_USER = "wordpressdeveloper"

A good trick is to get an SSH console into your web server, and then use mysql at the command line to help search for the right parameters. The syntax roughly is:

mysql -h hostname -u username -p database

And it should prompt for the password.

Also make sure you can shell into MySQL and connect remotely; if you can’t connect there then you have a different kind of problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.