In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to configure Laravel 5.3". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
1. Introduction
All configuration files of Laravel are stored in the config directory, and each configuration item has comments to ensure that browsing any configuration file configuration item can intuitively understand the role and usage of the configuration item.
2. Access configuration values
You can use the global helper function config to access configuration values anywhere in the application, which can be filename +". "+ configuration item. When the configuration item is not configured, the default value is returned:
$value = config('app.timezone');
If you want to set configuration values at runtime, pass array parameters to the config method:
config(['app.timezone' => 'America/Chicago']);
3. Environmental configuration
Setting different configuration values based on the environment in which the application runs can bring great convenience to our development. For example, we usually configure different cache drivers in local and online environments, which is easy to implement in Laravel.
Laravel uses the PHP library DotEnv developed by Vance Lucas to implement this mechanism. In a new installation of Laravel, there is an.env.example file in the root directory, which has been renamed to.env if Laravel was installed through Composer, otherwise you have to rename the file manually.
Get environment variable configuration values
Every time your app accepts a request, all the configurations listed in.env and their values are loaded into the PHP superglobal variable $_ENV, which you can then retrieve from your app via the helper function env. In fact, if you look at Laravel's configuration file, you'll see that this helper function is already used in many places:
'debug' => env('APP_DEBUG', false),
The second parameter passed to the env function is the default value, which would be the default value if the environment variable were not configured.
Do not submit.env files to source control (svn or git, etc.), as each developer/server using your application may require different environment configurations.
If you are developing on a team, you need to submit the.env.example file to source control along with your app: put some configuration values in the.env.example file as placeholders so that other developers know exactly what environment variables are needed to run your app.
Determine the current application environment
The current app environment is determined by the APP_ENV variable in the.env file, which you can access via the App Facade environment method:
$environment = App::environment();
You can also pass parameters to the environment method to determine whether the current environment matches a given value, and you can even pass multiple values if desired. This method returns true if the current environment matches the given value:
if (App::environment('local')) { // The environment is local}if (App::environment('local', 'staging')) { // The environment is either local OR staging...}
Application instances can also be accessed via the helper function app:
$environment = app()->environment();
4. Configuration cache
To speed up your application, you can use Artisan config:cache to cache all configuration files into a single file, which consolidates all configuration options into a single file that can be loaded quickly by the framework.
Once your app is live, you run php artisan config:cache once, but you don't need to run this command as often when developing locally, because configuration values often need to change.
5. Maintenance mode
When your app is in maintenance mode, all requests to your app return the same custom view. This mechanism makes it easy to "shut down" a site when upgrading or maintaining an application. The code for determining maintenance mode is located in the default middleware stack of the application. If the application is in maintenance mode, a MaintenanceModeException with status code 503 will be thrown.
To turn on maintenance mode, simply execute Artisan command down:
php artisan down
To turn off maintenance mode, the corresponding Artisan command is up:
php artisan up
Maintenance Mode Response Template
The default maintenance mode response view template is resources/views/errors/503.blade.php
Maintenance Mode & Queue
When your site is in maintenance mode, all queued tasks will not be executed; when the application exits maintenance mode, these tasks will continue to be processed normally.
Alternatives to Maintenance Mode
Since maintenance mode commands take a few seconds to execute, you might consider using Envoy to achieve a 0-second offline as an alternative.
"How to configure Laravel 5.3" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.