Gallery2:Installation on Windows Server 2003 and IIS6 - Gallery Codex
Personal tools

Gallery2:Installation on Windows Server 2003 and IIS6

From Gallery Codex

Installing Gallery 2 on IIS in a hosted environment is not possible, unless you have local administrator permissions on the server.

This guide assumes that Windows 2003 Server and Internet Information Server 6.0 is already installed.


You have to download the latest Versions of MySQL and PHP.


  • Download the latest "MySQL Essential installer (MSI) package" from:


  • Download the latest version of PHP from:

Make sure you download the .zip archive, not the Windows installer! The installer doesn't help preparing the IIS anyway and misses invaluable .dll files like php-gettext

UPDATE: PHP 5.2.0 installer does most of IIS integration for you. You can also specify which extensions you want to enable (gettext, GD2, etc.). The only thing that you need to do is to configure Application mapping and restart IIS. Apparently, it's a bug, so expect this to be done automatically in future versions.

Installing MySQL

The default Setting of the MySQL Installer are mostly good, but there are some important things:

  • Make sure you set a root password!
  • On screen 8 of the installer choose "Transactional"

Setting up the Database

In this guide we use "gallery2" as the databasename for your gallery, you can choose another if you want.

  • Start the MySQL Command Line Client
Start Menu -> MySQL -> MySQL Server 4.1 -> MySQL Command Line Client
  • Enter your root password (defined during install of MySQL) and press "Enter"
  • Create a database for your gallery. Enter the following statement and press "Enter".
  • Create a user for accessing the database. Replace "yourPasswordHere" with a password of your choice. Enter the following statement and press "Enter".
GRANT USAGE ON * . * TO 'gallery2'@'localhost' IDENTIFIED BY 'yourPasswordHere';
  • Grant the created user rights on your new database. Enter the following statement and press "Enter".
GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , ALTER ON `gallery2` . * TO 'gallery2'@'localhost';
  • Leave the MySQL Command Line Client. Enter the following statement and press "Enter".

Installing PHP.

The path used for PHP is just an example, you can choose another if you want.

  • Extract the archive in C:\PHP (Rename it if necessary)
  • Rename C:\PHP\php.ini-recommended to C:\PHP\PHP.INI

Configure the Session directory

  • Open C:\PHP\PHP.INI

Make sure you remove the initial semicolons!

  • Find
;session.save_path = "/tmp"

replace it with

session.save_path = "C:\WINDOWS\TEMP"
  • Find
; **You CAN safely turn this off for IIS, in fact, you MUST.**
; cgi.force_redirect = 1

replace it with

; **You CAN safely turn this off for IIS, in fact, you MUST.**
cgi.force_redirect = 0

Configure PHP extensions

  • Find
; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

replace it with

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\PHP\EXT"

If you can't find "extension_dir" in your C:\PHP\PHP.INI file, add it to the bottom of the file.

MySQL extension

As Gallery 2 uses a database to store it's metadata, you need to enable database support in PHP. This guide uses MySQL, but the procedure would be similar for Postgres or Oracle.

  • Find

replace it with


Gettext extension

  • In order to make the localization of g2 (multi-language) work you need the gettext extension of php. This can be enabled in php.ini. G2 does hint you for that. However gettext is a little strange extension.
  • Find

replace it with


But now comes the crux. php_gettext.dll is depending on \php-install-dir\dll\iconv.dll All other extensions work flawlessly for me. But gettext.dll required me to put iconv.dll into a dir that is included in the searchpath. E.g. /windows/system32 I then overreacted and copied all dll's to that /system32 dir. The manual of php 4 tells you to copy the dll's to the /php-install-dir/ but that only works if you add manually the php dir into the path statement of windows.

GD2 extension

Find the extension in your php.ini and remove the # in front of the line ;extension=php_gd2.dll

  • Find

replace it with


PHP.INI key values

Changing key php.ini values to suit the bigger demands of G2: The following values should be working for most of the gallery users. The max times have been upped just as a precaution. But I think that G2 overrides them anyway.

  • Find the following values and set to your needs.
max_execution_time = 300 ; Maximum execution time of each script, in seconds 
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data 
memory_limit = 32M ; Maximum amount of memory a script may consume (8MB)
upload_tmp_dir = "C:\Inetpub\wwwroot\uploads" ; Temporary directory for HTTP uploaded files.
post_max_size = 7M ; Maximum size of POST data that PHP will accept.
upload_max_filesize = 6M ; The maximum allowed size for uploaded files.
open_basedir = [path you want to use].  See: [1]

Set upload_max_filesize and post_max_size to whatever you need, but post_max_size MUST be >= the value you set for upload_max_filesize, and must be < the value in memory_limit.

Make PHP available to IIS

Set the system path to include C:\PHP

  • Click on My Computer -> Properties -> Advanced -> Environment Variables
  • Scroll down the System Variables (bottom window) and doubeclick on the PATH variable
  • Add the following to the end (make sure you add the initial semicolin)
  • Click OK

Make PHP.INI available to PHP

  • While you still have the Environment variables window open click new
  • In the Variable Name field enter
  • Set the Variable Value to

This will make PHP.INI available to PHP (We will verify this later)

Configuring IIS

You have a choice of whether to setup PHP to use the ISAPI extension, CGI executable, or using FastCGI. The ISAPI extension is not fully stable, and the CGI executable's performance is very poor because after every request the php-cgi.exe executable is unloaded. So if the php-cgi.exe executable is always loaded into memory then that would greatly increase the performance. There are two ways of doing this.
1. Spend $500 for Zend's own WinEnabler [2]
2. Setup the free FastCGI program that does the same thing as WinEnabler

The recommended way of running PHP on IIS is using FastCGI. Below you will find instructions on how to setup PHP using ISAPI but if your site is going to serve lots of pages, you will probably want to go with FastCGI.

Add the PHP ISAPI extension to IIS Web Service Extensions

  • Click on Start -> Administrative Tools -> Internet Information Services (IIS) Manager
  • Expand the local computer in the left pane
  • Click on "Web Service Extensions" in the left pane
  • In the right pane, click the blue underlined text, "Add a new Web service extension..."
  • Enter "PHP5 ISAPI" as the "Extension name"
  • Click the "Add..." button and browse to the php5isapi.dll file in your C:\PHP install directory
  • Click Open -> OK
  • Check the "Set extension status to Allowed" checkbox and click "OK"

Adding the PHP parsing to your IIS website

Note: You can add this either on the top-level Web Sites or to individual web sites beneath it. If you add it to the top-level web sites node in the left pane, it applies to all websites on the IIS instance. You can also choose to only install it on specific websites beneath the top-level node, in that case it will only apply to that site. The procedure for adding is the same for both scopes.

Be careful when applying this to the top-level node, as it will override settings defined in the individual websites beneath it.

  • In the left pane, expand Web Sites
  • Right Click the website you want to configure, and select properties
  • Open the Home Directory tab
  • Click Configuration
  • Then go to the Mappings tab
  • Click Add...
  • Enter the full path to php5isapi.dll in the "Executable" textbox or click the Browse button to browse your way to it. If you have followed the path recommendations in this guide, the fill path should be C:\PHP\php5isapi.dll
  • Enter .php in the Extension textbox
  • Select Limit to, enter GET,POST,HEAD
  • Click OK and verify that .PHP is now included in the Application extensions listbox
  • Click OK

This configures IIS to understand what to do with files ending with .php

Adding scripting permissions

  • While still having the Web Site Properties dialog box open, click Home Directory
  • Make sure that "Execute permissions" dropdown is set to "Scripts only".
  • Click OK

Setting up FastCGI

A good set of instructions for setting up FastCGI can be found here [3]. The basics are below.

  • Make sure you have PHP 4.3.x or later installed. Earlier versions of PHP require extra work to get FastCGI working.
  • Download the files at [4] and unpack isapi_fcgi.dll to c:\php\isapi_fcgi.dll.
  • Create a file using notepad named fastcgi.reg and insert the following text into it
Windows Registry Editor Version 5.00


  • Double click the file you just created to merge those settings into the registry.
  • Next setup FastCGI the same way as you would the ISAPI filter, except everywhere you see C:\PHP\php5isapi.dll you should replace that with C:\PHP\isapi_fcgi.dll

Testing PHP Installation

  • In the left pane, right-click on the website you are working with and select Properties
  • Then go to Home Directory
  • Check the Local Path. This shows you were that websites root directory is located (If you are working with the default IIS website, the location will be C:\INETPUB\WWWROOT\)
  • Create a new file called test.php in that location
  • The contents of test.php should be:
<?php phpinfo(); ?>

Now, you need to give the anonymous internet user account and NETWORK SERVICE account read/execute permissions on the C:\PHP directory, to allow IIS to parse the .PHP files. You do this by

  • Perform this for both the IUSR and NETWORK SERVICE accounts
  • Open My Computer
  • Right-click C:\PHP
  • Select Properties'
  • Go to the Security tab
  • Click Add
  • In the Enter object names to select textbox, enter IUSR
  • Click Check Names and it should expand it to NETWORK SERVICE/IUSR_ServerName
  • Click OK'
  • Verify that the Read & Execute, List Folder Contents and Read values are set to Read.
  • Click OK'

Open the test.php file via your browser, example:

A page showing your PHP configuration settings should now appear. If not, make sure you have followed ALL the steps outlined earlier in the guide.

Verify that PHP uses C:\PHP\PHP.ini by looking at the column for Configuration File (php.ini) Path Also, verify that MySQL support is loaded, and that the session_save.path is set to the correct values. If not, edit C:\PHP\PHP.ini again, set the values as outlined and then restart the IIS Web Service (IIS Manager->Right Click <servername>(Local computer)->All Tasks->Restart IIS).

After you have verified your PHP install, delete the test.php file from your website.

Installing Binaries

  • In IIS6 (Windows Server 2003) add Windows / IIS permissions: IIS_WPG permission on the g2data\tmp directory.
  • In IIS5 (Windows XP) give IWAM permissions to the g2data\tmp directory. At the command prompt enter the following command:
C:\>cacls \path\to\g2data\tmp /E /G %COMPUTERNAME%\IWAM_%COMPUTERNAME%:F


NOTE: The 6.4.2 windows binaries do not seem to play well with G2. After much testing, I finally installed the 6.4.1 binaries that i had working on my WinXP box, and that made IM work. See forum post: for more info and the binary I used. -Jrevillini 15:02, 18 July 2008 (UTC)

  • Download ImageMagick-6.2.3-0-Q16-windows-static.exe from, or the version Jrevillini found in his forum post linked above.
  • Install to C:\IM (or another location to your liking, but it's best kept in a folder structure without spaces in it)
  • Give IUSR account read/execute permissions on the folder where you just installed the ImageMagick binaries.
  • Give IUSR account read/execute permissions to cmd.exe (see bottom of article for more info on using cacls to do this)

NOTE: I had trouble successfully configuring the Image Magick plugin in Gallery unless the binaries were installed in a folder higher than the location set in open_basedir. Until I tried that all of the plugin path tests would fail. --Scn095 06:12, 1 January 2009 (UTC)




  • Download the latest SVN snapshot from celtic-druid. It is packaged in 7z format; so you will probably need 7-Zip File manager to unzip it. For convenience, you can download a zip version (rev9133) from geesu.
  • Specify the executable in Ffmpeg module configuration.


  • Download dcraw.exe from here or choose processor-optimized version from Benjamin Lebsanft website
  • Specify the executable in Dcraw module configuration.


  • Download the following files:
    • zip
    • unzip
    • Note: These files are the zip and unzip packages from cygwin, the appropriate dll must be included in the same directory for it to function
  • Extract the files to C:\zip
  • Give IUSR_machinename read/exec permissions on C:\zip

Permissions for Gallery2 Data Directory

Give COMPUTERNAME/IUSR_COMPUTERNAME Modify permission on the gallery2 data directory.



Why am I getting a CGI Application Error on my website or a "Error: HTTP POST failed (HTTP 502 Bad Gateway )" with gallery remote?

This can occur if you are uploading a file that takes over 300 seconds. Changing the max_execution_time variable in the php.ini above the default IIS value will not fix this problem. You need to change the CGITimeout property which is in the IIS metabase.

Some scripts are offered to help change this variable, but I prefer a GUI. Download this IIS Administration Pack and it will install metabase explorer.

Run the metabase explorer, then expand LM, and find W3SVC. Under this you will see a CGITimeout property, it should be set to 300 (that is the default). Increase this value so that your script can take longer to upload a file. Please realize though that ANY page hosted by IIS will have this timeout value, this is not set on a per site basis.

Why am I receiving a "Invalid access to memory location" error message?

Assuming you have installed PHP using the ISAPI dll. You now need to restart IIS. To do this, click start, then run, and type "iisreset /restart" then click ok. The problem *should* now be fixed.


  • make sure permissions are set on gallery2 dir, after copying. Permissions are not inherited when files/directories are copied within the same volume.
  • add index.php as directory index in web site configuration
  • permissions gallery2/config.php
  • cmd.exe, give (IUSR) execute permissions (module activation), or run from command line [cacls %COMSPEC% /E /G %COMPUTERNAME%\IUSR_%COMPUTERNAME%:R]
  • c:\windows\temp, give (USR) write permissions or have "Upload error: Upload failed" messages after uploading with Upload Applet.

hints for setting filepermissions:

You should use XCACLS, not CACLS to set permissions, CACLS doesn't correctly set inheritance.

Get XCACLS here:;amp;displaylang=en&familyid=0ad33a24-0616-473c-b103-c35bc2820bda&displaylang=en

{{{ XCACLS.vbs <path to your website>\gallery /E /G IUSR_<computernamehere>:M


XCACLS.vbs E:\inetpub\wwwroot\\htdocs\gallery /E /G IUSR_WEBSERVER1:M }}}