1

I have a very strange problem with Laravel and Lumen apps on WAMP virtual hosts. In short the problem is the DB credentials from Laravel app overwrite these on Lument app while in an HTTP request. This causes the Lumen app to throw MySQL Access denied error.

My Setup

I am under WAMP on my local dev machine, two virtual hosts established. One for Laravel app (say laravel.localhost, web application), another for Lumen app (lumen.localhost, web service, API). Both apps are served via Apache virtual hosts from different hard disk folders.

Both apps have different .env configs. On Laravel app the DB config is not configured (a defaut one is kept, not using a DB). On Lumen app the database access to specific DB configured. Both use default DB config part:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306

but of course different DB names and credentials.

Access denied for user 'root'@'localhost'

The issue comes as soon as from browser (!) or from Postman (!) I make an HTTP request from laravel.localhost to lumen.localhost. I receive a request on Lumen app side and I connect to DB. Then Access denied for user 'root'@'localhost' SQL error comes.

If I inspect the database connection on the Lumen app side (config('database.connections.mysql')), it shows the DB credentials from Laravel app side which is a big surprise for me.

Of course, as Lumen app has different DB credentials, the Laravel app's DB credentials cause the Access denied error.

Another side of this effect is if I put Lumen app's DB credentials into Laravel app .env the HTTP request goes with no errors.

Strange Behaviour

This all makes me think that these both apps somehow share the same PHP or PDO or whatever environment the Larevel DB config is kept in. And this behaviour is very strange.

On the contrary, if I make the same HTTP requests from my PHPUnit tests from Laravel app to Lumen app there is no issue.

Clearing Laravel caches does not help. The Laravel app DB credentials are not cached. I may change them before each request and they leak into the Lumen app's side "with" the request.

Anybody can help?

Valentine Shi
  • 6,604
  • 4
  • 46
  • 46
  • 1
    I suspect that your problem relates to [this](https://stackoverflow.com/questions/51846513/wamp-laravel-sending-api-requests-from-one-local-site-to-another-mixes-up-envi/52052556#52052556) problem that arises as a mix-up between environments. You may try the solution proposed there (cache the configuration) and seek for more information about the issue, and how it can be solved. It would be better here if I provide an answer as a "Duplicate of", but alas I cannot put enough description in comments :) – Daniel Protopopov Mar 21 '20 at 12:28
  • @Daniel Protopopov, thanks a lot. Unfortunately the bounty was not awarder. Yet I am very grateful to you! – Valentine Shi Mar 21 '20 at 14:04
  • No worries, glad to help! – Daniel Protopopov Mar 21 '20 at 14:24

0 Answers0