Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonasm's avatar

Multiple bootstrap/cache/config.php files

Let's say i have one codebase for 500+ clients, based on load balanced web-servers. Each client has their own database, and therefor their own set of credentials.

The easy way here would be to have different .env files with each of the clients credentials and enviornmental settings (this works fine btw), but for optimization reasons, i would like to run the "artisan cache:config" method. This will compile all the config files into a single "config.php" file in /bootstrap/cache".

Now, this is not very functional with lot's of clients. I's it possible to tell Laravel WHERE to look for the cached config file? Without changing core code?

Like defining an enviornmental variable from the vhost "CONFIG_PATH" and (pseudo code)

if( null !== getenv("CONFIG_PATH") && getenv("CONFIG_PATH") != "" ) {
    $app->bootstrapConfigPath( getenv("CONFIG_PATH") );
}

Or is the only possibility to have alot of directories, with each their "Bootstrap/cache" folder, and symlinks to the shared codebase ( Which in my opinion is a rather cumberstone path to walk down )

Thanks in advance.

0 likes
1 reply
tlacaelelrl's avatar

by looking at the source (I have not tested if it works) looks like there is a method called

Foundation/Application.php

    protected function normalizeCachePath($key, $default)
    {
        if (is_null($env = Env::get($key))) {
            return $this->bootstrapPath($default);
        }

        return Str::startsWith($env, $this->absoluteCachePathPrefixes)
                ? $env
                : $this->basePath($env);
    }

which is called when requesting the config.php and other cached files, so you can set environment variables on the server, for each instance run

APP_CONFIG_CACHE=app/caches/site1/config.php APP_CONFIG_CACHE=app/caches/site2/config.php

this is of course if each site runs on its own environment.

Env class === Support/Env.php

Please or to participate in this conversation.