您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
laravel环境变量的原理、优势及项目配置
发布时间:2024-10-26 19:06:16编辑:雪饮阅读()
-
Environment Based Configuration
Since many of Laravel's configuration option values may vary depending on whether your application is running on your local machine or on a production web server, many important configuration values are defined using the file that exists at the root of your application..env
Your 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..env
For more information about the file and environment based configuration, check out the full .envconfiguration documentation.
基于环境的配置
由于 Laravel 的许多配置选项值可能会有所不同,具体取决于您的应用程序是在本地计算机上运行还是在生产 Web 服务器上运行,因此许多重要的配置值都是使用应用程序根目录中的文件定义的。.env
您的文件不应提交到应用程序的源代码控制中,因为使用您的应用程序的每个开发人员/服务器可能需要不同的环境配置。此外,如果入侵者获得了对您的源代码控制存储库的访问权限,这将带来安全风险,因为任何敏感凭证都会被暴露。.env
有关基于文件和环境的配置的更多信息,请查看完整的.env配置文档.
Environment Configuration
It 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 file that defines many common environment variables. During the Laravel installation process, this file will automatically be copied to ..env.example.env
Laravel's default 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 directory using Laravel's function..envconfigenv
If you are developing with a team, you may wish to continue including a 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..env.example
Any variable in your file can be overridden by external environment variables such as server-level or system-level environment variables..env
环境配置
根据应用程序运行环境使用不同的配置值通常很有帮助。例如,您可能希望在本地使用与在 生产服务器上不同的缓存驱动程序。
为了简化这一点,Laravel 利用了DotEnv (点环境)PHP 库。在全新的 Laravel 安装中,应用程序的根目录将包含一个定义许多常见环境变量的文件。在 Laravel 安装过程中,此文件将自动复制到 。.env.example.env
Laravel 的默认文件包含一些常见的配置值,这些值可能会因您的应用程序是在本地运行还是在生产 Web 服务器上运行而有所不同。然后使用 Laravel 的函数从目录中的各种 Laravel 配置文件中检索这些值。.envconfigenv
如果您正在与团队一起开发,您可能希望继续在应用程序中包含文件。通过将占位符值放在示例配置文件中,您团队中的其他开发人员可以清楚地看到运行应用程序需要哪些环境变量。.env.example
文件中的任何变量都可以被外部环境变量(如服务器级或系统级环境变量)覆盖。.env
Environment File Security
Your 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..env
However, it is possible to encrypt your environment file using Laravel's built-in environment encryption. Encrypted environment files may be placed in source control safely.
环境文件安全
您的文件不应提交到应用程序的源代码控制中,因为使用您的应用程序的每个开发人员/服务器可能需要不同的环境配置。此外,如果入侵者获得了对您的源代码控制存储库的访问权限,这将带来安全风险,因为任何敏感凭证都会被暴露。.env
但是,可以使用 Laravel 的内置环境加密.加密的环境文件可以安全地置于源代码控制中。
本期词汇
Since 因为,由于
cinch (非正式)极其容易做的事情
Furthermore 此外,而且
关键字词:laravel,环境变量