laravel 总是必须清除 .env 中的缓存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43026069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:42:08  来源:igfitidea点击:

Always have to clear cache in .env?

laravellaravel-5.3

提问by Steve

I am having a cache issue. I have a project and worked on local. Now whenever i upload to server and edit the .envand config/app.phpfile. It is not taking the effect.

我有缓存问题。我有一个项目并在本地工作。现在每当我上传到服务器并编辑.envconfig/app.php文件。它没有发挥作用。

But, if i set the .envconfiguartions of server in local and cleared the cache using php artisan config:cacheand upload it to server. It works. Should i always do this method?

但是,如果我.env在本地设置服务器的配置并使用清除缓存php artisan config:cache并将其上传到服务器。有用。我应该总是这样做吗?

So everytime i need change .envi should first change it in local and clear the cache and upload in server? Or is there any method to directly command on server.

所以每次我需要更改时,.env我应该先在本地更改并清除缓存并上传到服务器?或者有什么方法可以直接在服务器上命令。

And again, in another project. Editing .envand config/app.phpfile directly in server takes immediate effect. What is happening?

再一次,在另一个项目中。直接在服务器中编辑.envconfig/app.php归档会立即生效。怎么了?

回答by Sanzeeb Aryal

With php artisan config:cache, you are first clearing the cache, and then setting the cache. You shoud get the message:

使用php artisan config:cache,您首先清除缓存,然后设置缓存。你应该得到消息:

Configuration cache cleared!

Configuration cached Successfully!

配置缓存已清除!

配置缓存成功!

Now, if you upload to server and edit .envfrom there, it will not take immediate effect because of the configuration is cached.

现在,如果你上传到服务器并.env从那里编辑,它不会立即生效,因为配置被缓存。

Solution: Only clear the cache: php artisan config:clearand php artisan cache:clear. Now you can upload to server and edit .envfile from server with immediate effect because the Configuration is not cached.

解决方案:只清除缓存:php artisan config:clearphp artisan cache:clear。现在您可以立即上传到服务器并.env从服务器编辑文件,因为配置没有被缓存。

回答by MoPo

Check APP_ENV in your .env file. If it's on production then yes, laravel caching it. You should run these commands before changing configs:

检查 .env 文件中的 APP_ENV。如果它在生产中,那么是的,laravel 缓存它。您应该在更改配置之前运行这些命令:

php artisan cache:clear
php artisan config:clear
php artisan route:clear

And then after changes run these:

然后在更改后运行这些:

php artisan config:cache
php artisan route:cache
php artisan optimize

回答by Jasbin Karki

I tried the following things and it worked for me

我尝试了以下事情,它对我有用

1.first turn off artisan server and make changes to envfile and

1.首先关闭artisan服务器并更改env文件和

2.run these commands

2.运行这些命令

php artisan cache:clear
php artisan config:clear
php artisan route:clear

3.run

3.运行

php artisan serve

Now it should work

现在它应该工作

回答by Maulik Shah

php artisan config:clear

php artisan cache:clear 

php artisan config:cache

If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

如果在部署期间使用 config:cache 命令,则必须确保仅从配置文件中调用 env 函数,而不是从应用程序的其他任何位置调用。

If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

如果您从应用程序中调用 env,强烈建议您将适当的配置值添加到配置文件中,然后从该位置调用 env,从而允许您将 env 调用转换为配置调用。

Read whole thread over https://github.com/laravel/framework/issues/21727

通过https://github.com/laravel/framework/issues/21727阅读整个线程

回答by tanderson

If you are using a queue driver with a supervisor, then your .envvariables loaded in queue functions will be cached until you restart supervisor.
In my case, I had changed some mail env variables and was confused why clearing the cache/config was not working on the remote server whereas local was working fine until I realized my local queue driver was processing mail synchronously, whereas remote server was using the queue for sending mail.

如果您使用带有主管的队列驱动程序,则.env加载到队列函数中的变量将被缓存,直到您重新启动主管。
就我而言,我更改了一些邮件环境变量,并且很困惑为什么清除缓存/配置在远程服务器上不起作用而本地工作正常,直到我意识到我的本地队列驱动程序正在同步处理邮件,而远程服务器正在使用发送邮件的队列。