Finn Dan Budo Was Made In Finland
In the 1980' there was a Finnish company making Karate training outfits. This was their emblem.

Installing PHP development environment in Microsoft Windows

PHP is still one of the most used development environment and programming language in the Web today.

This story was motivated by the need to have some of the PHP tools available for JetBrains PhpStorm, which is a remarkably advanced editor for better PHP development.

Also the need for running certain Grunt tasks that depend on PHP tools such as Mess Detector and CodeSniffer.

Further down the line, having a simple development environment available will ease the transition from copying 3rd party libraries to using tools like Composer and Phing for resolving project dependencies.

Install PHP

Download the pre-build binaries from windows.php.net.

At the moment I am still using PHP 5.4, while version 5.5 is becoming slowly dominant.

Due to the slowness, I will keep using the latest version of 5.4 until all the extensions, libraries and server hosting companies that are somehow affecting my life, have updated their version compatibility to 5.5.

Mean while downloading the PHP 5.4.19, VC9 x86 Non Thread Safe (2013-Aug-21 17:47:47).

  • Zip [15.88MB]
  • Debug Pack [8.1MB]

Once downloads have been completed, unzip both to C:\development\php\5.4.19.

The directory structure is further discussed in another story.

Rename php.ini-development to php.ini and edit it by setting

memory_limit = 512M
include_path = ".;C:\development\php\5.4.19\pear"
extension_dir = "ext"
date.timezone = Europe/Helsinki
date.default_latitude = 60.174306261926034
date.default_longitude = 24.983339309692383

Create new environment variable called PHP_BIN and set its value to C:\development\php\5.4.19. Add this new variable to the list of values in the PATH variable, such as %PHP_BIN%. Different path values are separated with ; from each other.

This will make the PHP, pear and other commands from the above directory to be available from anywhere in the command prompt.

Install Pear

Pear is the old school PHP package repository, abbreviated from PHP Extension and Application Repository.

Download the go-pear.phar and while with command prompt, in the PHP directory set up above, the installation of Pear can be initiatied with the following command:

php go-pear.phar

Further information about the installation process, and of the commands which the pear tool will listen, are documented in the Pear user guide.

Now running pear config-show should yield output similar to the one shown below.

 CONFIGURATION (CHANNEL PEAR.PHP.NET):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          C:\development\php\5.4.19
PEAR documentation directory   doc_dir          C:\php\pear\docs
PHP extension directory        ext_dir          ext
PEAR directory                 php_dir          C:\development\php\5.4.19\pear
PEAR Installer cache directory cache_dir        C:\Users\paazio\AppData\Local\Temp\pear\cache
PEAR configuration file        cfg_dir          C:\php\pear\cfg
directory
PEAR data directory            data_dir         C:\php\pear\data
PEAR Installer download        download_dir     C:\Users\paazio\AppData\Local\Temp\pear\download
directory
PHP CLI/CGI binary             php_bin          C:\development\php\5.4.19\php.exe
php.ini location               php_ini          <not set>
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         C:\Users\paazio\AppData\Local\Temp\pear\temp
PEAR test directory            test_dir         C:\php\pear\tests
PEAR www files directory       www_dir          C:\php\pear\www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            0
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          c:\gnupg\gpg.exe
Signature Key Directory        sig_keydir       C:\Windows\pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         C:\Windows\pear.ini
System Configuration File      Filename         C:\Windows\pearsys.ini

run PEAR_ENV.reg in order to have few pear specific environment variables available for the current user, thus fixing the options shown above.

The output of pear config-show should now look like something similar to:

CONFIGURATION (CHANNEL PEAR.PHP.NET):
=====================================
Auto-discover new Channels     auto_discover    <not set>
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          C:\development\php\5.4.19
PEAR documentation directory   doc_dir          C:\development\php\5.4.19\docs
PHP extension directory        ext_dir          ext
PEAR directory                 php_dir          C:\development\php\5.4.19\pear
PEAR Installer cache directory cache_dir        C:\Users\paazio\AppData\Local\Temp\pear\cache
PEAR configuration file        cfg_dir          C:\development\php\5.4.19\cfg
directory
PEAR data directory            data_dir         C:\development\php\5.4.19\data
PEAR Installer download        download_dir     C:\development\php\5.4.19\tmp
directory
PHP CLI/CGI binary             php_bin          C:\development\php\5.4.19\php.exe
php.ini location               php_ini          <not set>
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         C:\development\php\5.4.19\tmp
PEAR test directory            test_dir         C:\development\php\5.4.19\tests
PEAR www files directory       www_dir          C:\development\php\5.4.19\www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            0
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          c:\gnupg\gpg.exe
Signature Key Directory        sig_keydir       C:\development\php\5.4.19\pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         C:\development\php\5.4.19\pear.ini
System Configuration File      Filename         C:\development\php\5.4.19\pearsys.ini

Once the configuration is parsed from the correct file, some of the settings can be changed. A list of the different configuration settings are available at the Pear user guide

pear config-set preferred_state beta
pear config-set php_ini C:\development\php\5.4.19\php.ini
pear config-set auto_discover 1

Install few useful tools

PHP CodeSniffer, for checking the quality of code against several coding standards.

pear install --alldeps PHP_CodeSniffer

PHP Mess Detector, for detecting bad quality code.

pear channel-discover pear.phpmd.org
pear channel-discover pear.pdepend.org
pear install --alldeps phpmd/PHP_PMD

PHPUnit, for unit testing.

pear install --alldeps pear.phpunit.de/PHPUnit

PHP_CompatInfo, for finding out the minimum version and the extensions required for a piece of PHP code to run. Will be available as pci via command prompt.

pear install --alldeps bartlett.laurent-laville.org/PHP_CompatInfo

phpDocumentor 2, for creating HTML documentation out from comments and structure of code.

pear install --alldeps pear.phpdoc.org/phpDocumentor

Phing

pear install --alldeps pear.phing.info/phing

Install Composer

Download the latest snapshot of composer.phar and place it to C:\development\php\5.4.19\composer.

Install it by running the command below in the above mentioned directory.

php composer.phar init
php composer.phar update

The initialisation creates the required composer.json, which in this case will be the global one. The one created in my case, just by clicking through the command line wizard:

{
    "name": "paazio/composer",
    "authors": [
        {
            "name": "Juga Paazmaya",
            "email": "olavic@gmail.com"
        }
    ],
    "require": {

    }
}

The second command will end up doing nothing since there are no requirements set in the configuration. It will however download the basic files needed for Composer.

There does exist an installer which essentially downloads the latest snapshot, but places it to C:\ProgramData\Composer which might not be the most convenient place if all development tools are to be kept in the same place.

Also by downloading it by hand to the above specified location makes it easier to remember where it was placed and makes updating easy as well.