Multi-tenanted CMSes (with some PHP)
What is “multi-tenant”? <ul><li>One Codebase
Install once, maintain/upgrade that one instance
Many domain names
Many configurations
Each site has its own config file, detailing </li><ul><li>Database details – separate tables per domain, or separate datab...
Skin/Theme details
User-uploaded file locations </li></ul></ul>
Why bother? <ul><li>Cheaper
install one copy of software
all instance data, configs, etc., installed automatically or using a “point and click” installer
Easier to maintain and upgrade
fix in one place, fix everywhere. upgrade once, upgrade everywhere
conversely: bugs/errors are universal, so be careful
Upcoming SlideShare
Loading in …5
×

Multi tenant CMSes using php

4,899 views
4,732 views

Published on

slides for a talk I gave in Dublin Google buildings in March 2011

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,899
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Multi tenant CMSes using php

  1. 1. Multi-tenanted CMSes (with some PHP)
  2. 2. What is “multi-tenant”? <ul><li>One Codebase
  3. 3. Install once, maintain/upgrade that one instance
  4. 4. Many domain names
  5. 5. Many configurations
  6. 6. Each site has its own config file, detailing </li><ul><li>Database details – separate tables per domain, or separate databases
  7. 7. Skin/Theme details
  8. 8. User-uploaded file locations </li></ul></ul>
  9. 9. Why bother? <ul><li>Cheaper
  10. 10. install one copy of software
  11. 11. all instance data, configs, etc., installed automatically or using a “point and click” installer
  12. 12. Easier to maintain and upgrade
  13. 13. fix in one place, fix everywhere. upgrade once, upgrade everywhere
  14. 14. conversely: bugs/errors are universal, so be careful
  15. 15. Less resources needed
  16. 16. less HD space, as only one software instance
  17. 17. bytecode caching (APC, etc) for just 1 CMS copy, thus less file-access </li></ul>
  18. 18. Who's doing it? <ul><li>Joomla, Orchard, Drupal, etc
  19. 19. all have tutorials explaining how to do it (not built into core)
  20. 20. Wordpress
  21. 21. WordPress-MU so cool it was written into the core
  22. 22. Salesforce
  23. 23. Google Apps
  24. 24. Why is it not more prevalent in OSS? </li></ul>
  25. 25. The flow <ul><li>Server checks domain name
  26. 26. Finds config associated with domain name
  27. 27. Sets site-specific variables such as db details, file locations, theme details </li></ul>
  28. 28. Finding the config <ul><li>Different methods
  29. 29. WordPress MU uses one database
  30. 30. One table holds details of each domain
  31. 31. WP searches table to find ID of blog associated with domain name
  32. 32. Each blog's details kept in numbered tables in the same database (eg: wp_2_links, wp_23_links, etc)
  33. 33. KV-WebME uses multiple databases
  34. 34. Config found using sym-links in file-system
  35. 35. Each site's config kept in a separate directory on the filesystem </li></ul>
  36. 36. Proxy Config /home/webme /public_html/index.php /.private/config.php /sites.aliases/kvsites.ie /sites/kv-2-30/config.php
  37. 37. Proxy Config <?php $host=preg_replace( '/^www./', '', preg_replace( '/[^a-z0-9-.]/', '', strtolower( $_SERVER['HTTP_HOST'] ) ) ); $cfile='/home/webme/ sites.aliases /'.$host.'/config.php'; if (!file_exists($cfile)) { $cfile='/home/webme/ sites /'.$host.'/config.php'; if (!file_exists($cfile)) { echo 'error resolving domain name &quot;' .$_SERVER['HTTP_HOST'].'&quot; to a WebME server'; exit; } } require $cfile; define('CONFIG_FILE', $cfile);
  38. 38. Files <ul><li>Files are served through a router/proxy
  39. 39. mod_rewrite, nginx, etc
  40. 40. File's actual location determined by config file
  41. 41. URL is /file/whatever.jpg, but that's not where it really is
  42. 42. could be /home/webme/sites/kv-2-23/f/whatever.jpg </li></ul>
  43. 43. Flow for requesting a file <ul><li>Get site's config directory
  44. 44. user-uploaded files kept in sub-directory (/home/webme/sites/kv-2-23/f)
  45. 45. Rewrite file requests to route through a script
  46. 46. RewriteRule ^f/(.*)$ /ww.incs/get-file.php?filename=$1 [L]
  47. 47. Retrieve actual file location
  48. 48. validate the filename, check that it exists
  49. 49. Push to client
  50. 50. readfile() </li></ul>
  51. 51. Advantages of proxied files <ul><li>More secure
  52. 52. example: /f/whatever.php.jpg <-- image or script?
  53. 53. Authentication
  54. 54. require logged-in user, or that the user be a member of a certain group
  55. 55. Logging
  56. 56. record details such as what user viewed the file, push the file access to a live log view, etc.
  57. 57. Modification
  58. 58. if an image is /f/image.jpg , how about resizing it if called as /f/image.jpg,width=200 </li></ul>
  59. 59. Managing Core Upgrades <ul><li>Automate!
  60. 60. Keep version number of core database tables in config file.
  61. 61. Example: 'version'=>'32',
  62. 62. Hard-code version number into root /index.php
  63. 63. If versions don't match, run upgrade script, then re-save the config file with latest version </li></ul>if (!isset($DBVARS['version']) || $DBVARS['version']<32 ) { redirect('/ww.incs/upgrade.php'); }
  64. 64. Managing New Installations <ul><li>Run new installation from scratch
  65. 65. or...
  66. 66. Maintain a reference installation, and copy that one when creating new installation
  67. 67. Advantages </li><ul><li>Skip lengthy upgrade cycles
  68. 68. Prepopulate with sample data
  69. 69. Customise </li></ul></ul>
  70. 70. <ul><li>Fin </li></ul>

×