multisite van dyk walkah

101
Demystifying Multisite Architecture John VanDyk and James Walker Do It With Drupal, December 2008 1

Upload: jvandyk

Post on 09-May-2015

2.704 views

Category:

Technology


2 download

DESCRIPTION

Drupal Multisite presentation from Do It With Drupal seminar 2008

TRANSCRIPT

Page 1: Multisite Van Dyk Walkah

DemystifyingMultisite Architecture

John VanDyk and James WalkerDo It With Drupal, December 2008

1

Page 2: Multisite Van Dyk Walkah

Sharing Information Between Sites

How Multisite Works

What is Multisite?

2

three sections to this presentation, lots of time for questions

Page 3: Multisite Van Dyk Walkah

http://www.example.com

http://banana.example.com

http://www.example.com/apple

http://pancakeblog.net

3

You can always have multiple Drupal sites on a server, with multiple copies of Drupal

Page 4: Multisite Van Dyk Walkah

http://www.example.com

http://banana.example.com

http://www.example.com/apple

http://pancakeblog.net

4

We’re talking about having multiple sites on ONE copy of Drupal.

Page 5: Multisite Van Dyk Walkah

Why?

5

Page 6: Multisite Van Dyk Walkah

6

Page 7: Multisite Van Dyk Walkah

• Only one copy of the codebase

6

Page 8: Multisite Van Dyk Walkah

• Only one copy of the codebase

• Only one codebase to upgrade

6

Page 9: Multisite Van Dyk Walkah

• Only one copy of the codebase

• Only one codebase to upgrade

• Only one set of files to debug

6

Page 10: Multisite Van Dyk Walkah

• Only one copy of the codebase

• Only one codebase to upgrade

• Only one set of files to debug

• Still have flexibility for site-specific modules

6

Page 11: Multisite Van Dyk Walkah

7

Drupal has three essential components.The filesystem contains the files that make up the Drupal codebase.

Page 12: Multisite Van Dyk Walkah

$db_url = 'mysqli://joe:secret@localhost/example';

8

The database contains content and most configuration settings.

Page 13: Multisite Van Dyk Walkah

$db_url = 'mysqli://joe:secret@localhost/example';

example

8

The database contains content and most configuration settings.

Page 14: Multisite Van Dyk Walkah

$db_url = 'mysqli://joe:secret@localhost/example';

example

8

The database contains content and most configuration settings.

Page 15: Multisite Van Dyk Walkah

9

The files directory contains uploaded files.

Page 16: Multisite Van Dyk Walkah

10

If using private files, the files directory can be outside of the web root.

Page 17: Multisite Van Dyk Walkah

<?phprequire_once './includes/bootstrap.inc';drupal_bootstrap(FULL);

11

Page 18: Multisite Van Dyk Walkah

EARLY PAGE CACHE

DATABASE: initialize database layer.

ACCESS: identify and reject banned hosts.

SESSION: initialize session handling.

LATE PAGE CACHE

LANGUAGE: identify the language

PATH: path handling

FULL: Drupal is fully loaded

CONFIGURATION: initialize configuration.

12

Page 19: Multisite Van Dyk Walkah

EARLY PAGE CACHE

DATABASE: initialize database layer.

ACCESS: identify and reject banned hosts.

SESSION: initialize session handling.

LATE PAGE CACHE

LANGUAGE: identify the language

PATH: path handling

FULL: Drupal is fully loaded

CONFIGURATION: initialize configuration.

13

Multisite happens here.

Page 20: Multisite Van Dyk Walkah

We’ve got a request for http://www.example.com/That’s from host www.example.com, path /Let’s look for a settings file at

14

What normally happens.

Page 21: Multisite Van Dyk Walkah

We’ve got a request for http://www.example.com/That’s from host www.example.com, path /Let’s look for a settings file at

sites/www.example.com/settings.php

14

What normally happens.

Page 22: Multisite Van Dyk Walkah

We’ve got a request for http://www.example.com/That’s from host www.example.com, path /Let’s look for a settings file at

sites/www.example.com/settings.php

sites/example.com/settings.php

14

What normally happens.

Page 23: Multisite Van Dyk Walkah

We’ve got a request for http://www.example.com/That’s from host www.example.com, path /Let’s look for a settings file at

sites/www.example.com/settings.php

sites/example.com/settings.php

sites/com/settings.php

14

What normally happens.

Page 24: Multisite Van Dyk Walkah

We’ve got a request for http://www.example.com/That’s from host www.example.com, path /Let’s look for a settings file at

sites/www.example.com/settings.php

sites/example.com/settings.php

sites/com/settings.php

sites/default/settings.php

14

What normally happens.

Page 25: Multisite Van Dyk Walkah

http://www.example.com

http://banana.example.com

15

We’re talking about having multiple sites on ONE copy of Drupal.

Page 26: Multisite Van Dyk Walkah

$db_url = 'mysqli://jdoe:secret@localhost/banana';

$db_url = 'mysqli://moe:shhhh@localhost/www';

16

Now banana.example.com will get a site using the banana database; everything else gets the www database.

Page 27: Multisite Van Dyk Walkah

banana

$db_url = 'mysqli://jdoe:secret@localhost/banana';

$db_url = 'mysqli://moe:shhhh@localhost/www';

16

Now banana.example.com will get a site using the banana database; everything else gets the www database.

Page 28: Multisite Van Dyk Walkah

banana

example

$db_url = 'mysqli://jdoe:secret@localhost/banana';

$db_url = 'mysqli://moe:shhhh@localhost/www';

16

Now banana.example.com will get a site using the banana database; everything else gets the www database.

Page 29: Multisite Van Dyk Walkah

banana

example

$db_url = 'mysqli://jdoe:secret@localhost/banana';

$db_url = 'mysqli://moe:shhhh@localhost/www';

16

Now banana.example.com will get a site using the banana database; everything else gets the www database.

Page 30: Multisite Van Dyk Walkah

banana

example

$db_url = 'mysqli://jdoe:secret@localhost/banana';

$db_url = 'mysqli://moe:shhhh@localhost/www';

16

Now banana.example.com will get a site using the banana database; everything else gets the www database.

Page 31: Multisite Van Dyk Walkah

Edge casehttp://www.example.com/something

17

Need a symlink

Page 32: Multisite Van Dyk Walkah

http://banana.example.com/fanclub

18

Page 33: Multisite Van Dyk Walkah

CCK and Viewsavailable for all sites

porcupine themeavailable for all sites

19

Page 34: Multisite Van Dyk Walkah

20

Page 35: Multisite Van Dyk Walkah

fivestar moduleonly available

on banana.example.com

20

Page 36: Multisite Van Dyk Walkah

fivestar moduleonly available

on banana.example.com

bananator moduleonly available

on banana.example.com

20

Page 37: Multisite Van Dyk Walkah

fivestar moduleonly available

on banana.example.com

gobananas themeonly available

on banana.example.com

bananator moduleonly available

on banana.example.com

20

Page 38: Multisite Van Dyk Walkah

21

Each site has its own place to put uploaded files.

Page 39: Multisite Van Dyk Walkah

http://www.example.com/sites/www.example.com/files/image.jpg

22

mod_rewrite can help make your URLs more friendly

Page 40: Multisite Van Dyk Walkah

RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

http://www.example.com/sites/www.example.com/files/image.jpg

22

mod_rewrite can help make your URLs more friendly

Page 41: Multisite Van Dyk Walkah

RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L]

http://www.example.com/sites/www.example.com/files/image.jpg

http://www.example.com/files/image.jpg

22

mod_rewrite can help make your URLs more friendly

Page 42: Multisite Van Dyk Walkah

Summary So Far

• Single codebase

• Everything in sites/all is shared: modules, themes

• Site-specific modules and themes go in sites/sitename/

• Each site has its own file uploads directory

23

Page 43: Multisite Van Dyk Walkah

Cron!

24

Page 44: Multisite Van Dyk Walkah

Updating Multisite

25

Page 45: Multisite Van Dyk Walkah

example

Updating a Drupal Site

26

The database contains content and most configuration settings.

Page 46: Multisite Van Dyk Walkah

example

Updating a Drupal Site

26

The database contains content and most configuration settings.

Page 47: Multisite Van Dyk Walkah

example

Updating a Drupal Site

example

26

The database contains content and most configuration settings.

Page 48: Multisite Van Dyk Walkah

banana

Updating Multisite

cherry

27

Running update.php once is not enough!

Page 49: Multisite Van Dyk Walkah

banana

Updating Multisite

banana

cherry

27

Running update.php once is not enough!

Page 50: Multisite Van Dyk Walkah

banana

Updating Multisite

banana

cherry

27

Running update.php once is not enough!

Page 51: Multisite Van Dyk Walkah

banana

Updating Multisite

banana

cherry

27

Running update.php once is not enough!

Page 52: Multisite Van Dyk Walkah

banana

Updating Multisite

banana

cherrycherry

27

Running update.php once is not enough!

Page 53: Multisite Van Dyk Walkah

banana

Updating Multisite

banana

cherrycherry

27

Running update.php once is not enough!

Page 54: Multisite Van Dyk Walkah

Sharing Information Between Sites

How Multisite Works

What is Multisite?

28

Page 55: Multisite Van Dyk Walkah

Table Prefixing

29

Prefixing originally for multiple Drupal sites on cheap hosting

Page 56: Multisite Van Dyk Walkah

Table Prefixing

29

Prefixing originally for multiple Drupal sites on cheap hosting

Page 57: Multisite Van Dyk Walkah

Table Prefixing

$db_prefix = 'zoinks_';

29

Prefixing originally for multiple Drupal sites on cheap hosting

Page 58: Multisite Van Dyk Walkah

$db_prefix = array( 'default' => 'main_', 'users' => 'shared_', 'sessions' => 'shared_', 'role' => 'shared_', 'authmap' => 'shared_', );

30

settings.php

Page 59: Multisite Van Dyk Walkah

$db_prefix = array( 'default' => '', 'users' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.', 'authmap' => 'shared.', );

shared.usersdatabasename.tablename

31

settings.php

Page 60: Multisite Van Dyk Walkah

exampleaccessactionsactions_aidauthmap...

32

What will happen with this arrangement? Nothing different! The location of the two tables has just changed (users and authmap tables in the example database are unused).

Page 61: Multisite Van Dyk Walkah

usersauthmap

shared

exampleaccessactionsactions_aidauthmap...

32

What will happen with this arrangement? Nothing different! The location of the two tables has just changed (users and authmap tables in the example database are unused).

Page 62: Multisite Van Dyk Walkah

usersauthmap

shared

exampleaccessactionsactions_aidauthmap...

32

What will happen with this arrangement? Nothing different! The location of the two tables has just changed (users and authmap tables in the example database are unused).

Page 63: Multisite Van Dyk Walkah

bananaaccessactionsactions_aidauthmap...

exampleaccessactionsactions_aidauthmap...

33

Still no change in behavior!

Page 64: Multisite Van Dyk Walkah

usersauthmap

shared

bananaaccessactionsactions_aidauthmap...

exampleaccessactionsactions_aidauthmap...

33

Still no change in behavior!

Page 65: Multisite Van Dyk Walkah

usersauthmap

shared

bananaaccessactionsactions_aidauthmap...

exampleaccessactionsactions_aidauthmap...

33

Still no change in behavior!

Page 66: Multisite Van Dyk Walkah

usersauthmap

shared

bananaaccessactionsactions_aidauthmap...

exampleaccessactionsactions_aidauthmap...

33

Still no change in behavior!

Page 67: Multisite Van Dyk Walkah

“Logged in” means

• Cookie containing session ID

• Entry in sessions table containing session ID

• Entry in users table

34

Page 68: Multisite Van Dyk Walkah

usersauthmap

shared

bananasessionsrole

$user

35

Page 69: Multisite Van Dyk Walkah

usersauthmap

shared

bananasessionsrole

$user

examplesessionsrole

36

Page 70: Multisite Van Dyk Walkah

Share user, authmapSeparate login on each site

Simultaneous logins!

User record shared

Roles are not shared

Role assignments are not shared

37

Page 71: Multisite Van Dyk Walkah

Share user, authmapSeparate login on each site

Simultaneous logins!

User record shared

Roles are not shared

Role assignments are not shared

37

Page 72: Multisite Van Dyk Walkah

Shared Logins

38

Page 73: Multisite Van Dyk Walkah

usersauthmapsessions

shared

bananarole

$user

39

Page 74: Multisite Van Dyk Walkah

usersauthmapsessions

shared

bananarole

$user

$db_prefix = array( 'default' => '', 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', );

39

Page 75: Multisite Van Dyk Walkah

What happens?

40

Page 76: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

40

Page 77: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

40

Page 78: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

• We’re not logged in!

40

Page 79: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

• We’re not logged in!

• Huh?

40

Page 80: Multisite Van Dyk Walkah

SESS0787a3dbcceb3bde85599fd17a876fa8de: d977085b070ee1f8def0fa7c2fb26ada

SESS2611eb8d937302f9383947cd79a86d6888: 26bd9e318d607b0581696431bcfb93b1

What’s wrong with this picture?

41

Page 81: Multisite Van Dyk Walkah

$cookie_domain = ‘example.com’

42

Page 82: Multisite Van Dyk Walkah

What happens?

43

Page 83: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

43

Page 84: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

43

Page 85: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

• We’re already logged in!

43

Page 86: Multisite Van Dyk Walkah

What happens?

• Log into http://banana.example.com

• Go to http://www.example.com

• We’re already logged in!

• Yay!

43

Page 87: Multisite Van Dyk Walkah

user, authmap, sessions + $cookie_domain

One login for all sites

User record shared

Roles are not shared

Role assignments are not shared

44

Page 88: Multisite Van Dyk Walkah

usersauthmapsessionsrole

shared

banana

$user

45

Page 89: Multisite Van Dyk Walkah

usersauthmapsessionsrole

shared

banana

$user

$db_prefix = array( 'default' => '', 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.',);

45

Page 90: Multisite Van Dyk Walkah

46

Page 91: Multisite Van Dyk Walkah

user, authmap, sessions, role + $cookie_domain

One login for all sites

User record shared

Role names/ids shared

Role assignments are not shared

47

Page 92: Multisite Van Dyk Walkah

usersauthmapsessionsroleusers_roles

shared

banana

$user

48

Page 93: Multisite Van Dyk Walkah

usersauthmapsessionsroleusers_roles

shared

banana

$user

$db_prefix = array( 'default' => '', 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.', 'users_roles' => 'shared.',);

48

Page 94: Multisite Van Dyk Walkah

user, authmap, sessions, role, users_roles + $cookie_domain

One login for all sites

User record shared

Role names/ids shared

Role assignments shared

49

Page 95: Multisite Van Dyk Walkah

User record Login Role

Role assignment

user

+ sessions *

+ role

+ users_role

50

Page 96: Multisite Van Dyk Walkah

Caution!

51

Page 97: Multisite Van Dyk Walkah

Caution!• Table contention

51

Page 98: Multisite Van Dyk Walkah

Caution!• Table contention

• Database updates

51

Page 99: Multisite Van Dyk Walkah

Caution!• Table contention

• Database updates

• Don’t share role assignments and not role IDs!

51

Page 100: Multisite Van Dyk Walkah

Caution!• Table contention

• Database updates

• Don’t share role assignments and not role IDs!

• Think it out using stories!

51

Page 101: Multisite Van Dyk Walkah

Sharing Information Between Sites

How Multisite Works

What is Multisite?

52