I came across a confusing and frustrating problem with Laravel that might catch a few people out. I have a single server running both the staging and production versions of the same Laravel-based website. Their
.env files have the same
APP_NAME – because they are the same application – and have the appropriate
Usefully Laravel prefixes cache, session data and redis keys, so they are unique per application you're using. That's nice. However, the problem here is that – by default – these prefixes only use the
APP_NAME to make them unique.
You are able to override these prefixes with more
.env keys (
SESSION_COOKIE), but how many people configure these? I think taking into account the
APP_ENV might be a decent solution.
Currently, the prefixes are built like this;
Str::slug(env('APP_NAME', 'laravel'), '_').'_cache';
However, it would be nice if they looked like this;
Str::of(env('APP_NAME', 'laravel')) ->append(env('APP_ENV', 'production')) ->append(' cache') ->slug('_') ->value();
Takeaway: Make sure your
APP_NAME is different for every application on your server else you might encounter unexpected conflicts.