Friday, September 12, 2008

Self Hosted: Gallery2 (multi-site)

Please read the Gallery2 documentation, and follow the installation instructions. I did.

But these instructions are for a single Gallery2 site. I'm running three different Gallery2 sites, with different domain names (courtesy of No-IP.com) all from the same machine, all with an almost identical Apache2 configuration file.

Installing Gallery2 on Debian is rather straight forward, albeit somewhat tedious (please replace the text in red with your own stuff):
  1. run the following to setup the MySQL server:

    aptitude install mysql-server
    mysqladmin -u root password "password"
    skip this step if you already have a database server installed - and please read about securing the initial MySQL accounts.

  2. create a database for each Gallery2 site, and grant full privileges for this database to a specific user (provide this username, later on, to the web-based Gallery2 installer):

    mysqladmin -uroot -p create gallery2photos
    mysql gallery2 -uroot -p -e"GRANT ALL ON gallery2photos.* TO username@localhost IDENTIFIED BY 'password'"

  3. run (once)
    aptitude install gallery2

  4. create a configuration file for your site, e.g. /etc/apache2/sites-available/photos

    <VirtualHost *:80>
    ServerName gallery2.example.com
    ServerAdmin webmaster@example.com
    <IfModule mod_rewrite.c>
    RewriteLog /var/log/apache2/rewrite.log
    RewriteEngine On
    RewriteRule ^/$ gallery2 [R]
    </IfModule>
    DocumentRoot /var/www/photos
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    </Directory>
    Alias /admin/gallery2 /usr/share/gallery2
    <Directory /admin/gallery2>
    Options FollowSymLinks
    AllowOverride Limit Options FileInfo
    </Directory>
    <Directory /gallery2>
    Options FollowSymLinks
    AllowOverride Limit Options FileInfo
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log vhost_combined
    </VirtualHost>

  5. enable mod_rewrite:
    a2enmod rewrite
    the idea is that access to http://gallery2.example.com will automatically be diverted to http://gallery2.example.com/gallery2 (this is a dedicated photo album website)

  6. create a directory for your Gallery2 website:
    mkdir -p /home/username/www/photos/gallery2

  7. create a symlink /var/www/photos to the root directory of your Gallery2 website:
    ln -s /home/username/www/photos /var/www/photos

  8. set the directory ownership:
    chown -R www-data:www-data /home/username/www/photos

  9. create a directory to host the Gallery2 data and images (e.g. /home/username/g2data/photos - you'll be prompted to do this as part of the web-based Gallery2 installation procedure)

  10. enable the new site and restart the webserver:

    a2ensite photos
    /etc/init.d/apache2 restart

  11. open the following link in a browser: http://gallery2.example.com/admin/gallery2 and follow the web-based installer instructions... (you should also read the multi-site installation instructions)

Tip: when uploading new photos to Gallery2, that are already on your computer, you should use the "From Local Server" tab in the "Add Items" web page, and tick the option "Use symlink" for each photo that you upload. This keeps a single copy of each image on your computer, and separates the photos from the Gallery2 files.

No comments:

Post a Comment