Differences

This shows you the differences between two versions of the page.

Link to this comparison view

user_documentation:multiple_site [2012/08/24 11:38]
plg created
user_documentation:multiple_site [2013/05/31 18:07] (current)
hoedlmoser added Synchronization for Multisites
Line 1: Line 1:
-====== Multiple site (multisite) ======+====== Multiple Site (Multisite) ======
  
-The Multiple site feature, [[http://www.piwigo.org/releases/2.2.0#multisite|introduced in Piwigo 2.2]], is the  ability to have several galleries with a single Piwigo installed. This feature is used on [[http://piwigo.com|Piwigo.com]] where thousands galleries run on the each Piwigo installation.+The Multiple Site feature, [[http://www.piwigo.org/releases/2.2.0#multisite|introduced in Piwigo 2.2]], is the  ability to have several galleries with a single Piwigo installed. This feature is used on [[http://piwigo.com|Piwigo.com]] where thousands of galleries run on one Piwigo installation.
  
 ===== Databases ===== ===== Databases =====
Line 13: Line 13:
 ===== Web Server Configuration ===== ===== Web Server Configuration =====
  
-In your Apache configuration file, you need something like :+In your Apache configuration file, you need something like:
  
 <code>Alias /gallery1 /var/www/piwigo <code>Alias /gallery1 /var/www/piwigo
 Alias /gallery2 /var/www/piwigo</code> Alias /gallery2 /var/www/piwigo</code>
 +
 +Or if you like to do it on Server Name then just add a ServerAlias in your VirtualHost config:
 +
 +<code>ServerName piwigo.yourdomain.com
 +ServerAlias gallery1.yourdomain.com
 +ServerAlias gallery2.yourdomain.com</code>
  
 ===== Site Directories ===== ===== Site Directories =====
Line 23: Line 29:
  
 <code bash>mkdir /var/www/piwigo/gallery1 <code bash>mkdir /var/www/piwigo/gallery1
-mkdir /var/www/piwigo/gallery1/local +cd /var/www/piwigo/gallery1 
-mkdir /var/www/piwigo/gallery1/local/config +mkdir -p local/config _data upload 
-mkdir /var/www/piwigo/gallery1/_data +chown -R www-data:www-data .</code>
-mkdir /var/www/piwigo/gallery1/upload +
-chmod -R www-data:www-data /var/www/piwigo/gallery1</code>+
  
 Let's do the same for gallery2: Let's do the same for gallery2:
  
 <code bash>mkdir /var/www/piwigo/gallery2 <code bash>mkdir /var/www/piwigo/gallery2
-mkdir /var/www/piwigo/gallery2/local +cd /var/www/piwigo/gallery2 
-mkdir /var/www/piwigo/gallery2/local/config +mkdir -p local/config _data upload 
-mkdir /var/www/piwigo/gallery2/_data +chown -R www-data:www-data .</code>
-mkdir /var/www/piwigo/gallery2/upload +
-chmod -R www-data:www-data /var/www/piwigo/gallery2</code>+
  
 and so on for other sites. and so on for other sites.
Line 44: Line 46:
 In your local/config/config.inc.php, you need this kind of code: In your local/config/config.inc.php, you need this kind of code:
  
-<code php>if (preg_match('#^/gallery1#', $_SERVER['SCRIPT_NAME']))+<code php> 
 +if (preg_match('#^/gallery1#', $_SERVER['SCRIPT_NAME'])) 
 +#if (preg_match('/^gallery1.yourdomain.com$/', $_SERVER['SERVER_NAME']))
 { {
-  $site_dir = './gallery1/';+  $site_dir = 'gallery1';
 } }
 elseif (preg_match('#^/gallery2#', $_SERVER['SCRIPT_NAME'])) elseif (preg_match('#^/gallery2#', $_SERVER['SCRIPT_NAME']))
 +#elseif (preg_match('/^gallery2.yourdomain.com$/', $_SERVER['SERVER_NAME']))
 { {
-  $site_dir = './gallery2/';+  $site_dir = 'gallery2';
 } }
  
-define('PWG_LOCAL_DIR', $site_dir.'local/'); +if (isset($site_dir)) 
-$conf['upload_dir'] = $site_dir.'upload/')+
-$conf['data_location'] = $site_dir.'_data/');+  define('PWG_LOCAL_DIR', $site_dir.'/local/'); 
 +  $conf['upload_dir'] = './'.$site_dir.'/upload'; 
 +  $conf['data_location'] = $site_dir.'/_data/'; 
 +  
 +  # in case there is a specific configuration file for each "site" 
 +  @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php')
 +
 +</code>;
  
-# in case there is a specific configuration file for each "site" +The trick is to find how Piwigo can understand if it's currently running gallery1 or gallery2. In this example, we have used the $_SERVER['SCRIPT_NAME'] variable. You can also use an environment variable set by your webserver or the Servers Name in the $_SERVER['SERVER_NAME'] variable (if you search for a specific sub-domain). If no Alias or Server Name matches it will just use the default, root gallery.
-@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');</code> +
- +
-The trick is to find how Piwigo can understand it's currently running gallery1 or gallery2. On this example, we have used the $_SERVER['SCRIPT_NAME'] variable. You can also use an environment variable set by your webserver or the full URL (if you search for a specific sub-domain)+
  
 ===== Installations ===== ===== Installations =====
  
-Now you have to go to each Piwigo gallery : http://yourdomain.com/gallery1 and http://yourdomain.com/gallery2 and follow the installation each time.+Now you have to go to each Piwigo gallery: http://yourdomain.com/gallery1 and http://yourdomain.com/gallery2 or http://gallery1.yourdomain.com/ and http://gallery2.yourdomain.com/ (if you match on Server Name) and follow the installation each time. Keep in mind that the default, root gallery should be available somewhere at http://yourdomain.com/piwigo or http://piwigo.yourdomain.com/. 
 + 
 +===== Physical Albums ===== 
 + 
 +[[user_documentation:albums_management|Physical Albums]] (aka Synchronization) for Multisites are not yet (means version 2.5.1) supported out of the box. I mean all that stuff in the //galleries// directory. The main issue here is, that all sites of a Multisite installation are sharing this directory. An other issue is that with the current code directory traversals are possible to just import an others gallery. 
 + 
 +Either you disable Synchronization with the following code snippet in your local/config/config.inc.php: 
 +<code php>// disable the synchronization method for adding photos 
 +$conf['enable_synchronization'] = false;</code> 
 + 
 +Or you just hack the code as described in [[http://piwigo.org/forum/viewtopic.php?id=22173|[Forum, topic 22173] physical albums are not multisite save]]. 
 + 
 +Let's some it up here. 
 + 
 +==== Pimp Synchronization for Multisites ==== 
 + 
 +Due to the path for the //galleries// directory is nowhere configured as for upload_dir and data_location we need to put site_dir into the $conf variable. Just add the following to the ''if (isset($site_dir))'' statements from above. 
 + 
 +<code php>  $conf['site_dir'] = $site_dir;</code> 
 + 
 +Also we need to adapt admin/site_manager.php to prefix the //galleries// directory with the site_dir at creation time. Already existing //galleries// directories will not be prefixed automatically, you have to change them on your own in the database in table piwigo_sites. 
 + 
 +<code php>--- admin/site_manager.php  2013-01-01 13:35:02.000000000 +0100 
 ++++ admin/site_manager.php  2013-05-31 17:06:31.000000000 +0200 
 +@@ -53,8 +58,12 @@ 
 +   { 
 +     fatal_error('remote sites not supported'); 
 +   } 
 +-  $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); 
 ++  $url = preg_replace(array('/\/+/', '/(\.+\/)|(^\/)|(\/$)/'), array('/', ''), $_POST['galleries_url']); 
 +   $url.= '/'; 
 ++  if (isset($conf['site_dir'])) 
 ++  { 
 ++    $url = $conf['site_dir'] . '/' . $url; 
 ++  } 
 +   if ( ! (strpos($url, '.') === 0 ) ) 
 +   { 
 +     $url = './' . $url;</code> 
 + 
 +The added regex just removes 
 +  * multiple slashes 
 +  * first and last slash(es) 
 +  * any dot-slash, dot-dot-slahs, dot-dot-dot-slash, ... 
 +so we hopefully avoid a [[wp>Directory_traversal_attack|directory traversal attack]]. 
 + 
 
Back to top
user_documentation/multiple_site.1345808307.txt.gz · Last modified: 2012/08/24 11:38 by plg
 
 
github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact