Drupal - 数据库设置的最佳实践

时间:2017-07-02 13:57:34

标签: drupal drupal-8

在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();

但是,如果您的开发环境和生产环境具有不同的数据库设置会怎样?

1 个答案:

答案 0 :(得分:1)

Drupal支持多站点。您可以将其用于多种配置以进行开发,分段和生产。

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

通常我会设置三个文件夹:

  • development.myproject.com
  • staging.myproject.com
  • myproject.com(制作)

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

Drupal docs中的更多信息。