Simmons Consulting, the Website of Toby Simmons

Upgrading PHP from 4 to 5 on IIS

05
Jan

I needed to make some notes when starting the process of upgrading all our IIS web servers from PHP4 to PHP5. I have found a few gotchas (which might only apply in our circumstance.)

First of all, make a backup of your php.ini file in your %WINDIR%. The most important thing is to make a note of what extensions are enabled, so you can make sure you use the same settings for your new install.

Second, make sure you remove all traces of PHP4 before installing. If you installed it using an installer, go to Control Panels -> Add/Remove Programs and uninstall. If you did it manually, make sure you remove the script mapping for PHP in all of your web sites (php4isapi.dll if using ISAPI, php.exe if using FastCGI). You might also have to manually remove any copies of php4ts.dll in your %WINDIR% or %SYSTEMDIR%. Also, make sure the old PHP4 path isn’t in your %PATH% environment variable. Then delete your PHP4 install directory. Now reboot your server.

When your server is rebooted, the next step is to install PHP5. It is easiest to use the MSI installer available from php.net. I selected the PHP ISAPI for IIS, then I accepted the default install location, “C:\Program files\PHP”. When the installer prompts you for what components to install, only select the extensions you really need. Don’t just select all of them, because some will require other things to be installed which don’t come with PHP. The extensions I selected are Curl, Exif, GD2, Multi-byte string (which is required by Exif), Mcrypt, Mssql, Mysql and Mysqli. This list becomes important a bit later.

After you finish the install, you need to make sure your web user account (IUSR_MACHINENAME) has read and execute access to your PHP install directory.

Next, you need to edit your php.ini which starts out in your install directory. The edits I needed to make are first of all start a log file to catch PHP errors, so find the line where the setting for “error_log” is and make it something like

error_log = "C:\Program files\PHP\logs\err.log"

You will need to make sure the web user account has write access to this file.

Next, you will want to make sure the mbstring.dll extension is loaded before any of the others. If you don’t need this extension, you can skip this step.

Finally, you will want to change the location for your temp files. By default, it will put them in your logged on account’s temp folder. You need to change this to a folder that the anonymous web user account has write access to. The two entries I needed to change were:

upload_tmp_dir="C:\Temp"
session.save_path="C:\Temp"

Next, copy this php.ini file to your %WINDIR%.

The next thing I had to do was modify the script mapping in IIS. I went to all sites that have the PHP script mapping and edited it adding the “Check that file exists” option. I’ve found there are problems with PHP pages that require NTFS authentication without this change.

Reboot your server again.

Now, you can try loading a php page. I recommend you start with a simple

<?php phpinfo();  ?>

page. Check your error log to see if there were any errors. On one server, I ran into an error with loading mssql.dll and the mysql dlls. After running the installer again and selecting the “repair” option and rebooting again, this went away.

So far, I have upgraded two development machines. Now it’s time to do a real server!

One Comment »

  1. Toby Simmons says:

    The real server went as well as the development machines. Wahoo!

Leave a Reply to Toby Simmons

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>