Adding additional features to PHP

by Klaus Graefensteiner 1. March 2010 10:00

Introduction

This is the second article of a series of blog post called the WIMPinator Chronicles that describe how to setup a PHP development environment for Windows 7 and IIS 7.5.

In this part we are refining and enhancing the PHP runtime that we installed using the Web Platform Installer.

The blog post answers the following questions:

  • What flavors and versions of PHP are there for Windows and which one do I use for IIS or Apache?
  • What PHP runtime got installed by the Windows Platform Installer and how can I add additional features and extensions?
  • How do I modify my PHP.ini file to fix missing DLL (Dynamic Link Libray) errors?

The Series

  1. Getting a Wordpress blog installed in a jiffy on Windows 7 using the Web Platform Installer
  2. Adding additional features to PHP
  3. Installing PEAR and PHPUnit
  4. Installing Eclipse PDT
  5. Configuring Eclipse PDT to work with Subversion source control
  6. Configuring Eclipse to work with Ant build tasks
  7. Creating a new IIS 7.5 fast CGI web site
  8. Setting up XDebug with Eclipse and IIS 7.5
  9. Setting up the Zend Debugger with Eclipse and IIS 7.5
  10. Configuring Ruby and Watir
  11. Moving a Wordpress blog from GoDaddy shared hosting to my local debugging system.

PHP Versions and Flavors for Windows and IIS

In order to choose the right PHP runtime binaries you have to answer yourself the following questions:

What version of PHP do I need?

Is it 5.2, 5.3 or 6.0? It depends several things, like what version does your hosting provider support or does an extension that you need exist for the particular PHP version. In my case my hosting provider supports PHP version 5.2 and the Web Platform Installer also installs PHP 5.2.

What Operating System is PHP running on?

It’s Windows.

What CPU architecture is my computer running?

x86 (32-bit), x64 (64-bit) or IA64)? Web Platform Installer installs the x86 PHP binaries, which run on 32-bit and 64-bit Windows.

What http web server is PHP running under?

If you run on IIS you need the Non-Thread-Safe binaries. (nts).

If you run on Apache you need the Thread-Safe binaries (ts).

I am running on IIS, which means I need the Non-Thread-Safe binaries.

Note: Some extensions (DLLs) like for example the XDebug.dll come in a XDebug_TS.dll flavor and in a XDebug.dll incarnation. The binary without the “_TS” suffix is the Non-Thread-Safe version. The DLL that ends with “_TS” is the Thread-Safe library.

And at last but not least:

What VisualC/C++ Runtime Libraries are the PHP binaries linked against?

At this point, I see you shaking your head, but it is true, PHP also distinguishes the PHP runtime files based on which version of the C-Runtime is being used for linking. The options are VC6 or VC9.

The Web Platform Installer uses the VC6 version because it uses PHP 5.2 and PHP 5.2 only comes in the VC6 flavor. PHP 5.3 has a VC6 edition that is used for Apache and a VC9 compilation that you should use for IIS to gain some performance and stability improvements.

You can find some additional information here:

http://www.php.net/manual/en/install.windows.iis7.php

and here:

http://blogs.msdn.com/brian_swan/archive/2010/02/02/getting-started-with-php-on-windows.aspx

This all boils down to…

… the following situation: For downloading PHP 5.2 on IIS (Windows) you are left with two options:

http://us2.php.net/get/php-5.2.12-nts-Win32.zip/from/a/  (VC6, notice the nts in the name.)

http://windows.php.net/download/#php-5.2-nts-VC6-x86 (VC6, notice the nts in the name  – Gets installed by Web Platform Installer)

Enhancing the PHP runtime

The following information only applies, if you installed the PHP runtime using the Web Platform Installer (WPI). WPI only installs the bare minimum of PHP extensions and features that Wordpress require. If you need to interface with Oracle, SQL Server, SQLite or other database systems, or if you want to take advantage of any libraries that gets distributed over PEAR(PHP Extension and Application Repository), then you need to upgrade PHP using the correct Microsoft Software Installer (MSI) package.

The following screenshot shows the files that the basic WPI installed:

MinimalPHPWithoutPear_2

Figure 1: PHP folder after basic PHP install using the Web Platform Installer

Gotcha 1

This is the first gotcha somebody can run into. If you are searching the web for the correct version of the PHP Microsoft Software Installer package you will find the following download page:

PHP5.2.12Non-Thread-Safe-Windows-Installer(Not used by WPI)_2

Figure 2: The most popular PHP download for IIS is not used by WPI

The link to the popular download page is this one: http://us2.php.net/get/php-5.2.12-nts-Win32.zip/from/a/.

If you download and try to install this version you will run into a MSI error because the installer is going to expect a different installer package to complete the setup. It is basically looking for the one that the WPI used.

WPI uses the following version:

http://windows.php.net/download/#php-5.2-nts-VC6-x86

DownloadTheCorrectVersion(VC6)_2

Figure 3: Download page for the PHP installer used by WPI

DownloadingPHPVC6_2

Figure 4: Ready to download PHP 5.2.12 nts VC6

Do you recognize the different MSI package filenames?

DifferentPHPVersions_2

Figure 5: Showing a screenshot of the different PHP MSI packages

php-5.1.12-nts-win32-installer.msi (downloaded from popular PHP download page)

php-5.1.12-nts-win32-VC6-x86.msi (used by the Web Platform Installer WPI)

Ready to launch the installer

Double click on the just downloaded php-5.1.12-nts-win32-VC6-x86.msi.

PHPInstallationWizard_2

Figure 6: Welcome to the PHP 5.2.12 Setup Wizard

Because PHP is already installed the wizard is presenting the Change, Repair or Remove option screen. Click the Change button to add additional features.

ChangePHPFeatures_2

Figure 7: Click Change button to install additional featuers

Select the IIS FastCGI option.

PHPInstallSetupWebServerIISFastCGI_2

Figure 8: Selecting the IIS FastCGI option

Select all Script Executables and Extras.

PHPInstallationSelectAllOptions_2

Figure 9: There is more to select

PHPInstallationAllOptionsSelected_2

Figure 10: Added everything (this for my development machine)

Note: On a production server you would only select the features that you actually need.

Click Finish and the Installer wizard will complete.

PHPFeatureChangeComplete_2

Figure 11: Ready to Finish the PHP installation wizard

Now all features are installed, but unfortunately we are not quite done yet. we selected far too many features and chances are that some of the dependencies of some of the extensions are not available and will cause exception messages. The next paragraph is going to cover this problem in more detail.

Fixing missing DLL errors in PHP.ini

One way to verify that PHP is configured correctly after the installation is to run php –m in an Administrator command prompt. php –m is trying to iterate over all configured PHP extensions. Most likely you will encounter some of the following errors that can be fixed by modifying the php.ini file.

ListOfBadModulesAfterPHP-m_2

Figure 12: The snmp extensions are not working

Depending on what you have installed on your computer you might get many message boxes complaining about missing DLLs.

ProblemsAfterRunningPHP-m1_2

Figure 13: MSVC71.dll is missing (There might be multiple instances of this dialog)

 ProblemsAfterRunningPHP-m2_2

Figure 14: OCI.dll is missing (Oracle client software is not installed on this computer)

ProblemsAfterRunningPHP-m5_2

Figure 15: SQLite3.dll is missing (SQLite is not installed on this computer)

ProblemsAfterRunningPHP-m8_2

Figure 16: libcs.dll is missing

This is not a complete list. The procedure for fixing these kind or errors is to look for extensions that refer to DLLs with similar names and try to comment them out in the PHP.ini file. Then run php –m again. If the errors are not showing up anymore then you are done otherwise try some other extension. Repeat this until you know which extensions cause which error.

The following two screenshots show my php.ini file before and after commenting the extension that cause my missing DLL errors.

Here is the original php.ini extension section after the install.

ModifyPHP_INI_2

Figure 17: Original php.ini extension section

Here is the modified php.ini after commenting out the “bad” behaving extensions:

Note: You need to open the file as Administrator, otherwise you will not be able to save the modified file.

ModifiedPHP_INI_2

Figure 18: Modified php.ini file

Here is an excerpt of the php.ini file that shows what I commented out to make the loading errors go away.

[PHP_CURL] 
extension=php_curl.dll 
[PHP_GD2] 
extension=php_gd2.dll 
[PHP_GETTEXT] 
extension=php_gettext.dll 
[PHP_IMAP] 
extension=php_imap.dll 
[PHP_MBSTRING] 
extension=php_mbstring.dll 
;[PHP_MSSQL] 
;extension=php_mssql.dll (requires mscrt71.dll) 
[PHP_MYSQL] 
extension=php_mysql.dll 
[PHP_MYSQLI] 
extension=php_mysqli.dll 
[PHP_OPENSSL] 
extension=php_openssl.dll 
[PHP_PDO] 
extension=php_pdo.dll 
[PHP_PDO_MYSQL] 
extension=php_pdo_mysql.dll 
[PHP_PDO_SQLITE] 
extension=php_pdo_sqlite.dll 
[PHP_SOAP] 
extension=php_soap.dll 
[PHP_TIDY] 
extension=php_tidy.dll 
[PHP_XMLRPC] 
extension=php_xmlrpc.dll 
[PHP_ZIP] 
extension=php_zip.dll 
[PHP_EXIF] 
extension=php_exif.dll 
[PHP_WINCACHE] 
extension=php_wincache.dll 
[PHP_BZ2] 
extension=php_bz2.dll 
[PHP_DBA] 
extension=php_dba.dll 
[PHP_DBASE] 
extension=php_dbase.dll 
[PHP_FDF] 
extension=php_fdf.dll 
[PHP_GMP] 
extension=php_gmp.dll 
[PHP_INTERBASE] 
extension=php_interbase.dll 
[PHP_LDAP] 
extension=php_ldap.dll 
[PHP_MCRYPT] 
extension=php_mcrypt.dll 
[PHP_MHASH] 
extension=php_mhash.dll 
[PHP_MIME_MAGIC] 
extension=php_mime_magic.dll 
[PHP_MING] 
extension=php_ming.dll 
[PHP_MSQL] 
extension=php_msql.dll 
;[PHP_OCI8] 
;extension=php_oci8.dll 
[PHP_PDO_FIREBIRD] 
extension=php_pdo_firebird.dll 
;[PHP_PDO_MSSQL] 
;extension=php_pdo_mssql.dll (requires mscrt71.dll) 
;[PHP_PDO_OCI] 
;extension=php_pdo_oci.dll 
;[PHP_PDO_OCI8] 
;extension=php_pdo_oci8.dll 
[PHP_PDO_ODBC] 
extension=php_pdo_odbc.dll 
[PHP_PDO_PGSQL] 
extension=php_pdo_pgsql.dll 
;[PHP_PDO_SQLITE_EXTERNAL] 
;extension=php_pdo_sqlite_external.dll 
[PHP_PGSQL] 
extension=php_pgsql.dll 
;[PHP_PSPELL] 
;extension=php_pspell.dll 
[PHP_SHMOP] 
extension=php_shmop.dll 
;[PHP_SNMP] 
;extension=php_snmp.dll 
[PHP_SOCKETS] 
extension=php_sockets.dll 
;[PHP_SQLITE] 
;extension=php_sqlite.dll 
;[PHP_SYBASE_CT] 
;extension=php_sybase_ct.dll 
[PHP_XSL] 
extension=php_xsl.dll

Finally the content of the PHP folder should look similar to this after installing all features and extensions:

NewPearFilesAfterGo-PearInstall_2

Figure 19: PHP folder after installing all features and extensions

Ausblick

Instead of finding the correct MSI installation package to update the PHP deployment, I also tried uninstalling it completely and installing it form scratch, with success.

In the next blog post in the WIMPinator Series I am going to describe how to get PEAR working and install the PHPUnit unit testing framework.

Tags: , ,

Wordpress | Test Automation | Php | Debugging | WIMPinator Chronicles | Tips & Tricks

Comments

2/1/2012 2:03:55 PM #

trackback

Creating a new IIS 7.5 Fast CGI web site for your PHP project

Creating a new IIS 7.5 Fast CGI web site for your PHP project

Tellingmachine |

Comments are closed

About Klaus Graefensteiner

I like the programming of machines.

Add to Google Reader or Homepage

LinkedIn FacebookTwitter View Klaus Graefensteiner's profile on Technorati
Klaus Graefensteiner

Klaus Graefensteiner
works as Developer In Test and is founder of the PowerShell Unit Testing Framework PSUnit. More...

Open Source Projects

PSUnit is a Unit Testing framwork for PowerShell. It is designed for simplicity and hosted by Codeplex.
BlogShell is The tool for lazy developers who like to automate the composition of blog content during the writing of a blog post. It is hosted by CodePlex.

Administration

About

Powered by:
BlogEngine.Net
Version: 1.6.1.0

License:
Creative Commons License

Copyright:
© Copyright 2012, Klaus Graefensteiner.

Disclaimer:
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Theme design:
This blog theme was designed and is copyrighted 2012 by Klaus Graefensteiner

Rendertime:
Page rendered at 2/4/2012 5:10:35 AM (PST Pacific Standard Time UTC DST -7)