ThisCalculator

Everyday

Add phpMyAdmin to WordPress with Docker Compose

Updated · Standard formula, shown below

This guide shows you how to add phpMyAdmin to an existing WordPress setup that runs with Docker Compose. You’ll get a web-based database manager at a URL like http://localhost:8080, where you can browse, edit, and export your WordPress database without installing extra software. You’ll need a docker-compose.yml file that already defines a WordPress service and a MySQL (or MariaDB) service.

What You’ll Need

  • Docker and Docker Compose installed on your machine (check with docker --version and docker compose version).
  • An existing docker-compose.yml file for WordPress that includes a MySQL or MariaDB service.
  • Basic familiarity with editing YAML files and running terminal commands.
  • Port 8080 (or another port you choose) free on your host machine.

Step-by-Step

  1. Locate your docker-compose.yml file. This is usually in the folder where you ran docker compose up. Open it in a text editor.
  2. Identify your database service name. Look for the service that runs MySQL or MariaDB. It’s often named db or database. Note the exact service name; you’ll need it later.
  3. Add a phpMyAdmin service. Under the services: section, add a new block. A typical setup looks like this:
      phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: phpmyadmin
        restart: unless-stopped
        ports:
          - "8080:80"
        environment:
          PMA_HOST: db
          PMA_PORT: 3306
          PMA_ARBITRARY: 1
        networks:
          - your-network-name
        

    Replace db with your actual database service name, and your-network-name with the network name defined in your compose file (often default or a custom one).

  4. Ensure the network is shared. If your compose file doesn’t define a custom network, Docker Compose creates a default network automatically, and all services join it. If you have a custom network, make sure both the database and phpMyAdmin services are attached to it (as shown above).
  5. Check environment variables. The key one is PMA_HOST – it must match your database service name exactly. PMA_PORT is usually 3306 for MySQL/MariaDB. PMA_ARBITRARY set to 1 allows you to enter a hostname manually in the login screen, which is handy for testing.
  6. Save the file. After adding the phpMyAdmin service, save your docker-compose.yml.
  7. Restart your stack. Run docker compose up -d to apply changes. This will create the new phpMyAdmin container and leave your existing WordPress and database containers running (if they were already up).
  8. Verify the container is running. Use docker compose ps to see the status. You should see phpmyadmin listed with an “Up” status.
  9. Access phpMyAdmin. Open your browser and go to http://localhost:8080. If you changed the host port, use that port instead.
  10. Log in. Use the same MySQL credentials you set for WordPress. These are defined in your compose file as environment variables for the database service (e.g., MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE). The username is usually root or the user you created; the host is the database service name (or db).

Common Mistakes

  • Wrong PMA_HOST. Using the container’s IP address instead of the service name is a common error. Docker Compose provides DNS resolution by service name, so always use the service name.
  • Forgetting to attach to the same network. If phpMyAdmin and the database are on different networks, they can’t communicate. Ensure both are on the same network.
  • Port conflict. If port 8080 is already taken, the container won’t start. Change the host port (e.g., "8081:80") or free the port.
  • Using the wrong database user. The WordPress user often only has privileges on the WordPress database. If you try to log in with that user and see “Access denied”, use the root user (with the root password you set) instead.
  • Editing the wrong compose file. Make sure you’re editing the file that Docker Compose actually uses. If you have multiple compose files, check the one in your current directory.

Tips

  • Use a different host port if needed. For example, "8081:80" to avoid conflicts with other services.
  • Set a custom upload limit. If you need to import large SQL files, you can add UPLOAD_LIMIT: 128M to the environment section.
  • Keep phpMyAdmin off the public internet. If your Docker host is exposed, consider binding to localhost only: "127.0.0.1:8080:80".
  • Use a named volume for persistent configuration. Not strictly necessary, but you can mount a volume if you want to keep phpMyAdmin’s config files.
  • Remember to use docker compose down and up if you change network settings. Sometimes a simple up -d doesn’t re-create networks properly.

Troubleshooting

  • Can’t access phpMyAdmin at localhost:8080. Check if the container is running (docker compose ps). If it’s not, view logs with docker compose logs phpmyadmin. Common causes: port conflict, wrong network, or missing image.
  • Login error: “mysqli::real_connect(): (HY000/2002): Connection refused”. This means phpMyAdmin can’t reach the database. Verify that PMA_HOST matches the database service name exactly, and that both services are on the same network.
  • Login error: “Access denied for user”. You’re using the wrong credentials. Check the MYSQL_USER and MYSQL_PASSWORD in your compose file. If you’re using the WordPress user, it may only have access to the WordPress database; try the root user.
  • Blank page or 500 error. Often due to a corrupted config or a missing dependency. Try pulling the latest image (docker compose pull phpmyadmin) and restarting. If you changed environment variables, double-check for typos.
  • Changes to compose file don’t take effect. Run docker compose up -d --force-recreate to force re-creation of containers.
  • phpMyAdmin is slow. This can happen if the database container is on a different network or if there’s a DNS issue. Ensure both are on the same network and consider using the database service name instead of an IP.

Frequently Asked Questions

Do I need to expose the MySQL port to the host?

No. In fact, it’s safer not to. phpMyAdmin communicates with the database over the internal Docker network, so you don’t need to publish the MySQL port (e.g., 3306) to the host.

Can I use phpMyAdmin with MariaDB?

Yes. The phpMyAdmin image works with both MySQL and MariaDB. Just set PMA_HOST to the MariaDB service name and PMA_PORT to 3306 (the default for MariaDB).

How do I change the port phpMyAdmin runs on?

Edit the ports section of the phpMyAdmin service. For example, "8081:80" will make it accessible at http://localhost:8081.

Is it safe to expose phpMyAdmin to the internet?

Generally, no. phpMyAdmin is a common target for brute-force attacks. If you must expose it, use HTTPS and strong passwords, and consider IP whitelisting. For local development, keep it bound to localhost.

Why do I see “Cannot log in to the MySQL server” even though my credentials are correct?

This often happens when the database user is only allowed to connect from a specific host. In Docker, the database service sees the connection coming from the phpMyAdmin container’s IP. Make sure your MySQL user is configured to allow connections from any host (e.g., 'user'@'%') or from the Docker network subnet.

Can I add phpMyAdmin to an existing running stack without downtime?

Yes. Adding a new service and running docker compose up -d will create the new container without stopping the existing ones, as long as you don’t change the database or WordPress service definitions.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.