I regularly visit forums, stack overflow, IRC channels to ask questions and giving back open source community whatever possible for me. Obviously I learned much from those places and owe them. One of the common questions asked on community how to setup development environment. Obviously not basic one but advanced like how to setup Pear, Composer, XDebug, PHP Unit etc. All these are vital tools for development. So I’m trying to cover all these common questions on one single post.

Please note here I’m setting advanced PHP development environment on Windows 7.

WAMP: PHP cannot work standalone but need a web server to execute and database for getting data. WAMP is good all in one package for windows. Download WAMP server from http://www.wampserver.com/en/. Select right package as per your need for example 64 bits or 32 bits.

Once downloaded, double click the downloaded package to install WAMP. I personally do not prefer to install software on C drive so I installed it at D:\wamp. Decide where you want to install wamp.

With WAMP installed, you have PHP as well. You might need to run PHP from command line. It is therefore recommended to add PHP path in your system path as follow.

  • First check where it is. For me path is ‘D:\wamp\bin\php\php5.3.13’ as I installed WAMP on D drive and got PHP version 5.3.13 with that. For you, it may be different based on where you installed and What PHP version you got with WAMP.
  • Now right click on ‘My Computer’ (Simly ‘Computer in Windows 7) and click on ‘Properties’.
  • Click on ‘Advanced System Settings’.
  • Click on ‘Environment Variables’ under ‘Advanced’ tab.
  • Now under ‘System variables’, double click on ‘PATH’.
  • Under variable value, add ‘D:\wamp\bin\php\php5.3.13;’ (or whatever correct path is) before the value. Make sure you add semicolon (;) at the end.

Now open shell (dos prompt) and enter command ‘php –version’. It should display correct version.

With PHP available on shell, next big thing is to install Pear. Pear stands for PHP Extension and Application Repository. As the name suggest, it is important to install many PHP extensions and application. A good developer system must be always ready with PEAR to install any required PHP extension. The one which we need immediately is PHPUnit. So first lets install Pear.

  • First download http://pear.php.net/go-pear.phar and save it in PHP directory. For me, I saved it at ‘D:\wamp\bin\php\php5.3.13’, same as PHP path we set earlier.
  • Now open command prompt as administrator. To open command prompt as administrator, right click on ‘start>All Programs>accessories>command prompt’ and select ‘Run as Administrator’.
  • Go to PHP directory. For me, I entered following commands:
    cd wamp\bin\php\php5.3.13
  • Enter command php –d phar.require_hash=0 go-pear.phar
  • Enter ‘system’ and on next screen, just press enter to keep default options.
  • On next screen, press ‘y’.
  • Now go to php directory and double click on PEAR_ENV.reg
  • Congratulation, Pear is installed on wamp.

Installing PHP unit

Any serious developer must write unit test for their code. However before you could actually run you unit tests, you must install PHP unit as follow.

  • Close previous command prompt.
  • Open new command prompt as administrator.
  • Enter command
    pear chanel-discover pear.phpunit.de
  • Above command will add PHP unit’s pear channel to your pear, if not already added.
  • Enter command
    pear install phpunit/PHPUnit
  • This command will download PHP unit and install it to folder pear/PHPUnit of your php path.

PHP Unit tutorial is out of scope of this article. If you are not already aware of PHP unit, go through PHP Unit tutorial available on official site and many other sites.

Well we now have PHP running, Pear installed so we can download dependency any time and de facto PHP unit testing framework PHPUnit. Is it sufficient? No, there are many more things to be installed to make perfect development environment. However to keep the readable limit of blogs, lets cover remaining parts in Part 2 of this blog post, that should be available next week.