Wednesday, October 18, 2006

IIS, PHP 5.1.6 and MySQL

Today I needed to upgrade an IIS web server running PHP. The current PHP version on the server was 4.4.x and I was upgrading to PHP 5.1.6. Like many before me I discovered that MySQL functions were 'broken' following the upgrade as MySQL is not enabled by default in 5.1.x versions of PHP. Getting MySQL extensions working in conjunction with this upgrade/install seems to be problematic for some and so it proved for me. I am happy to say it is now working fine. I installed and tested both the CGI and ISAPI versions on a Windows 2000. By way of testing I also converted an existing 5.1.4 CGI installation on an XP box to the 5.1.6 ISAPI version. There is a lot of conflicting advice on the net and I suspect that many problem arise from mixing and matching snippets from various postings. I strongly suggest that you read this entire article before proceeding. Pre-installation If you have tried and failed with this install already please do the following:
  1. If you have copied any of the following DLLs to the windows\system32 folder remove them: php_mysql.dll, php_mysqli.dll, libmysql.dll, libmysqli.dll.
  2. If you have copied php.ini to the windows directory (or the file already exists there) remove it.
Installation — step by step guide
  1. Download and unpack the complete 5.1.6 distribution from www.php.net.
  2. Backup or rename your existing PHP install if required.
  3. Search your system for php.ini files. If you find one in the windows directory rename it or delete it.
  4. Create a c:\php directory.
  5. Copy all the files from the downloaded distribution to c:\php.
  6. Rename phpdist.ini to php.ini.
  7. Edit the extension_dir line in php.ini to say extension_dir="c:\php\ext".
  8. Uncomment the line in php.ini that says extension=php_mysql.dll. (To uncomment the line remove the comma at the start.)
  9. Configure App Mapping for each web/virtual server using the Internet Services Manager. For the CGI install the App Mapping should be c:\php\php-cgi.exe. For the ISAPI install the App Mapping should be c:\php\php5isapi.dll. To configure App Mapping run the Internet Services Manager and display the property pages for the each website to be configured. Click the Home Directory tab then Configuration. If there isn't an existing entry for .php you will need to Add one, otherwise Edit the existing. Browse to the required executable (either php-cgi.exe or php5isapi.dll). Click OK a few times and repeat as requiired.
  10. If you are configuring IIS for the ISAPI version the php.ini file must be in the windows directory so MOVE php.ini to the windows directory — move it DO NOT copy it. If you are configuring IIS for the CGI version then php.ini can either be in your php directory OR the windows directory but NOT both.
  11. Finally, add c:\php entry to the system path. To do this double-click the System icon in Control Panel and select the Advanced tab then click the Environment Variables button. In the System variables pane double-click the Path entry and at the end of the Variable Value entry add a semi-colon followed by c:\php.
  12. Reboot and then try connecting to a MySQL database from a PHP page.

0 Comments:

Post a Comment

<< Home