Cấu hình Drupal settings file một cách chính xác

Cấu hình Drupal settings file một cách chính xác

I’m a big fan of brevity. This is why I take a few minutes at the start of every project to clean up the settings.php file, make it simpler, and sprinkle in a few things to make local development and on-boarding easier.

First off, we remove the unneeded bits in the file. All of the comments and commented out code is removed. What we are left with is a short file. But wait! What about all the helpful information in the comments? Well, that is exactly why the default.settings.phpfile exists.

>> Giới thiệu sử dụng Mink để testing website Drupal 7

>> Drupal Development: Hướng dẫn tạo CTools Panels Plugin trong Drupal 7

>> Trả lời 8 thắc mắc cho những ai sở hữu Drupal 6 hiện tại

The second thing we do is add support for local developer settings. Over the years I think I’ve tried all the methods out there, and never liked any until we came across this one. Every local developer creates a file called secret.settings.phpthat isn’t tracked in version control.

In our .gitignorefile we add this line:

docroot/sites/default/secret.settings.php

Then in our settings.php file we add this block at the end:

/**
 * Secret settings file for local development only.
 *
 * This file should NEVER be committed to version control and should never exist
 * on a non-local development machine.
 */
if (file_exists('./' . conf_path() . '/secret.settings.php')) {
  require './' . conf_path() . '/secret.settings.php';
}

The idea is that we only include secret settings if it exists, as it never will on your hosting platform. We also keep this file out of version control as the settings in this file are unique for every user.

But what about on-boarding? To allow developers to get up to speed quickly we keep a file called example.secret.settings.phpin version control that serves as a starter for the secret.settings.phpfile.

Here is a typical example.secret.settings.phpfolder for a Drupal site using Vagrant (more on that soon!):

<?php

/**
 * Example secret settings PHP file for making MAG run on your local install.
 *
 * This is configured to connect from your local to a Vagrant box running on
 * your local when running from Drush.
 */

$databases['default']['default'] = array(
  'driver' => 'mysql',
  'database' => 'dbname',
  'username' => 'root',
  'password' => '',
  'host' => '127.0.0.1',
  'prefix' => '',
  'collation' => 'utf8_general_ci',
);

// This allows us to use Drush without a Drush alias.
if (php_sapi_name() == 'cli') {
  $databases['default']['default']['port'] = '3307';

  $conf['memcache_servers'] = array(
    '127.0.0.1:11212' => 'default',
  );
}

// For local development we need to make the local solr server is the default.
$conf['apachesolr_default_environment'] = 'solr';

// Force showing PHP errors.
error_reporting(E_ALL);
ini_set('display_errors', '1');

$conf['file_temporary_path'] = '/tmp';

$conf['securepages_basepath'] = 'http://127.0.0.1:8080';
$conf['securepages_basepath_ssl'] = 'https://127.0.0.1:8443';

// If we didn't set this than base_url would be used for the cookie domain and
// that is different on http v https when both use different non-standard port
// numbers.
$cookie_domain = 'localhost';

Lastly, here is what a typical Drupal settings.php file looks like for one of our projects (I removed the database credentials which would appear here):

<?php

/**
 * Core Drupal settings.
 */
$update_free_access = FALSE;
$drupal_hash_salt = 'some nice hash from here: http://www.passwordtool.hu/';

/**
 * Needed PHP setting tweaks.
 */
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
ini_set('session.gc_maxlifetime', 200000);
ini_set('session.cookie_lifetime', 2000000);

/**
 * Fast 404 configuration.
 */
$conf['404_fast_paths_exclude'] = '/\/(?:styles)\//';
$conf['404_fast_paths'] = '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i';
$conf['404_fast_html'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>';

/**
 * Enabled mixed-mode SSL.
 *
 * This enables a user to use the same session over HTTP and HTTPS. Normally
 * this is really bad, but in conjuction with the Secure Pages module we ensure
 * that SSL is forced for any admin area of Drupal.
 *
 * @see https://www.drupal.org/https-information
 */
$conf['https'] = TRUE;

/**
 * Secret settings file for local development only.
 *
 * This file should NEVER be committed to version control and should never exist
 * on a non-local development machine.
 */
if (file_exists('./' . conf_path() . '/secret.settings.php')) {
  require './' . conf_path() . '/secret.settings.php';
}

Coming soon: My next post will cover how we tune the Drupal settings file for the Acquia Enterprise Cloud.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Confirms 4 câu hỏi về việc: Designers Aren't Clear How To Help Drupal 8

Confirms 4 câu hỏi về việc: Designers Aren't Clear How To Help Drupal 8

Below are the questions that were asked and some of the great takeaways I personally gathered from the answers given. Moving forward this information will be extremely helpful in creating a solution to the existing problems of not enough designers getting involved.

Thực hành Drupal 8 Theming Fundamentals phần 2

Thực hành Drupal 8 Theming Fundamentals phần 2

In our last post on Drupal 8 theming fundamentals, we learned to set up a theme and add our CSS and JavaScript.

Hướng dẫn Syncing Databases giữa Drupal Websites với Backup and Migrate

Hướng dẫn Syncing Databases giữa Drupal Websites với Backup and Migrate

John Hannah explains how you can use destinations in Backup and Migrate module to sync Drupal databased.

Công ty diệt chuột T&C

 

Diet con trung