Wednesday, May 29, 2013

NetBeans IDE 7.4: Installing PHP Mess Detector & PHP_CodeSniffer on Windows 7

Installing Pear

Assuming you already have PHP installed and your PHP installation directory is written in the Windows environment variable PATH:
  1. Go to to download go-pear.phar to your PHP installation directory.
  2. Run the Windows Command Processor (cmd.exe).
  3. Run >php go-pear.phar
  4. Select system for the install type.
  5. Next you will be shown the paths that PEAR will use. You want to change "all" so that Pair is installed in a suitable directory such as C:\php\pair\.
  6. Do not install the pear.ini file in the Windows installation directory, instead change it (number 11) to your pair installation directory c:\php\pear\pear.ini. To do this type 11, press enter, then type c:\php\pear\pear.ini.
  7. After the install has finished run c:\php\PEAR_ENV.reg and restart Windows to finish the installation.
Installing PHP CodeSniffer
  1. Run the Windows Command Processor (cmd.exe).
  2. Change directories to the PHP install directory (C:\php\pair\).
  3. Run >pear install PHP_CodeSniffer-1.4.5 (or whichever version you like). You will see a similar screen:
    Unknown remote channel:
    Did not download optional dependencies: channel://, use
     --alldeps to download automatically
    pear/PHP_CodeSniffer can optionally use package "channel://
    downloading PHP_CodeSniffer-1.4.5.tgz ...
    Starting to download PHP_CodeSniffer-1.4.5.tgz (377,255 bytes)
    e: 377,255 bytes
    install ok: channel://
    PHP_Timer is optional, follow the instructions if you would like to install it along with PHP_CodeSniffer.
Installing PHP Mess Detector
  1. Run the Windows Command Processor (cmd.exe).
  2. Run >pear channel-discover
  3. Run >pear channel-discover
  4. Run >pear install phpmd/PHP_PMD-1.4.1. You will see a similar screen:
    Did not download optional dependencies: pecl/imagick, use --alldeps to download
    pdepend/PHP_Depend can optionally use package "pecl/imagick" (version >= 2.2.0b2
    downloading PHP_PMD-1.4.1.tgz ...
    Starting to download PHP_PMD-1.4.1.tgz (46,814 bytes)
    .............done: 46,814 bytes
    downloading PHP_Depend-1.1.0.tgz ...
    Starting to download PHP_Depend-1.1.0.tgz (182,692 bytes)
    ...done: 182,692 bytes
    install ok: channel://
    install ok: channel://
    pecl/imagick is optional, follow the instructions if you would like to install it along with PHP_PMD.
Installing PHP Mess Detector & PHP CodeSniffer in NetBeans IDE 7.4
  1. Go to Tools>>Options>>PHP>>Code Analysis
  2. For the "Code Sniffer:" field, browse to C:\PHP\pear\phpcs.bat to install PHP_CodeSniffer.
  3. For the "Mess Detector:" field, browse to C:\PHP\pear\phpmd.bat to install PHP Mess Detector.
  4. Find the "[Date] date.timezone =" in the php.ini file and set it to a proper timezone.


  1. how do you actually USE the sniffer though

    1. Go to Source >> Inspect and in the Configuration combo box choose "Code Sniffer". Click the Inspect button an It will then scan your project and give you a line by line analysis of potential "messes".

  2. Oh wow..I've been scouring the web for the past hour to find how to use Code Sniffer in Netbeans and eventually found it in a comments section..Everybody's telling you how to install it and that's the part I figured out myself...smh.

  3. Short and useful, many thanks!