如何在生产和开发中管理不同的 php.ini 设置?

发布于 2024-12-28 11:53:34 字数 395 浏览 0 评论 0原文

是否有管理从开发到生产的 php.ini 配置的最佳实践?显然,这可以手动完成,但这很容易出现人为错误。我想尝试将生产文件置于版本控制中,然后可能自动修改开发版本。 我的想法或想法我不知道它们是否可行:

  1. php.ini 包含 - 只需在末尾包含开发设置 文件?
  2. 从 apache conf 进行条件加载?
  3. 编写一个脚本,当 php.ini 更改时,生成 phpdev.ini 的动态版本 - (我知道这可以完成)
  4. 使用运行时 php 设置来显示错误 - 我认为这有局限性,因为如果脚本有致命错误,那么它不会运行运行时设置。
  5. 备份计划 - 将生产版本保留在 SC 中,并手动更改 phpdev.ini 根据需要按需配置。那么如果人为失误 它们是在开发级别完成的。

Is there a best practice for managing php.ini configurations from development to production? Obviously it can be done manually, but that is prone to human error. I'd like to try and have the production file in version control and then possibly modify the development version automatically.
Thoughts or ideas i've had which i dont know if they are feasible:

  1. php.ini includes - just include the dev settings at the end of
    the file?
  2. conditional loads from apache conf?
  3. write a script that when php.ini changes, a dynamic version of phpdev.ini gets generated - (i know this can be done)
  4. use runtime php settings for display errors - i think this has limitations because if the script has fatal errors, then it wont run the runtime setting.
  5. backup plan - keep the production version in SC, and manually change
    phpdev.ini as needed as needed. Then if manual mistakes are made
    they are done at the development level.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼泪淡了忧伤 2025-01-04 11:53:34
  1. 将您的 ini 存储在源代码存储库中以环境命名的不同目录中:environments/{dev,qa,staging,prod}/php.ini
  2. 在每个环境中,执行以下操作:rm /etc/php.ini; ln -s /var/www/site/environments/prod/php.ini /etc/php.ini

这样,您就可以获得版本控制的好处,而不必手动编辑每个版本。

  1. Store your ini in your source code repository in different directories named after their environments: environments/{dev,qa,staging,prod}/php.ini
  2. On each environment, do this: rm /etc/php.ini; ln -s /var/www/site/environments/prod/php.ini /etc/php.ini

This way, you get the benefits of revision control and don't necessarily have to edit each manually.

同展鸳鸯锦 2025-01-04 11:53:34

我不确切知道这是否是您正在寻找的,但我个人喜欢通过 apache 虚拟主机设置执行所有非安全必要的 php.ini 修改,例如开发虚拟主机:

    ServerName sb.local
    ServerAlias sb.local
    DocumentRoot /srv/some-site

    php_value session.cookie_domain "sb.local"
php_value date.timezone "America/New_York"
php_value mbstring.func_overload 7
php_value default_charset "utf-8"
AddDefaultCharset utf-8 

php_value session.gc_maxlifetime "990000"
php_value error_reporting 30711
# 30711 = E_ALL ^ E_NOTICE
php_value display_errors "On"
php_value display_startup_errors "On"
php_value log_errors "On"
php_value html_errors "On"

I don't know exactly if this is what you're looking for, but personally I like to perform all non-security-necessary php.ini modifications via the apache virtualhost settings, e.g. a development virtualhost:

    ServerName sb.local
    ServerAlias sb.local
    DocumentRoot /srv/some-site

    php_value session.cookie_domain "sb.local"
php_value date.timezone "America/New_York"
php_value mbstring.func_overload 7
php_value default_charset "utf-8"
AddDefaultCharset utf-8 

php_value session.gc_maxlifetime "990000"
php_value error_reporting 30711
# 30711 = E_ALL ^ E_NOTICE
php_value display_errors "On"
php_value display_startup_errors "On"
php_value log_errors "On"
php_value html_errors "On"

etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文