【问题标题】:Handling the Drupal settings.php file when using Git across multiple servers跨多个服务器使用 Git 时处理 Drupal settings.php 文件
【发布时间】:2013-02-11 17:18:51
【问题描述】:

我们的许多网站都使用 Drupal 6。我们正在将它们全部移入 Git 以进行版本控制。每个站点将有一个开发服务器、一个测试服务器和一个实时服务器。我想知道处理 settings.php 文件的最佳实践,因为数据库连接信息在服务器之间显然会有所不同。我见过从 switch 语句到包含文件的解决方案。此处所述的包含文件解决方案http://drupaldork.com/2011/11/local-settings-development-sites 似乎是一个很好的解决方案,但我想知道您最终在 ACTUAL settings.php 文件中留下了什么。换句话说,如果每个服务器都有一个“本地”设置文件,如 settings.local.php,其中包含该特定服务器的连接信息,你是否从真正的根 settings.php 中删除连接信息?还是你离开它?如果你离开它,你在那儿放什么?这是否重要,因为它最终会被本地设置文件覆盖?主根 settings.php 中的连接信息应该是某种默认连接信息吗?

【问题讨论】:

    标签: database git drupal drupal-6 settings


    【解决方案1】:

    其中一种方法,我宁愿不要将 settings.php 保留在 Git 中。 https://help.github.com/articles/ignoring-files

    在我们的例子中,我们将代码库保存在 Git 下,但 settings.php 文件被忽略。这样 Prod、Sandbox 和本地环境就会有自己的 settings.php 文件。

    【讨论】:

      【解决方案2】:

      我们在 repo 中保留 2 个 settings.php 文件,但不包括基本 settings.php。

      我用于生产的 settings.php 文件正常。只是数据库设置和默认的东西。 对于开发,我的 settings.php 文件包含数据库设置和包含到存储在名为 settings.dev.php 的 repo 中的文件。

      # Additional site configuration settings.
      if (file_exists('/Users/User/Sites/site.com/sites/default/settings.dev.php')) {
        include_once('/Users/User/Sites/site.com/sites/default/settings.dev.php');
      }
      

      Settings.dev.php 包括关闭缓存和设置环境指示器的开关:

      // Secure Pages
      $conf['securepages_enable'] = FALSE;
      
      // Environment Indicator
      $conf['environment_indicator_color'] = 'blue';
      $conf['environment_indicator_enabled'] = TRUE;
      $conf['environment_indicator_text'] = 'Development Server';
      
      // Robots disable
      $conf['robotstxt'] = 'User-agent: *
      Disallow: /';
      
      // Turn off Caching and such
      $conf['cache'] = FALSE;
      $conf['page_compression'] = FALSE;
      $conf['preprocess_css'] = FALSE;
      $conf['css_gzip'] = FALSE;
      $conf['preprocess_js'] = FALSE;
      $conf['javascript_aggregator_gzip'] = FALSE;
      

      Settings.php 在 repo 中被忽略,但 settings.dev.php 被包括在内。我们还在 repo 中保留了一个 settings.stage.php。在 settings.php 文件中为 prod 设置值需要非常小心,因为它会干扰某些模块并阻止您在需要时快速更改设置。但是你可以用 settings.prod.php 做同样的事情。

      【讨论】:

      • 我喜欢这两种解决方案,都没有对错。我真的希望我能将它们都标记为正确的。我暂时忽略 settings.php 文件。谢谢你们的意见。
      猜你喜欢
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 2022-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多