How to maintain a local mirror image of your gallery2 setup for development

AMTuring
AMTuring's picture

Joined: 2009-11-05
Posts: 1
Posted: Thu, 2009-11-05 16:48

I may be mistaken, but I was unable to find a solution in the FAQ or forums.

I want to maintain a local copy of the Gallery2 setup (photos and database) to work on my website design without disturbing the working website.

The instructions for backup were helpful, but the backup installed on my local machine did not work. I am running Max OS X and MAMP (Mac Apache, MySQL and PHP) for a local web server.

I found the key points were to
1. Make sure your database copy on the local machine matches the config.php name and user.
2. Make sure the base path for your gallery data matches the local machine.
3. Make sure the database server name is localhost on the local copy of config.php.

A similar procedure could also be used to move from one webhost to another.

Here is a step-by-step description of how I got it working:

1. Perform a backup of your database as per the instructions at http://codex.gallery2.org/Gallery2:How_do_I_Make_Backups_of_My_Database. You will bet a sql file backup of your databse from this procedure. Copy this to your local machine.
2. Start up your local phpmyadmin (under MAMP this is found at http://localhost/MAMP/?language=English) install the database from the sql file created in step 1. For ease of use you should use the same database name and add a database user identical to the one you use on the main site (name, password, and Grant Full Access).
3. Copy the contents of your gallery2 directory to your local copy of the website. In my case this was at the home level of the website. You may use ftp, sftp, scp, or rsync to do the transfer.
4. Now for the key step - edit the config.php file in the gallery2 directory. Change the data.gallery.base variable to be a relative path instead of absolute. In my case the original looked like:

$gallery->setConfig('data.gallery.base', '/homepages/14/d9999999999/htdocs/gallery2/g2data/');

and I changed it to

$gallery->setConfig('data.gallery.base', 'g2data/');

The path is relative to the gallery2 directory if your data is in a different location.

You may also need to change the server name. My webhost provides MySQL databases on a separate server, so the hostname had to point away from the local machine. On my website the server was as follows:

$storeConfig['hostname'] = 'db9999.perfora.net';

I changed this to the following.

$storeConfig['hostname'] = 'localhost';

Also note that an alternative to creating a user in step 2 is to edit the database user information you will find near the above line in the config.php. You can change the config to match your local default user (e.g. root).

Finally, to keep the mirror up to date repeat the steps, but now use rsync to copy over only the updated gallery2 data. In fact I use rsync to make a copy of the entire website.

I hope someone else finds this useful. I can freely play with the website design with full gallery2 functionality on my local machine now.


Gallery version: 2.2.6
PHP version: 5.2.11 / 5.2.8
Webserver: Apache 2.0.63 / 1.3.34
Database: MySql 5.1.37 /5.0.67
Activated toolkits: Gd, ImageMagick, NetPbm
Operating system: Mac OS X (10.5.8) and Linux Debian 2.6.28.8
Browser Firefox: 3.5.4

AMTuring