注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

和申的个人主页

专注于java开发,1985wanggang

 
 
 

日志

 
 

2. Getting Started- Configuration 配置  

2017-03-04 17:40:20|  分类: Laravel |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Laravel
配置

Configuration

介绍

Introduction

Laravel 框架使用的全部配置文件都存储在config目录下面。每个选项都是有文档,因此,可以轻松的通过查找文件来熟悉可用选项功能。

All of the configuration files for the Laravel framework are stored in the de >configde> directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

环境配置

Environment Configuration

环境配置对与基于不同应用运行环境有不同配置值的的非常有用。例如,你可能希望本地开发使用其他的缓存驱动,而不是同你生成环境一样的驱动。为了实现这一的目标,Laravel 利用 DotEnv php 库(PHP library )实现(万斯卢卡斯 开发的DotEnv 库 https://github.com/vlucas/phpdotenv)。在Laravel 刚刚安装的时候,你应用的根目录可能会包含一个 .env.example 文件。 如何你通过 Composer安装的 Laravel

It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver locally than you do on your production server.

To make this a cinch, Laravel utilizes the DotEnv PHP library by Vance Lucas. In a fresh Laravel installation, the root directory of your application will contain a de >.env.examplede> file. If you install Laravel via Composer, this file will automatically be renamed to de >.envde>. Otherwise, you should rename the file manually.

You may also create a de >.env.testingde> file. This file will override values from the de >.envde> file when running PHPUnit tests or executing Artisan commands with the de >--env=testingde>option.

Retrieving Environment Configuration

All of the variables listed in this file will be loaded into the de >$_ENVde> PHP super-global when your application receives a request. However, you may use the de >envde> helper to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice several of the options already using this helper:

de  >'debug' => env('APP_DEBUG', false),de>

The second value passed to the de >envde> function is the "default value". This value will be used if no environment variable exists for the given key.

Your de >.envde> file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration.

If you are developing with a team, you may wish to continue including a de >.env.examplede> file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application.

Determining The Current Environment

The current application environment is determined via the de >APP_ENVde> variable from your de >.envde> file. You may access this value via the de >environmentde> method on the de >Appde> facade:

de  >$environment = App::environment();de>

You may also pass arguments to the de >environmentde> method to check if the environment matches a given value. The method will return de >truede> if the environment matches any of the given values:

de  >if (App::environment('local')) {
    // The environment is local
}

if (App::environment('local', 'staging')) {
    // The environment is either local OR staging...
}de>

Accessing Configuration Values

You may easily access your configuration values using the global de >configde> helper function from anywhere in your application. The configuration values may be accessed using "dot" syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:

de  >$value = config('app.timezone');de>

To set configuration values at runtime, pass an array to the de >configde> helper:

de  >config(['app.timezone' => 'America/Chicago']);de>

Configuration Caching

To give your application a speed boost, you should cache all of your configuration files into a single file using the de >config:cachede> Artisan command. This will combine all of the configuration options for your application into a single file which will be loaded quickly by the framework.

You should typically run the de >php artisan config:cachede> command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.

If you execute the de >config:cachede> command during your deployment process, you should be sure that you are only calling the de >envde> function from within your configuration files.

Maintenance Mode

When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a de >MaintenanceModeExceptionde>will be thrown with a status code of 503.

To enable maintenance mode, simply execute the de >downde> Artisan command:

de  >php artisan downde>

You may also provide de >messagede> and de >retryde> options to the de >downde> command. The de >messagede> value may be used to display or log a custom message, while the de >retryde> value will be set as the de >Retry-Afterde>HTTP header's value:

de  >php artisan down --message="Upgrading Database" --retry=60de>

To disable maintenance mode, use the de >upde> command:

de  >php artisan upde>

Maintenance Mode Response Template

The default template for maintenance mode responses is located in de >resources/views/errors/503.blade.phpde>. You are free to modify this view as needed for your application.

Maintenance Mode & Queues

While your application is in maintenance mode, no queued jobs will be handled. The jobs will continue to be handled as normal once the application is out of maintenance mode.

Alternatives To Maintenance Mode

Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like Envoyer to accomplish zero-downtime deployment with Laravel.

  评论这张
 
阅读(111)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017