sprintcube/docker-compose-lamp

[BUG] Could not connect to "localhost" wordpress set-up.

t-AIR-e opened this issue · 1 comments

Describe the bug
I could not connect to WordPress using localhost during the installation of WordPress.

which Branch / PHP Version are you using ?
php8

Steps to reproduce
Run docker-compose, and use the sample env variables for my .env
Next, in PHPMyAdmin, create credentials; wordpress_db, wordpress_usr, 12345 (set permissions for database and hostname to %)

Expected behavior

  1. Get and extract WordPress to ./www/wordpress visit localhost/wordpress.
  2. Enter the database details as shown above
  3. Then hit connect, should connect.

** My solution **
Edit line 13 of docker-compose.yml
- database
to
- database:mysql
Now when trying to connect to WordPress I enter, MySQL as the hostname.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: WSL2 Ubuntu
  • Browser Chrome
  • Docker Version: Latest
docker -v
Docker version 20.10.21, build baeda1f

Additional context
Now I don't know if there was an other way of doing this, but using localhost or % during WordPress install didn't work.
extra_hosts: - "host.docker.internal:host-gateway"
From my limited knowledge and googling, this part of the docker-compose file should of solved this issue with connecting to mysql between containers.

i've just had a similar issue: i was moving some existing wordpress dev installs from my previous computer to a new machine, on a fresh docker-compose-lamp env (php8, mariadb106).
After reading this message in issue #204, i gave it a try:

Changing this line
define( 'DB_HOST', 'localhost' );
to:
define( 'DB_HOST', 'database' );
in every wp-config.php did the trick... in a similar way as you solved by adding the 'mysql' pseudo, i guess.
Perhaps you could just try and use 'database' during the install?