[Windows] Laravel behaving strange on Windows Server

You likely encounter those problem when developing Laravel Application using Windows Machine.

Symptoms:

  • Frequent Apache Crash (Connection reset)
  • “Access denied for user ‘homestead’@’localhost’ (using password: YES)”, even .env is set to different credential
  • .env setting drifting between two separate Laravel installations  (e.g. http://127.0.0.1:8080 .env setting applied to http://127.0.0.1:8081)

Reason:

Because the “dotenv” package, used by Laravel, work in a way that is not thread-safe.

And “Dotenv was never meant to be used in production“.

See: https://github.com/vlucas/phpdotenv/issues/76

Solution 1:

Avoid PHP Apache Module setup in anyway.
If you are using XAMPP for Windows, you are running PHP as Apache Module.
Install a proper WAMP stack: https://blog.tiger-workshop.com/wamp-development-machine-setup-note/

Solution 2:

Run php artisan config:cache to cache .env config.

You will need to run it every time you change the config.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.