2017-07-02 51 views
0

在Drupal中,配置數據庫設置(數據庫,用戶名,密碼,主機等)的最佳實踐是什麼?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

Drupal支持多站點。您可以將其用於開發,分期和生產的多種配置。

與開發,分期和生產領域的名稱sites文件夾中創建一個文件夾,每個人都會有自己的settings.php文件而這又意味着他們將有單獨的數據庫連接配置。 Drupal將根據當前正在使用的域自動選擇正確的文件夾。

我一般設置三個文件夾:

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

配置​​是可選的,如果您創建的文件夾正是域名。如果您想通過路徑訪問(例如myproject.com/devel),則可以配置​​。

Drupal docs的更多信息。