[RESOLVED] Wordpress - Error establish a database connection

Wordpress compose did not work correctly

I tried it on an installation with Ubuntu 22.04 lts, and apparently it had installed successfully.

1.When I clicked this message appeared: “Error establishing a database connection”.

1.1. So I went to check the environmental variables, they were correct.

1.2. I checked the web ui connections, network, ports, everything was fine.

1.3. I went to check the wp-config.php and wp-config-docker.php files, they were wrong.

1.3.1. Then I edited these parameters based on the configured environmental variables:

define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'insert') );

define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'insert') );

define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'insert') );

define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'insert') );

$table_prefix = getenv_docker('WORDPRESS_TABLE_PREFIX', 'insert');
  • it still didn’t work.

1.4. So I went to mysql and the folder had nothing (it just created the folder).

1.5. So I decided to install it separately.

1.5.1. First mysql with its database, network (bridge) and ports settings.

1.5.2. Then wordpress: With the environmental variables, it worked. Without the environmental variables (internal configuration), it worked.

So I tested it on a machine with Debian 11 and compose worked perfectly.

  • I didn’t understand the error, but if anyone has this problem, I solved it like this, if anyone has another solution please share.

@omegas32 I am also facing issues with MYSQL, If you check logs it’s showing mkdir: cannot create directory ‘/var/lib/mysql’: File exists. Looking like the issue with the volume mount for MySQL database

@Mayur_Deore This is an issue with Docker not having permission to create the directory on the host machine at /DATA/AppData/big-bear-wordpress/mysql.

Check Directory Permissions: Use the ls -ld command to check the permissions of this directory.

For example:

ls -ld /DATA/AppData/big-bear-wordpress/mysql

This command will output information, including the permissions, owner, and group of the directory.

Also, do you all have external hard drives mounted to the /DATA/AppData/*?

@omegas32 Do you know if you’re getting the same error as @Mayur_Deore?

No, mine just created a folder called mysql, but it was empty.

@omegas32 Can you look at the logs on the MySQL container and post your errors?

I followed the logs tutorial, and I found that the problem was related to permissions, so I configured the pgid and puid in the service db and it worked.