Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Multisite Van Dyk Walkah

3,096 views

Published on

Drupal Multisite presentation from Do It With Drupal seminar 2008

Published in: Technology, Design
  • Be the first to comment

Multisite Van Dyk Walkah

  1. 1. Demystifying Multisite Architecture John VanDyk and James Walker Do It With Drupal, December 2008 1
  2. 2. What is Multisite? How Multisite Works Sharing Information Between Sites 2 three sections to this presentation, lots of time for questions
  3. 3. 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
  4. 4. 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.
  5. 5. Why? 5
  6. 6. 6
  7. 7. • Only one copy of the codebase 6
  8. 8. • Only one copy of the codebase • Only one codebase to upgrade 6
  9. 9. • Only one copy of the codebase • Only one codebase to upgrade • Only one set of files to debug 6
  10. 10. • 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
  11. 11. 7 Drupal has three essential components. The filesystem contains the files that make up the Drupal codebase.
  12. 12. $db_url = 'mysqli://joe:secret@localhost/example'; 8 The database contains content and most configuration settings.
  13. 13. example $db_url = 'mysqli://joe:secret@localhost/example'; 8 The database contains content and most configuration settings.
  14. 14. example $db_url = 'mysqli://joe:secret@localhost/example'; 8 The database contains content and most configuration settings.
  15. 15. 9 The files directory contains uploaded files.
  16. 16. 10 If using private files, the files directory can be outside of the web root.
  17. 17. <?php require_once './includes/bootstrap.inc'; drupal_bootstrap(FULL); 11
  18. 18. CONFIGURATION: initialize configuration. 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 12
  19. 19. CONFIGURATION: initialize configuration. 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 13 Multisite happens here.
  20. 20. 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.
  21. 21. 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.
  22. 22. 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.
  23. 23. 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.
  24. 24. 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.
  25. 25. http://www.example.com http://banana.example.com 15 We’re talking about having multiple sites on ONE copy of Drupal.
  26. 26. $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.
  27. 27. $db_url = 'mysqli://jdoe:secret@localhost/banana'; 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.
  28. 28. $db_url = 'mysqli://jdoe:secret@localhost/banana'; banana example $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.
  29. 29. $db_url = 'mysqli://jdoe:secret@localhost/banana'; banana example $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.
  30. 30. $db_url = 'mysqli://jdoe:secret@localhost/banana'; banana example $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.
  31. 31. Edge case http://www.example.com/something 17 Need a symlink
  32. 32. http://banana.example.com/fanclub 18
  33. 33. CCK and Views available for all sites porcupine theme available for all sites 19
  34. 34. 20
  35. 35. fivestar module only available on banana.example.com 20
  36. 36. fivestar module only available on banana.example.com bananator module only available on banana.example.com 20
  37. 37. fivestar module only available on banana.example.com bananator module only available on banana.example.com gobananas theme only available on banana.example.com 20
  38. 38. 21 Each site has its own place to put uploaded files.
  39. 39. http://www.example.com/sites/www.example.com/files/ image.jpg 22 mod_rewrite can help make your URLs more friendly
  40. 40. http://www.example.com/sites/www.example.com/files/ image.jpg RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L] 22 mod_rewrite can help make your URLs more friendly
  41. 41. http://www.example.com/sites/www.example.com/files/ image.jpg RewriteRule ^files/(.*)$ /sites/%{HTTP_HOST}/files/$1 [L] http://www.example.com/files/image.jpg 22 mod_rewrite can help make your URLs more friendly
  42. 42. 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
  43. 43. Cron! 24
  44. 44. Updating Multisite 25
  45. 45. Updating a Drupal Site example 26 The database contains content and most configuration settings.
  46. 46. Updating a Drupal Site example 26 The database contains content and most configuration settings.
  47. 47. Updating a Drupal Site example 26 The database contains content and most configuration settings.
  48. 48. Updating Multisite banana cherry 27 Running update.php once is not enough!
  49. 49. Updating Multisite banana cherry 27 Running update.php once is not enough!
  50. 50. Updating Multisite banana cherry 27 Running update.php once is not enough!
  51. 51. Updating Multisite banana cherry 27 Running update.php once is not enough!
  52. 52. Updating Multisite banana cherry 27 Running update.php once is not enough!
  53. 53. Updating Multisite banana cherry 27 Running update.php once is not enough!
  54. 54. What is Multisite? How Multisite Works Sharing Information Between Sites 28
  55. 55. Table Prefixing 29 Prefixing originally for multiple Drupal sites on cheap hosting
  56. 56. Table Prefixing 29 Prefixing originally for multiple Drupal sites on cheap hosting
  57. 57. Table Prefixing $db_prefix = 'zoinks_'; 29 Prefixing originally for multiple Drupal sites on cheap hosting
  58. 58. $db_prefix = array( 'default' => 'main_', 'users' => 'shared_', 'sessions' => 'shared_', 'role' => 'shared_', 'authmap' => 'shared_', ); 30 settings.php
  59. 59. $db_prefix = array( 'default' => '', 'users' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.', 'authmap' => 'shared.', ); shared.users databasename.tablename 31 settings.php
  60. 60. access actions example actions_aid authmap ... 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).
  61. 61. users shared authmap access actions example actions_aid authmap ... 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).
  62. 62. users shared authmap access actions example actions_aid authmap ... 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).
  63. 63. access actions banana actions_aid authmap ... access actions example actions_aid authmap ... 33 Still no change in behavior!
  64. 64. users shared authmap access actions banana actions_aid authmap ... access actions example actions_aid authmap ... 33 Still no change in behavior!
  65. 65. users shared authmap access actions banana actions_aid authmap ... access actions example actions_aid authmap ... 33 Still no change in behavior!
  66. 66. users shared authmap access actions banana actions_aid authmap ... access actions example actions_aid authmap ... 33 Still no change in behavior!
  67. 67. “Logged in” means • Cookie containing session ID • Entry in sessions table containing session ID • Entry in users table 34
  68. 68. users shared authmap $user sessions banana role 35
  69. 69. users shared authmap $user sessions banana role sessions example role 36
  70. 70. Share user, authmap Separate login on each site Simultaneous logins! User record shared Roles are not shared Role assignments are not shared 37
  71. 71. Share user, authmap Separate login on each site Simultaneous logins! User record shared Roles are not shared Role assignments are not shared 37
  72. 72. Shared Logins 38
  73. 73. users authmap shared sessions $user role banana 39
  74. 74. users authmap shared sessions $user $db_prefix = array( role banana 'default' => '', 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', ); 39
  75. 75. What happens? 40
  76. 76. What happens? • Log into http://banana.example.com 40
  77. 77. What happens? • Log into http://banana.example.com • Go to http://www.example.com 40
  78. 78. What happens? • Log into http://banana.example.com • Go to http://www.example.com • We’re not logged in! 40
  79. 79. What happens? • Log into http://banana.example.com • Go to http://www.example.com • We’re not logged in! • Huh? 40
  80. 80. What’s wrong with this picture? SESS0787a3dbcceb3bde85599fd17a876fa8de: d977085b070ee1f8def0fa7c2fb26ada SESS2611eb8d937302f9383947cd79a86d6888: 26bd9e318d607b0581696431bcfb93b1 41
  81. 81. $cookie_domain = ‘example.com’ 42
  82. 82. What happens? 43
  83. 83. What happens? • Log into http://banana.example.com 43
  84. 84. What happens? • Log into http://banana.example.com • Go to http://www.example.com 43
  85. 85. What happens? • Log into http://banana.example.com • Go to http://www.example.com • We’re already logged in! 43
  86. 86. What happens? • Log into http://banana.example.com • Go to http://www.example.com • We’re already logged in! • Yay! 43
  87. 87. user, authmap, sessions + $cookie_domain One login for all sites User record shared Roles are not shared Role assignments are not shared 44
  88. 88. users authmap shared sessions role $user banana 45
  89. 89. users authmap shared sessions role $user $db_prefix = array( banana 'default' => '', 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.', ); 45
  90. 90. 46
  91. 91. user, authmap, sessions, role + $cookie_domain One login for all sites User record shared Role names/ids shared Role assignments are not shared 47
  92. 92. users authmap sessions shared role users_roles $user banana 48
  93. 93. users authmap sessions shared role users_roles $user $db_prefix = array( 'default' => '', banana 'users' => 'shared.', 'authmap' => 'shared.', 'sessions' => 'shared.', 'role' => 'shared.', 'users_roles' => 'shared.', ); 48
  94. 94. user, authmap, sessions, role, users_roles + $cookie_domain One login for all sites User record shared Role names/ids shared Role assignments shared 49
  95. 95. User Role Login Role record assignment user + sessions * + role + users_role 50
  96. 96. Caution! 51
  97. 97. Caution! • Table contention 51
  98. 98. Caution! • Table contention • Database updates 51
  99. 99. Caution! • Table contention • Database updates • Don’t share role assignments and not role IDs! 51
  100. 100. Caution! • Table contention • Database updates • Don’t share role assignments and not role IDs! • Think it out using stories! 51
  101. 101. What is Multisite? How Multisite Works Sharing Information Between Sites 52

×