Enabling PHP PECL extensions for Windows

One of the biggest strengths of PHP as a programming language is the extensibility you're able to achieve through the use of the PHP Extension Community Library, or PECL for short. These libraries give the programmer easy access to functionality to perform a wide variety of tasks such as caching, authentication, encryption and image manipulation just to name a few. In this guide we'll cover the relatively simple task of installing these PECL extensions into your PHP environment under the Windows family of operating systems.

Download your PECL extensions

Although there are several free compiler options for Windows, most open source packages for Windows are offered already compiled into binaries ready for use. PECL is no different. You'll find that most of the commonly used PECL extensions are included with your core PHP installation package, or are downloaded in a separate package. This however still does not account for all the available PECL extensions. For example the PECL Win32 Binaries package for PHP 5.2.4 includes 74 of the C complied PECL extensions, however if you goto the home of Win32 PECL Binaries you'll find it houses 111 extensions. Most likely you will not need these extra PECL extensions, but if you do you'll need to goto PECL4WIN where you can download these PECL extensions individually, or as a complete package for your particular version of PHP.

Check you extensions directory

Once you have downloaded you PECL extensions, then you'll need to put them in a place where PHP can get to them. In PHP4 this is usually in a directory called "extensions" in the root of your PHP directory, and with PHP5 it is in a directory also in the PHP root called "ext". This is only standard structure though, and the best way to check is to open up your php.ini file and look for a directive called "extension_dir". The path specified for this directive is where PHP will look when loading you PECL extensions.

List and enable your PECL extensions

Now that you have extracted your PECL binaries to your PECL extensions directory, the next step is to make sure they are all listed in php.ini, and finally enable the required extensions. PECL extensions are listed in php.ini like this;

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll

To enable a PECL extension in php.ini all you need to do is remove the semicolon (;) from infront of the PECL extension in question, so to load the curl and exif extensions from above your extension list would look like this;

;extension=php_bz2.dll
extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
extension=php_exif.dll
;extension=php_fdf.dll

Now as there are 111 PECL extensions currently available from the PECL4WIN site, you don't really want to be listing these out manually. Below is the code from a small batch file I wrote which lists out all the PECL extensions in your extensions directory, and outputs the list into a text file called "ext.txt" along with the semicolon prefix.

@Echo Off
cls
Echo Retrieving list of PECL Extensions...
FOR /R X:\path\to\php\ext %%G IN (php_*.dll) DO echo ;extension=%%~nxG >> ext.txt
Echo Complete. Copy contents of ext.txt into php.ini...

To use this code, simply copy it to a file with a .bat or .cmd extensions (e.g. ext.bat) in your PHP extension directory and change the path in the FOR loop to reflect the full path to your PHP extensions directory. Once you have that done that simply execute the script and copy and paste the contents of the output file over the top of the existing extensions list in php.ini. As mentioned though you can also just manually type in each additional extension to the extensions list in php.ini, the script above just does it all for you so you don't miss or misspell extension names.

Save and verify

Now that you have downloaded all the required PECL extensions into your PHP extensions directory, listed them in php.ini and enable those required, it is time to test they are loaded. To do this we'll use the phpinfo function to view the PHP environment. Firstly you'll need to save your php.ini file, and then restart IIS. Create a file with a .php extension (e.g. phpinfo.php) in your website directory and enter the following code;

<?php
phpinfo
();
?>

Save this and then point your Web browser to this new file (e.g. www.example.com/phpinfo.php) to view your PHP environment. Some considerations to keep in mind are that not all PECL extensions are compatible with IIS when using PHP in ISAPI mode as discussed in my article on the difference between PHP thread safe and non thread safe binaries. Also be mindful that a lot of the extensions are dependent on other DLL's being present and PATH environment variables being set in order to work. If these are missing then you are likely to see errors on screen when restarting IIS with the offending extension(s) enable. For this reason I would recommend only enabling extensions one at a time and only as you need them. As always, if you are having any issues I'll be happy to help if you post here or in my forums.


Average rating
(0 votes)
|
Submitted by Dominic Ryan on Tue, 2007-10-02 14:17.

Post new comment

  • Use <!--pagebreak--> to create page breaks.
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will automatically be converted to links.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.