Multiple Site (Multisite)

The Multiple Site feature, introduced in Piwigo 2.2, is the ability to have several galleries with a single Piwigo installed. This feature is used on where thousands of galleries run on one Piwigo installation.


Only the files are shared, each gallery has a specific database or a set of tables in the same database if you use a specific table prefix for each gallery.

Piwigo files

Download Piwigo and extract files on your web server, in /var/www/piwigo for example.

Web Server Configuration

In your Apache configuration file, you need something like:

Alias /gallery1 /var/www/piwigo
Alias /gallery2 /var/www/piwigo

Or if you like to do it on Server Name then just add a ServerAlias in your VirtualHost config:


Site Directories

Create directories /var/www/piwigo/gallery1 and /var/www/piwigo/gallery2 and sub-drectories, with write access for www-data (chmod 0777 if you don't understand what www-data is)

mkdir /var/www/piwigo/gallery1
cd /var/www/piwigo/gallery1
mkdir -p local/config _data upload
chown -R www-data:www-data .

Let's do the same for gallery2:

mkdir /var/www/piwigo/gallery2
cd /var/www/piwigo/gallery2
mkdir -p local/config _data upload
chown -R www-data:www-data .

and so on for other sites.

Activate Multiple Site

In your local/config/, you need this kind of code:

if (preg_match('#^/gallery1#', $_SERVER['SCRIPT_NAME']))
#if (preg_match('/^$/', $_SERVER['SERVER_NAME']))
  $site_dir = 'gallery1';
elseif (preg_match('#^/gallery2#', $_SERVER['SCRIPT_NAME']))
#elseif (preg_match('/^$/', $_SERVER['SERVER_NAME']))
  $site_dir = 'gallery2';
if (isset($site_dir))
  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/');

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.


Now you have to go to each Piwigo gallery: and or and (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 or

Physical Albums

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/

// disable the synchronization method for adding photos
$conf['enable_synchronization'] = false;

Or you just hack the code as described in [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.

  $conf['site_dir'] = $site_dir;

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.

--- 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;

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 directory traversal attack.

Back to top
user_documentation/multiple_site.txt · Last modified: 2013/05/31 18:07 by hoedlmoser
github twitter newsletter Donate © 2002-2024 · Contact