File env bị ẩn làm thế nào để thấy laravel năm 2024
All of the configuration files for the Laravel framework are stored in the
Show 1 directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you. These configuration files allow you to configure things like your database connection information, your mail server information, as well as various other core configuration values such as your application timezone and encryption key. Application OverviewIn a hurry? You can get a quick overview of your application's configuration, drivers, and environment via the
2 Artisan command: If you're only interested in a particular section of the application overview output, you may filter for that section using the
3 option:
Or, to explore a specific configuration file's values in detail, you may use the
4 Artisan command:
Environment ConfigurationIt is often helpful to have different configuration values based on the environment where the application is running. 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. In a fresh Laravel installation, the root directory of your application will contain a
5 file that defines many common environment variables. During the Laravel installation process, this file will automatically be copied to
6. Laravel's default
6 file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the
1 directory using Laravel's
9 function. If you are developing with a team, you may wish to continue including a
5 file with your application. By putting placeholder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application. [!NOTE] Environment File SecurityYour
6 file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed. However, it is possible to encrypt your environment file using Laravel's built-in . Encrypted environment files may be placed in source control safely. Additional Environment FilesBefore loading your application's environment variables, Laravel determines if an
3 environment variable has been externally provided or if the
4 CLI argument has been specified. If so, Laravel will attempt to load an
5 file if it exists. If it does not exist, the default
6 file will be loaded. Environment Variable TypesAll variables in your
6 files are typically parsed as strings, so some reserved values have been created to allow you to return a wider range of types from the
8 function:
6 Value
8 Value true (bool) true (true) (bool) true false (bool) false (false) (bool) false empty (string) '' (empty) (string) '' null (null) null (null) (null) null If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes:
Retrieving Environment ConfigurationAll of the variables listed in the
6 file will be loaded into the
2 PHP super-global when your application receives a request. However, you may use the
9 function to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice many of the options are already using this function:
The second value passed to the
9 function is the "default value". This value will be returned if no environment variable exists for the given key. Determining the Current EnvironmentThe current application environment is determined via the
3 variable from your
6 file. You may access this value via the
7 method on the
8 facade:
You may also pass arguments to the
7 method to determine if the environment matches a given value. The method will return
0 if the environment matches any of the given values:
[!NOTE] Encrypting Environment FilesUnencrypted environment files should never be stored in source control. However, Laravel allows you to encrypt your environment files so that they may safely be added to source control with the rest of your application. EncryptionTo encrypt an environment file, you may use the
2 command: Running the
2 command will encrypt your
6 file and place the encrypted contents in an
5 file. The decryption key is presented in the output of the command and should be stored in a secure password manager. If you would like to provide your own encryption key you may use the
6 option when invoking the command:
[!NOTE] If your application has multiple environment files, such as
6 and
0, you may specify the environment file that should be encrypted by providing the environment name via the
4 option:
DecryptionTo decrypt an environment file, you may use the
2 command. This command requires a decryption key, which Laravel will retrieve from the
3 environment variable: Or, the key may be provided directly to the command via the
6 option:
When the
2 command is invoked, Laravel will decrypt the contents of the
5 file and place the decrypted contents in the
6 file. The
8 option may be provided to the
2 command in order to use a custom encryption cipher:
If your application has multiple environment files, such as
6 and
0, you may specify the environment file that should be decrypted by providing the environment name via the
4 option:
0 In order to overwrite an existing environment file, you may provide the
3 option to the
2 command:
1 Accessing Configuration ValuesYou may easily access your configuration values using the global
1 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:
2 To set configuration values at runtime, pass an array to the
1 function:
3 Configuration CachingTo give your application a speed boost, you should cache all of your configuration files into a single file using the
7 Artisan command. This will combine all of the configuration options for your application into a single file which can be quickly loaded by the framework. You should typically run the
8 command as part of your production deployment process. 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. Once the configuration has been cached, your application's
6 file will not be loaded by the framework during requests or Artisan commands; therefore, the
9 function will only return external, system level environment variables. For this reason, you should ensure you are only calling the
9 function from within your application's configuration (
1 function . The
4 command may be used to purge the cached configuration: [!WARNING] Debug ModeThe
9 option in your
0 configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the
1 environment variable, which is stored in your
6 file. [!WARNING] Maintenance ModeWhen 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
7 instance will be thrown with a status code of 503. To enable maintenance mode, execute the
8 Artisan command: If you would like the
9 HTTP header to be sent with all maintenance mode responses, you may provide the
00 option when invoking the
8 command. The
9 header will instruct the browser to automatically refresh the page after the specified number of seconds:
4 You may also provide a
03 option to the
8 command, which will be set as the
05 HTTP header's value, although browsers generally ignore this header:
5 Bypassing Maintenance ModeTo allow maintenance mode to be bypassed using a secret token, you may use the
06 option to specify a maintenance mode bypass token:
6 After placing the application in maintenance mode, you may navigate to the application URL matching this token and Laravel will issue a maintenance mode bypass cookie to your browser:
7 If you would like Laravel to generate the secret token for you, you may use the
07 option. The secret will be displayed to you once the application is in maintenance mode:
8 When accessing this hidden route, you will then be redirected to the
08 route of the application. Once the cookie has been issued to your browser, you will be able to browse the application normally as if it was not in maintenance mode. [!NOTE] Pre-Rendering the Maintenance Mode ViewIf you utilize the
11 command during deployment, your users may still occasionally encounter errors if they access the application while your Composer dependencies or other infrastructure components are updating. This occurs because a significant part of the Laravel framework must boot in order to determine your application is in maintenance mode and render the maintenance mode view using the templating engine. For this reason, Laravel allows you to pre-render a maintenance mode view that will be returned at the very beginning of the request cycle. This view is rendered before any of your application's dependencies have loaded. You may pre-render a template of your choice using the
8 command's
13 option:
9 Redirecting Maintenance Mode RequestsWhile in maintenance mode, Laravel will display the maintenance mode view for all application URLs the user attempts to access. If you wish, you may instruct Laravel to redirect all requests to a specific URL. This may be accomplished using the
14 option. For example, you may wish to redirect all requests to the
08 URI:
0 Disabling Maintenance ModeTo disable maintenance mode, use the
16 command: [!NOTE] Maintenance Mode and QueuesWhile 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 ModeSince maintenance mode requires your application to have several seconds of downtime, consider alternatives like Laravel Vapor and Envoyer to accomplish zero-downtime deployment with Laravel. |