Introduction
I had been running two sites, http://www.dratek.com and http://www.draperfarms.com, on separate servers. I finally moved dratek.com to the draperfarms.com server so I wouldn't need to pay double hosting costs, but I was still using separate Drupal and Gallery2 installations. It didn't take long for this to become a nuisance, as anytime an update was needed, it meant having to perform it for each site. Fortunately, Drupal and Gallery2 both support multi-site installations, so all sites can share a common code base.
Drupal Multi-Site Installation
First, I'll cover how to install Drupal for a multi-site configuration. Drupal documentation and a number of other sites discuss setting up a multi-site installation, but for the most part, these are all fresh installs. Since I already had the sites running, I wanted to keep my existing data (granted, there wasn't much, so losing it wouldn't have been too catastrophic.) For the purposes of this tutorial, I will refer to the default site, draperfarms.com, as domain1, and my new site, dratek.com, as domain2.
Important First Steps!!!
Whenever doing something like this, it is important to make backups of your databases. One wrong move and you could lose everything!
Prepare The New Site
When I first added dratek.com to draperfarms.com, CPanel created a 'dratek' directory in the public_html directory. The first thing I did was to rename this to dratek_old in order to avoid conflicts or losing data. Next, login via SSH using something like PuTTY and navigate to the public_html directory. Enter 'ln -s . domain2' (where domain2 is the name of your new site) to create a symbolic link from http://www.domain2.com. At this point, going to http://www.domain2.com will be the same as going to http://www.domain1.com, but we'll fix that soon.
Tell Drupal About The New Site
In the Drupal 'sites' directory, create a directory for your new site named 'domain2.com' (in my case, dratek.com) and copy the default.settings.php file here. There should already be a sites/all directory, which applies to ALL of your sites, as well as a 'default' directory which applies to domain1.com. Rename the domain2.com/default.settings.php file to domain2.com/settings.php and edit it as necessary. For instance, you may need to set the database connection string, or edit the database table prefix if using a shared database.
Since I already had dratek.com running with its own Drupal installation, I copied its 'files' folder to the 'sites/dratek.com' folder. I also carefully copied the modules and themes. When doing this, it is important to place them in the appropriate directory: if they should be accessible to all sites, place them in 'sites/all', if they should only be accessible to domain2, then put them in 'sites/domain2.com'.
Once the necessary themes and modules were available, I was able to access dratek.com in the multi-site installation, since I was using my existing database. If you are setting up a new site, you will need to run the drupal installation script and be sure to select the multi-site configuration.
Gallery2 Multi-Site
I use Gallery2 for my image galleries, and since I was setting up Drupal for multiple sites, I wanted to do the same with Gallery2. Doing this on a new site isn't too difficult, and there are numerous sites that detail the procedure, along with the documentation on the Gallery2 website. However, since I already had existing galleries whose data I wanted to preserve, it was just slightly more involved. The first steps I will cover will be for setting up Gallery2 as a fresh install. I will then explain what I had to do in order to get my existing galleries working.
Install Gallery2 Multi-Site
Get the latest version of Gallery2 and upload it to your server. If you have SSH access, you can upload the zip file and decompress it on the server, saving yourself some time. I used the 'typical' package, but it is actually recommended to use the 'full' package. This caused me some problems, which I'll explain in the 'notes' section below.
Let's say my primary site is http://www.domain1.com, and it is located on the server at home/domain/public_html. If I have installed Drupal in the root directory, then I can install Gallery2 in the root directory as well. In order to avoid confusion or conflicts, name the Gallery2 directory something like 'gallery2_base' so that the path would be public_html/gallery2_base. This directory will only contain the code base and not the individual galleries.
Before starting the Gallery2 install, we need directories for the individual galleries, directories to store the data, and databases for each gallery. I am using separate databases for each gallery, but if you'd prefer, you can use a single shared database provided that you specify a different table prefix for each gallery. I created the databases domain1_gallery1 and domain1_gallery2 (note that the host automatically prepends the domain1_ prefix to any database I create) and I set the proper permissions for each database. Ideally, the data directories should be above the root directory so as to not be accessible directly from the web. I create them in home/domain1/gallery1_g2data and home/domain1/gallery2_g2data and chmod them to 777. Lastly, we need directories to hold each individual gallery. Since we are doing a multi-site setup with Drupal as well, these should be in the appropriate 'sites' directory (public_html/sites/default/gallery2, public_html/sites/domain2.com/gallery2, etc.)
With the preliminary steps taken care of, we can proceed to the gallery installation. Assuming that the code base for the gallery is in gallery2_base, we open a browser and go to http://www.domain1.com/gallery2_base/install to begin the installation process. This is pretty much self-explanatory, and there are plenty of sites that document this, but here's a quick run-down of the steps:
- Welcome -- Select your language, but otherwise nothing happens here.
- Authenticate -- Gallery2 needs a login.txt file with randomly generated code to prove you have access to the server. This file changes for each site in a multi-site install.
- System Checks -- Gallery2 makes sure the server can run Gallery2. If everything shows as success, your are good to go; otherwise, you may need to resolve some issues.
- Installation Type -- I'll cover this a bit since the multi-site installation may be a bit confusing. You have to select the "Multisite Installation" option, then enter the directory for the NEW gallery. This is the individual gallery for the site: (ie. home/domain1/public_html/sites/domain2.com/gallery2). For a multisite installation, you cannot specify the directory that contains the code base, which prevents you from overwriting important files. Also, you need to enter the URL for the NEW gallery (ie. http://www.domain2.com/sites/domain2.com/gallery2/main.php.) Note that for the initial installation for the primary domain, you would not install as a multi-site and you would set the directory for the code base.
- Storage Setup -- This is where you enter the directory for storing the data files (ie. /home/domain1/gallery2_g2data.)
- Database Setup -- Enter the database information (DB name, username, and password) for the gallery. If necessary, specify table and column prefixes.
- Admin User Setup -- Set the password for the 'admin' user.
- Create Config File -- Gallery2 generates the config.php file.
- Check Security -- Gallery2 makes sure the config.php is secure.
- Finish Installation -- Installation is complete and you may go to the newly installed gallery.
Special Note About Using Existing Galleries
- In Step 6 of the installation process (Database Setup) you can use the database for an existing gallery. This will give you the option to erase the tables for a clean install, or to reuse the existing table data. If you want to keep the existing gallery, choose to reuse the tables.
- My biggest obstacle with using existing galleries was that I would encounter errors such as this:
Error (ERROR_BAD_PATH) : Invalid path: modules/permalinks/module.inc
There are a couple reasons I had this happen. First, I started with a fresh codebase rather than using an existing install, which meant any modules I had added weren't available (remember above when I said I used the "typical" package?) Second (and related) is that my two galleries didn't have the same modules anyway, so even if I did use an existing codebase, I would have had problems. I spent quite a bit of time trying to figure this out, and the solution is actually pretty easy. If you had the forsight to use the "full" package, you may not have this problem at all, since the modules are probably all there already. Additionally, if you were smart and disabled any non-core modules, you wouldn't be getting this error (though it could still come back to bite you later.) Since I didn't do either one, I found that the best thing to do was to make a list of the modules I had installed, then go into phpMyAdmin to edit the appropriate database. In the table g2_PluginPackageMap (note the g2_ table prefix) browse for any module that is giving the error message (such as permalinks in the example) and delete it from the table. You should also edit table g2_PluginMap to disable these modules. Once the gallery is installed, you can go into the site administration and re-install the plugins.
- Save the headache and just go with the full installation package...