Upgrade, Installation and Setup of Gallery 2.3 and the Drupal 6 version of the Gallery Module with G2Image

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
ergophobe's picture

I'm not sure this has any value anymore or where, if anywhere this should go, but these are my notes. I finally upgraded from drupal 4.7 to drupal 6.4. That meant I could finally try the new Gallery module. These are my notes to myself on the process and what I did and little issues I had. I hope they're useful. Perhaps with some feedback and refinement they might have something worth adding to the codex. Not sure about that.

1. Install Gallery

  • extract Gallery 2.3.x to subdir of drupal site. The drupal module will handle the path and so this can be anything. The default is place your gallery in a subdirectory within drupal named /gallery2 and for the drupal gallery module to use http://example.com/gallery/ as the default Gallery root. But for now, we're accessing Gallery directly via it's filesystem path.
  • add a rewrite rule to your drupal .htaccess rewrites to prevent everything getting rewritten to drupal format: RewriteCond %{REQUEST_URI} !=/gallery2/.*
    This isn't strictly necessary in the sense the drupal already checks to see if the given address is a directory or file, but if you are using clean URLs with Gallery, the test for driectory and file will come up negative and you won't be able to use that URL to access your gallery.
  • open the /gallery2/install/ dir in your browser (i.e. http://example.com/gallery2/install and it should install
  • In my case, gallery gives a warning that output buffering is enabled in php.ini and this may cause memory overload and progress bars won't work. Is this a problem? So far so good, but I need to look into this when I get a chance.
  • admin name is the same as in drupal.
  • run through security checklist in step 11.
  • if you're building a test install on any Windows version before Vista, you can't use .htaccess without various problems and must redefine it in the AccessFileName directive in your httpd.conf as ht.access or something. If you've done this, the Gallery URL Rewrite test will not work until you copy it over to a file named ht.access in the file that it tells you to modify when mod_rewrite test fails during URL config. Once the plugin is finally activated, G2 creates a .htaccess file in the gallery root. It needs to be copied and renamed as well. In both cases leave the original .htaccess so that Gallery and drupal find them when looking to see if they're writeable.
  • In the Gallery admin, also activate Image Block and Image Frame plugins.
  • LOG OUT of Gallery.

2. Install the Drupal G2 Module

  • LOG OUT OF GALLERY if you forgot to in the last step.
  • unpack gallery2 module in your /sites/all/modules or /sites/default/modules directory and follow instructions in README.TXT
  • to get friendly URIs to work
    • enable clean URIs in drupal
    • enable them in Gallery and configure
    • from within embedded Gallery, go to URL Rewrite Administration
      • under rules, find the "Show Item" rule and add the base URL (relative to drupal root) of your gallery to the rewrite rule there. So, for example, the default would be v/%path%
        If your drupal install is at http://example.com/ and your gallery URL (i.e. the drupal alias for your gallery, not the directory filesystem path - by default the directory is /gallery2 and the URL is /gallery) is /mygallery, your Show Item path would be mygallery/v/%path%
        -Note that while pages will use the /mygallery directory in their URLs, other resources (so your actual images) will use the filesystem name (/gallery2) in their paths. That can be good or bad depending on the terms you choose. If you want it absolutely clear that what you have are photographic images, you could use "photos" for one (e.g. the page URL) and "images" for the other (e.g. the image src). If you use the same name for both, that will create issues, because any set of rewrite rules would then prevent you from being able to access Gallery in both the embedded version and the standalone version (that's why you must not put your gallery in a directory named /gallery).
      • Under the SETUP tab, still on the URI Rewrite Admin page of the embedded gallery, scroll down to Embedded Setup and set the path to your drupal .htaccess and give the drupal alias (again, not the directory name) of your gallery (so in our example, /mygallery/).
  • Once again, if you're building a test site on a Windows box, the WAMP setup (Apache under Windows) provides a few challenges if you aren't using Vista because XP and earlier don't allow you to create files with what it thinks is an extension only, that is to say you can't just save a file as .htaccess. Again, one way around this on WAMP setups is to change the AccessFileName directive in your httpd.conf to use something like ht.access. If you've set up your testbed server like that, this means that in the Gallery Module Configuration, you will not be able to test and configure URI Rewrite settings on a windows server where your access file is something other than .htaccess. You need to create a .htaccess that's writable and then transfer settings over in / and /gallery2. That should work and you can also use that method as a general solution (i.e. copy .htaccess files to where you need them and then edit as you need).
    • At least in my case, the automatic configuration aspect of all this didn't work and it took some effort to get the right rewrite rules in the right place. In the .htaccess in my main drupal directory (so not the one created when you activated the URL Rewrite plugin in Gallery), I had to add this line above your other rewrite rules:
         RewriteRule ^gallery/v/([^?]+)(\?(.+))? index.php?q=gallery&g2_view=core.ShowItem&g2_path=$1&$3  [QSA,L]

      It should precede the other rewrites for drupal because you're basically trying to intercept requests that need to be rewritten for Gallery, grab them, rewrite them to a valid request and then quit before any other rewrites get their grubby regexes on them.

3. G2Image Helper

The 6.x version of the Gallery module comes with a helper plugin to integrate the magical G2Image chooser. Initially developed to integrate with Wordpress and TinyMCE, it's been ported to drupal and has a standalone version. Since I don't use TinyMCE, I use the standalone version of G2Image. Like Gallery itself, you have to download G2Image first before you can install the module (the module settings page gives you a current link).

  • if you're using TinyMCE you need to install G2Image in a directory called /g2image/ within your TinyMCE plugins directory.
  • if you're not using TinyMCE, you can create the /g2image/ directory anywhere you want. I've chosen to make it a subdirectory of the g2image drupal module, which seems to make some sort of sense. So in my case, that puts it in example.com/sites/all/modules/gallery/gallery_g2image/g2image
    That's a long path, but so be it.
  • set the "path to Gallery main" in /g2image/config.php relative to server root. So in my case, since Gallery is within drupal, that path is simply the default path: $g2ic_gallery2_path = "gallery2/";
  • go to admin/build/modules and activate the g2image module.
  • now go back to /admin/settings/gallery and notice that there's a new g2image settings tab. Go there and select whether to use TinyMCE or Standalone. If using Standalone, you can also select which types of pages use g2image. In my case, I don't really want images in comments, so I just allow node/add/*
  • note that when you save the configuration, it will put in the absolute path to your gallery install into the g2image/config.php file. and will set $g2ic_use_full_path to TRUE. So if you are setting this up in a sandbox and need to transfer to your server, this setting will likely be wrong unless your sandbox has the same file system setup as you server (very unlikely).
  • now you should have a "Add Gallery 2 Image" link below every textarea (that is, multi-line text entry boxes, but not single-line ones).

3. Permissions

-by default, when you install the Gallery module, anonymous users do not have access to the galleries and will get an Access Denied error. You need to go to /admin/user/permissions and let anonymous users in.
- there are also permissions you may need to set for G2Image.

4. Menus

By default the Gallery module adds menu items to the main Navigation menu in drupal. I only show this to admins, so I don't want the Gallery menu navigation there. This is a simple fix. Just go into menu admin (/admin/build/menu) and navigate to the navigation menu. There you'll find the Gallery menu. You can click edit and give it an parent you want (in other words add it to any menu you want) or you can create a new menu block just for Gallery and add it there.

5. Theming

Things might not look quite right on your gallery pages because of the way the gallery and drupal styles interact. The easiest way to do this is to add to the $body_classes variable and use the CSS cascade to style individual elements.

By default, the theme.inc function template_preprocess_page provide for a class based on page type (line 1797 in drupal 6.4)

$body_classes[] = preg_replace('![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s', '', 'page-'. form_clean_id(drupal_strtolower(arg(0))));

This gives you something like:

.page-gallery

for all gallery pages, based on the page type. So this can be page-node, page-taxonomy. I believe this is based on the first part of the system path (so not necessarily the request URI).

If you're using the Zen theme or a derivative, you're all set. You'll also already have the following classes available in the BODY tag:

-the class for the index and item pages for a specific gallery

.page-gallery-X-YYYY=ZZZZ

based on the URL requested. If you're asking for your gallery at example.com/gallery/v/subdir1, this class will be page-gallery-v-subdir1. If you have a sub-gallery of subdir1 in subdir2, you will have not have the class for subdir1, but you will have page-gallery-v-subdir1-subdir2. Note that if you choose to use another alias for your gallery, like example.com/images/, these examples would be page-images-v-subdir1 and page-images-v-subdir1-subdir2.

-the general class for all gallery pages. The zen theme grabs the "section" by taking the first element in the path, so in this case "gallery".

  section-gallery

Again, if the alias for your gallery section is /images, this class would be section-images.

If you want to have similar classes for your theme and they aren't provided, you can do the same as they do in the Zen theme and grab them like so:

<?php
    $path
= drupal_get_path_alias($_GET['q']);
    list(
$section, ) = explode('/', $path, 2);
   
$body_classes[] = zen_id_safe('page-' . $path);
   
$body_classes[] = zen_id_safe('section-' . $section);
  
?>

At the time of this writing, this is in lines 138-141 of the zen theme template.php file.

If you're styling something within the content area, you also have some additional selectors provided by the module itself.
- #gallery which basically surrounds the content that gallery itself is providing
- .galleryWrapper which is set in the "content" div.

Now you can style things using the cascade by adding style rules such as

body.section-gallery #content-inner {
  margin: 0;
}

It may be helpful to modify your Gallery theme a little for embedding. In that case, just copy your theme to a new directory and search and replace for every occurrence of your theme name and change it so something else. So in my case, for example, the theme was Yoguide and I changed it to YoguideEmbed and put it in a directory with the same name as the theme. Once you've done this, you can have a default theme for when you access gallery directly.

In drupal, you can go to /admin/settings/gallery and choose a specific theme for use when embedded by drupal. So in my case, my Gallery default is Yoguide, but my embedded theme is YoguideEmbed

6. Transfer to live site

In my case, I was also upgrading from drupal 4.7 and gallery 2.2 to drupal 6.4 and gallery 2.3. I did a lot of testing and futzing locally before really taking the plunge. I still haven't made the Gallery module and G2Image live since I just finished tweaking the themes. Anyway, here's a rundown on how to get it all on the server.

If you've been building this in a sandbox on your local server, now you have to transfer it to your live site. Generally speaking that's pretty easy. Here's what I do when I want to make sure not to blow away an existing site and be able to revert everything if something is wrong.

  • create new directory /mysite2
  • mirror your sandbox setup to the /mysite2 directory on your server. This is a huge transfer and there are much better methods than FTP. One option is to use subversion to get up-to-date versions of drupal and Gallery. Since there are virtually no files that get changed during the install process, this is a good method. Then just transfer over your /sites directory for drupal and your gallery theme if you have a custom theme.
  • Also you will need to FTP over your Gallery config.php file in the main gallery directory
  • finally, you will need to upload your .htaccess files to the server. Make sure these match the ht.access files that are working on your windows machine if that's your situation and also that they have no Windows-specific weirdness (they shouldn't normally).
  • edit your /sites/all/modules/gallery/gallery_g2image/g2image/config.php file so that the file path to your gallery install is correct. You can probably achieve this by going into /admin/settings/gallery/g2image and just save and it will rewrite the config.php file, but not sure about this.
  • in drupal go to /admin/settings/performance and make sure you've cleared all cached data (button way at the bottom).
  • similarly, go into the Gallery admin under Maintenance and clear both the template cache and the database cache.
  • create SQL dump files of your local drupal database and upload it to the server. I like names that match the application version so I can keep track of what's what, so I use something like mysitedrupal6.
  • you can probably do the same for Gallery, but the Gallery upgrade process always is smooth for me, so I just do a dump of my server DB and then create a copy of it in a db named for the version I'm upgrading to (e.g. mysitegallery23) and take my site offline for the upgrade.
  • make sure that your /sites/default/settings.php and your /gallery2/config.php files are set to the right DBs and the user and passwords for those DBs work.
  • rename the directory where you site is currently stored from /mysite to /mysite1. If you already have it set up so that you have a symlink from /mysite to /mysite1, then it's even easier
  • create a symlink from /mysite to /mysite2 or, if you're already using symlinks, update the symlink so it points to /mysite2 instead of mysite1.
  • Take a deep breath and load your home page. If it looks okay, go to http://example.com/gallery2/upgrade/index.php and get your Gallery install updated. The click around and check everything out.
  • If it doesn't work, you can quickly delete the symlink and change the name of your working install back so the symlink points to /mysite1 again. Note that by using new databases instead of upgrading the old databases, your old install works instantly just by renaming your directory.
  • Looking okay? If it is , now go in to drupal admin and make sure that your caching is turned on (/admin/settings/performance).
  • after you're sure your new install is working, delete the old DBs and directories before you get confused.

Gallery2 Integration

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week