【问题标题】:Drupal - best practice for database settingsDrupal - 数据库设置的最佳实践
【发布时间】:2017-07-02 13:57:34
【问题描述】:

在 Drupal 中,配置数据库设置(数据库、用户名、密码、主机等)的最佳实践是什么?

sites/default/default.settings.php 中声明如下:

/**
 * Database settings:
 *
 * The $databases array specifies the database connection or
 * connections that Drupal may use.  Drupal is able to connect
 * to multiple databases, including multiple types of databases,
 * during the same request.
 *
 * One example of the simplest connection array is shown below. To use the
 * sample settings, copy and uncomment the code below between the @code and
 * @endcode lines and paste it after the $databases declaration. You will need
 * to replace the database username and password and possibly the host and port
 * with the appropriate credentials for your database system.
 *
 * The next section describes how to customize the $databases array for more
 * specific needs.
 *
 * @code
 * $databases['default']['default'] = array (
 *   'database' => 'databasename',
 *   'username' => 'sqlusername',
 *   'password' => 'sqlpassword',
 *   'host' => 'localhost',
 *   'port' => '3306',
 *   'driver' => 'mysql',
 *   'prefix' => '',
 *   'collation' => 'utf8mb4_general_ci',
 * );
 * @endcode
 */
 $databases = array();

但是如果你的开发环境和生产环境有不同的数据库设置呢?

【问题讨论】:

    标签: drupal drupal-8


    【解决方案1】:

    Drupal 支持多站点。您可以将其用于开发、暂存和生产的多种配置。

    sites 文件夹中使用您的开发、暂存和生产域的名称创建一个文件夹,每个文件夹都有自己的settings.php 文件,这反过来意味着它们将具有单独的数据库连接配置。 Drupal 将根据当前使用的域自动选择正确的文件夹。

    通常我设置三个文件夹:

    • development.myproject.com
    • staging.myproject.com
    • myproject.com(生产)

    如果您创建的文件夹正是域名,则配置sites.php 是可选的。如果你想通过路径访问(例如myproject.com/devel),你可以配置sites.php

    Drupal docs 中的更多信息。

    【讨论】:

      猜你喜欢
      • 2011-11-23
      • 1970-01-01
      • 2010-12-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 2017-07-11
      • 2011-11-30
      • 1970-01-01
      相关资源
      最近更新 更多