Error establishing a database connection right after installation (at first click to login page)

Bedrock Version

1.25.0

What did you expect to happen?

I expected to see the WP admin login page

What actually happens?

I got the “Error establishing a database connection”

Steps to reproduce

I installed bedrock via composer
I configured my .env file

I went through the wordpress installation (choose language, then sitename, username, password and email)

And at first try to log in after successful installation, I got the error : “Error establishing a database connection”

I repeated the process many times and always the same error

System info

Xampp for Windows 10 (22H2)
PHP 8.2.12
Apache/2.4.58 (Win64)
Database client version: libmysql - mysqlnd 8.2.12

Thanks for help

Hi there,
As far as I’m concerned, there must be a problem connecting to your database.
It’s an error generated by WordPress.
Are you sure of the info in your .env?

Hi there, Thank you for your reply.

I am sure it is not related to the database or credentials. Here is why:

  1. As I explained, the error happened right after a successful wp installation when I clicked on the login link at the bottom of “successful installation” page. If my “.env” was erroneous, I wouldn’t be able to install WP.
  2. I created a simple test.php page to test my credentials connecting to database and it connected successfully.

And the problem occured many times (I can say at least 7), so I posted my question on this forum.

br

I would recommend to search for ”Error establishing a database connection” in the WP core files and then debug from there.

That message can occur even if the problem isnt really with the database connection, for example if you are running a multisite with wrong values in wp_blogs/wp_site.

1 Like

Thanks folbert for pointing debugging.

The problem was that at certain point in wp-includes/functions.php, wordpress looks for the ‘siteurl’ from ‘wp_options’ table, but for some reason this option was not populated during installation process!

The solution was that I populated my ‘home’ and ‘siteurl’ variables in the ‘wp_options’ table using phpmyadmin and voila. Now I can see the wordpress login form.
‘home’ is normally for homepage address, and ‘siteurl’ is for the wp core files: {home}/wp.

Regards.