Gallery on Dreamhost
NOTE, 2004/04/05: When this document was originally written, Dreamhost ran PHP as an Apache module, meaning you had to do a lot of funky custom stuff to run PHP as a CGI program. They have now changed this default setting, so you no longer have to do the php-cgi stuff. New domain names are automatically configured to use CGI. Domains that existed before they made the switch require you to go into the control panel and manually switch from an Apache module to a CGI script.

Getting PHP Gallery under DreamHost is not exactly an easy thing to do, but I finally managed to get it running. These steps are from memory. No notes were taken as I got it configured and installed. So, here's the info...

There are several problems to overcome when installing Gallery:
  • netpbm is not completely installed on Dreamhost. The one they use is missing GIF creation support
  • An open_basedir restriction has been put in place. This means you cannot access your home directory through the normal /home/username symlink. It can only be accessed through the /home/.machine/username directory, which is not portable. If they decide to move you to another machine, all of the paths will be incorrect.
  • The PHP exec() function has been disabled

The solution is a little complicated. First, download the netpbm binaries from the Gallery download page and place them in a folder in your home directory named "bin". (You can do this same thing for the missing tools like jhead). When configuring Gallery, you will have to point it to /home/your_username/bin instead of the standard /usr/bin location.

Next, the open_basedir and exec() problems need to be bypassed. This can be done by running php as a CGI program instead of as an Apache module. Download the PHP CGI executable from the Gallery download page. Create a cgi-bin folder in your website's directory (mkdir /home/your_username/domain.com/cgi-bin), rename the PHP executable to "php.cgi" and copy it into this cgi-bin folder.

Next, you will need to set up a subdirectory that uses PHP as CGI instead of as an Apache module. Make a folder at /home/your_username/domain.com/php-cgi. This folder needs a .htaccess file with the following content:
RemoveHandler .php
AddType application/cgi-php php
Action application/cgi-php /cgi-bin/php.cgi
This means that any PHP files in this folder will be handled by the CGI variant of PHP. Install the Gallery files in this folder. Just follow the normal installation instructions that begin with:
cd /home/your_username/domain.com/php-cgi
tar -zxvf /path/to/gallery/gallery.tgz
:
:
[and concludes with]
mkdir albums
chmod 0777 albums
Do not run the setup PHP script yet. You will need to edit a few files first.

Because PHP is running as a CGI program, it will have difficulty creating sessions in the /tmp folder. You will need to create a tmp folder (which is also useful for uploads) in your home directory and tell Gallery/PHP to use that for sessions.
mkdir /home/your_username/tmp
Now, tell Gallery where to place the session files by editing /home/your_username/domain.com/php-cgi/gallery/session.php and adding the following ini_set line (changing the username, of course) before the line containing "session_start();"
}

/* Start a new session, or resume our current one */
ini_set("session.save_path", "/home/username/tmp");
session_start();

/* emulate register_globals for sessions */
if (!$gallery->register_globals) {


Now, you will need to create an .htaccess file at /home/your_username/domain.com/.htaccess that tells the web server to invisibly redirect http://domain.com/gallery to http://domain.com/php-cgi/gallery so that the user is not burdened with a nasty URL. The contents of this new .htaccess file should be:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^gallery(.*)$ /php-cgi/gallery$1
RewriteRule ^albums(.*)$ /php-cgi/albums$1
</IfModule>


At this point, you can configure PHP Gallery using the normal configuration method (http://domain.com/gallery/setup). Remember to point it to the proper bin and tmp folders (the ones in your home directory). Also, you will need to tell it to disable file locking, as this does not seem to be supported when running PHP as a CGI process. All file paths should include the php-cgi folder (/home/your_username/domain.com/php-cgi/gallery) but the URL should not include it (http://domain.com/gallery).

Even with all of these instructions, you may still find little snags here and there. A good, working knowledge of Unix/Linux is very useful in troubleshooting your installation. Also, try checing the PHP Gallery FAQ and documention. They are quite extensive.
dock image