简体   繁体   中英

Getting nginx environment variable in laravel with cached config

I use laravel framework on 2 websites, The application backend is one, but view paths is different for each site. There is nginx variable "WEBSITE", which is available in PHP (phpinfo prints it). When I run application locally, all is right. But in production, I get exception what variable is not exists.

I discovered what during deploy running command php artisan config:cache, which cached all config in "bootstrap" directory. I don't may delete this command, because it ups performance of site. This command caches all config including app/config/view.php file that descript changes in view paths, like this

'paths' => [
    resource_path('views/' . env('WEBSITE')),
],

but config already cached without variable and in this form is delivered to the production. I don't understand how fix this problem, other that edit all views, base layouts for both sites. Does anyone know how to solve this problem in a simple way?

Just add a fallback by explicitly adding WEBSITE=somewebsiteurl in your production sites.env, then re-cache the config and try if it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM