1

I'm working on a new project with Lumen and just noticed that the .env configuration sometimes doesn't work. It then uses the default locale and database settings, instead of mine.

I already tried to clear the cache and set the environment to production, but none of these have solved my problem.

APP_NAME=Lumen
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOCALE=de
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

Instead of applying the locale and database configuration, it sometimes just uses the default configuration, as if the .env wasn't there.

An example of the error that sometimes occurs:

SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'
Robin
  • 11
  • 8
  • https://stackoverflow.com/questions/29986626/pdoexception-1044-sqlstatehy000-1044-access-denied-for-user-localhost – Rashed Hasan Sep 28 '19 at 18:05
  • @RashedHasan I'm not missing the .env file, neither is the database configuration missing or incorrect (as it is working sometimes). – Robin Sep 28 '19 at 18:10
  • `sometimes doesn't work`- when? Doing what, exactly? Is it reproducible? – Don't Panic Sep 28 '19 at 18:11
  • It's just happening randomly when loading the page. – Robin Sep 28 '19 at 18:16
  • I faced same problem, then `php artisan config:cache` `php artisan config:clear` `php artisan cache:clear` worked for me. Would you please have a look to - https://laracasts.com/discuss/channels/general-discussion/env-not-reading-variables-sometimes – Rashed Hasan Sep 28 '19 at 18:29
  • 2
    Lumen doesn't have these artisan commands. Only `php artisan cache:clear` seems to work, but did not solve my problem. – Robin Sep 28 '19 at 18:40
  • 1
    @Robin Did you manage to solve this problem? I´m in exactly the same situation with Lumen 7.x... – Randolf Feb 15 '21 at 11:11
  • @Randolf Yes I did. It turned out that it was because of the Apache web server. With Nginx the problem did not occur anymore. – Robin Nov 15 '21 at 02:33

0 Answers0