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

Graph Query Language do Facebook tạo ra từ năm 2012

Average: 9.5 (13 votes)

Làm thế nào để tương tác với hệ sinh thái của React JS hiệu quả

Average: 9.4 (13 votes)

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

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

 
Phiên bản Android 2.3 Gingerbread  nổi tiếng nhất thế giới
Phiên bản Android 2.3 Gingerbread nổi tiếng nhất thế giới

Mặc dù đã ra mắt từ cách đây 2 năm, tuy nhiên phiên bản 2.3 Gingerbread mới là phiên bản Android phổ biến nhất trên thế giới hiện nay, chứ không phải là các phiên bản mới như Android 4.0 Ice Cream Sandwich hay 4.1 Jelly Bean.

Độc giả trong nước đã có thể đọc sách về Steve Jobs bản tiếng Việt trên các thiế
Tiểu sử Steve Jobs bản tiếng Việt trình làng

Nhà sách điện tử Alezaa bắt đầu bán ra tác phẩm mang tên Steve Jobs từ 17h ngày 5/11 nhưng đã thu hút hơn 2.000 lượt đặt mua trước. Alezza dự kiến sẽ tiêu thụ được ít nhất 5.000 bản trong tháng này.

Hướng dẫn custom entity reference: Drupal & Entity reference
Hướng dẫn custom entity reference: Drupal & Entity reference

There are some good examples out there on how to create a custom Entity reference Behaviour plugin, but not so much for Selection handlers.