#Laravel does not use database password

22 messages · Page 1 of 1 (latest)

frank grail
#

I get an
SQLSTATE[HY000] [1045] Access denied for user 'efhjuef'@'192.168.176.3' (using password: NO)
failure on my laravel website, but I give a password in the env file. So I expect (using password: YES)
Why did laravel not use the password by connection?

My .env file:
DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=efhjuef
DB_PASSWORD=qfk39WtcTTb

nocturne raptor
#

Make sure your config is not cached php artisan config:clear if you're in a local environnement or in production to re-cache php artisan config:cache.

frank grail
nocturne raptor
#

And ?

frank grail
#

Get same result

#

But The password is empty jet

nocturne raptor
#

You're talking about container, is your password passed as a secret -e environnement variable ?

frank grail
#

mom wrong project

frank grail
nocturne raptor
frank grail
#

environment:
- DB_HOST=mariadb
- DB_PORT=3306
- DB_USERNAME=$MARIADB_USER
- DB_DATABASE=$MARIADB_DATABASE
- DB_PASSWORT=$MARIADB_PASSWORD

DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=efhjuef
DB_PASSWORD=qfk39WtcTTb

nocturne raptor
#

May I see your config/database.php file ?

frank grail
#

'password' => env('DB_PASSWORD', ''),

nocturne raptor
#

Do you have access to your password through a tinker session ?

config('database.mariadb.password'); 

I'm guessing your connection name is mariadb, change it if it's called something else.

frank grail
#

it says null

#

Psy Shell v0.11.9 (PHP 8.1.13 — cli) by Justin Hileman

config('database.mariadb.password');
= null

nocturne raptor
#
  • Exit your tinker session.
  • php artisan config:cache
  • try again
frank grail
#

null

#

with this in database.php
'password' => 'qfk39WtcTTb',

nocturne raptor
#

I have never used containers/pods/etc. in production, I know it's not meant to update its code so I do not how to properly handle changes.

Can you now test to retrieve your password from the env file. To do that:

  • clear your config cache php artisan config:cache
  • tinker session

env('DB_PASSWORD')

frank grail
#

it's null
It must be an vault or feature in the bitnami/laravel image
I create it this environment with normal nginx container
Thank you for analyse

nocturne raptor
#

Ho sorry I wrote php artisan config:cache when I wanted you to clear it php artisan config:clear. env() will always return null if the config if cached.