Configuration

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

After Installation

After installing Laravel, you may wish to "name" your application. By default, the app directory is namespaced under App, and autoloaded by Composer using the . However, you may change the namespace to match the name of your application, which you can easily do via the app:name Artisan command.

For example, if your application is named "Horsefly", you could run the following command from the root of your installation:

Renaming your application is entirely optional, and you are free to keep the App namespace if you wish.

Other Configuration

Laravel needs very little configuration out of the box. You are free to get started developing! However, you may wish to review the config/app.php file and its documentation. It contains several options such as timezone and locale that you may wish to change according to your location.

Once Laravel is installed, you should also .

Laravel may require one set of permissions to be configured: folders within storage and vendor require write access by the web server.

You may easily access your configuration values using the Config facade:

  1. $value = Config::get('app.timezone');
  2. Config::set('app.timezone', 'America/Chicago');
  1. $value = config('app.timezone');

Environment Configuration

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. It's easy using environment based configuration.

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 .env.example file. If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.

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

Feel free to modify your environment variables as needed for your own local server, as well as your production environment. However, your .env 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 .env.example 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.

Accessing The Current Application Environment

You may access the current application environment via the environment method on the Application instance:

You may also pass arguments to the environment method to check if the environment matches a given value:

  1. if ($app->environment('local'))
  2. {
  3. // The environment is local
  4. if ($app->environment('local', 'staging'))
  5. {
  6. // The environment is either local OR staging...
  7. }

To obtain an instance of the application, resolve the Illuminate\Contracts\Foundation\Application contract via the service container. Of course, if you are within a , the application instance is available via the $this->app instance variable.

An application instance may also be accessed via the app helper or the App facade:

  1. $environment = App::environment();

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

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, an HttpException will be thrown with a status code of 503.

To enable maintenance mode, simply execute the down Artisan command:

To disable maintenance mode, use the up command:

  1. php artisan up

Maintenance Mode Response Template

The default template for maintenance mode responses is located in resources/views/errors/503.blade.php.

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.

Apache

The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:

  1. Options +FollowSymLinks
  2. RewriteEngine On
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteCond %{REQUEST_FILENAME} !-f

If your web host doesn't allow the option, try replacing it with Options +SymLinksIfOwnerMatch.

On Nginx, the following directive in your site configuration will allow "pretty" URLs:

Of course, when using , pretty URLs will be configured automatically.