Nguyen Tien Si

Multi-site trong Drupal

Mô hình multi-site trong Drupal

Cơ sở dữ liệu

  • db_website1: sử dụng cho website1.com
  • db_websiten: sử dụng cho websiten.com
  • db_share: cơ sở dữ liệu dùng chung

Kết nối cơ sở dữ liệu

Trong file settings.php của website1.com

<?php
$db_url
= 'mysql://username:password@localhost/db_website1';
$db_prefix = array(
 
'default'     => 'w1_',
 
'users'       => 'db_share.',
 
'users_roles' => 'db_share.',
 
'sessions'    => 'db_share.',
 
'role'        => 'db_share.',
 
'authmap'     => 'db_share.',
);
?>

Trong file settings.php của websiten.com

<?php
$db_url
= 'mysql://username:password@localhost/db_websiten';
$db_prefix = array(
 
'default'     => 'wn_',
 
'users'       => 'db_share.',
 
'users_roles' => 'db_share.',
 
'sessions'    => 'db_share.',
 
'role'        => 'db_share.',
 
'authmap'     => 'db_share.',
);
?>

Độ ưu tiên trong multi-site

Ví dụ với một site có đường dẫn như sau: http://www.drupal.org/mysite/test/ thì độ ưu tiên trong thư mục sites sẽ là:

1. sites/www.drupal.org.mysite.test
2. sites/drupal.org.mysite.test
3. sites/org.mysite.test

4. sites/www.drupal.org.mysite
5. sites/drupal.org.mysite
6. sites/org.mysite

7. sites/www.drupal.org
8. sites/drupal.org
9. sites/org

10. sites/default

Độ ưu tiên được sắp xếp từ 1 -> 10, nghĩa là khi truy cập vào đường dẫn http://www.drupal.org/mysite/test/ thì hệ thống Drupal sẽ tìm file thông tin cấu hình của site đó theo ưu tiên từ 1 là thư mục sites/www.drupal.org.mysite.test nếu không có thì bỏ qua và tiếp tới các thư mục ưu tiên khác. Nếu có dừng lại đọc thông tin cấu hình trong thư mục đó.

5 comments

Anonymous's picture

Thanks anh Sỹ

Đọc được new theme qua twitter của anh vào xem lại gặp được bài tut multisite của anh ^^.
Anh cho em hỏi thêm là một website bình thường mình chỉ cần config được subdomain là thực hiện multisite với drupal phải không anh?

Anonymous's picture

Thử dùng multi-site với sites

Thử dùng multi-site với sites + context + purl chưa, cái đó cũng hay lắm, dù là đang phát triển.

mrsinguyen's picture

@trunghaily: Cái subdomain

@trunghaily:
- Cái subdomain trỏ về IP chứa hosting.
- Còn trong thư mục site thì đặt tên của site theo thứ tự ưu tiên:

1. sites/www.drupal.org.mysite.test
2. sites/drupal.org.mysite.test
3. sites/org.mysite.test

4. sites/www.drupal.org.mysite
5. sites/drupal.org.mysite
6. sites/org.mysite

7. sites/www.drupal.org
8. sites/drupal.org
9. sites/org

10. sites/default

@Bao:
Để dùng thử xem sao

mrsinguyen's picture

PS: Hiên tại hai website

PS: Hiên tại hai website www.sanglt.comwww.nguyentiensi.com đang chạy multi-site

Anonymous's picture

Em xin nick Yahoo CHAT của anh nào biết làm vấn đề này ạ

Nick CHAT yahoo của em là hotro_hbco

Anh nào làm được điều này rồi add nick của em vào cho em học hỏi với ạ

Nếu được thì liên hệ hòm thư dangky@bonghongvang.vn cho em thông tin em sẽ gọi hoặc email liên hệ lại. Em đang làm cái này mã làm mãi chưa được. Hiện em quản lý 20 site khác nhau nên cần cái này lắm.

Add your comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options