logo
Published on john.parnefjord.se (http://john.parnefjord.se)

PHP5 on IIS5.1/IIS6

By johnp
Created 2007-12-20 08:55

Installation

Installing PHP5 on IIS5.1/IIS6 proved harder than I initially thought, much due to some minor issues that gave some very odd failures. Anyway this is how I installed PHP5 and solved the different obstacles that I ran into.

Download the msi-package from http://www.php.net/downloads.php [1]. Some argue that you should go for the zip package, as they claim that the msi-package doesn't work. Well, it does work.

Start the installation. Install the ISAPI filter for IIS. During installation do not install all extensions to start with. Start with one you need as it is easier to debug and the script will create the extension dir for you. If a new extension is needed after installation is performed then open Add/Remove programs from the control panel, click Change for PHP5. Here is an important update. When you have later verified that PHP5 works you might just as well install all modules at once and thereafter disable them by commenting them in php.ini.

The reason for this is an annoyance that exists in the installer. Every time it runs the path to the ISAPI-filter under mappings is changed to a DOS 8.3 filename and does not work properly. You have to manually correct it to a full path. In that case it is better to install all modules from start and comment all of them immediately in php.ini. As new modules are needed, just remove the comment in php.ini and restart the web server. If running the installer then remember to do the path change as well for the ISAPI-filter, something that I most likely would forget and if there is someone else trying to do the change it isn't likely that he or she would spot the problem right away.

By default the files will be installed in C:\Program Files\PHP. You can change this according to you own needs, but the examples use the default installation path.

Configuration

Add C:\Program Files\PHP to Windows PATH environment variable.

Create a new system environment variable called PHPRC. This tells the processor where to find php.ini, so in this case it should be C:\Program Files\PHP.

Using IIS6, check under Web Service Extensions that the PHP ISAPI-filter is set to Allowed. The installation script should take care of this, if not do the following. Open up the IIS Manager, go to Web Service Extensions, choose Add a new Web service extension, enter a name such as PHP, choose the Add button and for the value browse to the ISAPI file php5isapi.dll, then check Set extension status to Allowed and click OK.

In order to use index.php as a default page, choose Add under the Documents tab. Enter index.php and click OK.

Under Home Directory then Virtual Directory or Directory, do the following:

Create the following directories/files under PHP installation dir.

The IIS user (usually IUSR_MACHINENAME) needs permission to read various files and directories, such as php.ini, docroot, and the session tmp directory. I added IUSR_MACHINENAME to be able to read from web root and to be able to read and write to sessions and uploads directories and just write to error.log, but no execute permissions on these dirs!

php.ini settings

When you install extensions they will by default live in the subfolder ext in the installation directory. Set extensions directory to

extension_dir = "C:\Program Files\PHP\ext" 

The error_log can be of good help during setup. After that I disable this as the log can grow really fast if the log level is set too high. To turn on logging set value:

error_log = "C:\Program Files\PHP\logs\error.log" 

Set appropriate values for session.save_path and upload_tmp_dir according to the directories created above:

upload_tmp_dir="C:\Program Files\PHP\uploads"
session.save_path="C:\Program Files\PHP\sessions"       

If you are NOT running virtual hosts you can set doc_root to

doc_root = "C:\inetpub\wwwroot"

Otherwise this value will just lead to problems like "No input file specified"-error. Most annoying. So if you run Virtual Hosts see to that doc_root is commented or if it's already set on a server with virtual hosts and want to remove it, you have restart the WWW service afterwards, it won't do just to restart the web sites in IIS.

Enable the extensions in php.ini you want to use by uncommenting the extension=php_xxxxx.dll lines in php.ini. If you add new extensions using the method described in the beginning the script will automatically add the extension for you, but nevertheless you might need to configure the options of that specific extension.

In a production environment change the level of error reporting to something not so verbose, for example just report errors:

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

For security reasons always turn these off:

allow_url_fopen = Off
allow_url_include = Off 

If file uploads to web server isn't needed from start then it can be disabled by setting this value:

file_uploads = off

Source URL:
http://john.parnefjord.se/node/42