Bedrock database connection - not using my .env file credentials

Hello,

I’m trying to use bedrock for first time but I have a problem with connecting to the mysql database. My database connection section in .env file looks like this

DB_NAME=‘superproject_name’
DB_USER=‘superproject_user’
DB_PASSWORD=‘mysuperpassword’
DB_HOST=‘localhost’

The credentials are working. I also tried to use the DATABASE_URL method. I also tried changing localhost to 127.0.0.1 and 127.0.0.1::3306 but it doesnt work either.

The weirdest part is it looks like these values aren’t even used - my mysql log shows this:

Connect @localhost on
Connect Access denied for user ‘’@‘localhost’ (using password: NO)

But the .env file should be processed by the sever, because if I try and remove database section from .env file I get a 500 error saying I’m missing DB_NAME for example in my config file.

Do you have any idea what could be causing this problem?

MariaDB 10.1.45, Apache 2.4.25, Debian 9.12

Could you describe how it doesn’t work? It’s not clear to me here where you’re encountering the inability to log in, or what error it’s generating. Is it during the in-browser WordPress setup process? Or somewhere else? The .env file is only going to be parsed by PHP requests running through Bedrock/Wordpress.

I dont even get to the installation process. Everything shows the default WordPress database error in the browser: Error Establishing a Database Connection

Maybe some parsing issue with the .env file?
Try again with an empty example .env file?:

Unfortunatelly it doesn’t work even with fresh .env file … I’ve even tried different web-server with different database credentials … Basically what I do is:

  1. Create database, database user and test the credentials
  2. composer create-project roots/bedrock superweb
  3. Go to superweb.com/web

And here I get this default WP error: https://i.imgur.com/MNnmjO8.png

When I go and investigate what credentials it uses to connect the database I find this line in mysql error log: Connect Access denied for user ‘’@‘localhost’ (using password: NO)

If I try and manually create wp-config.php in /web/wp/wp-config.php and fill in the database credentials - it works and it gets me to the wordpress installation.

The output of $dotenv in application.php looks like this - I think those variables shouldn’t be empty … https://gist.github.com/cafesk8/d2c9f7c751f504255118d9663af9d4e2

Any ideas anybody? Tried different enviroments with the same result …

Some random stabs:

  1. Unicode used in that env file?
  2. *nix line endings used in that env file?
  3. Proper owner/permissions (read) for that env file?
  4. When a VM/container is used, env file correctly mounted into it?

This topic was automatically closed after 42 days. New replies are no longer allowed.

SOLVED
The one and only problem was, that my server had putenv() in disabled_functions in php.ini.

2 Likes