To be able to run PHP analyses with Sonar, you will need:
- Sonar installed with its PHP plugin
- PHP environment (PHP and tools that are required by the plugin)
Installing Sonar
See Installing Sonar.
Installing Sonar PHP Plugin
- Install the Sonar PHP plugin through the Update Center or download it into the SONAR_HOME/extensions/plugins directory
- Restart the Sonar server
Installing PHP Environnement
This installation section provides two ways for installing necessary tools to make the plugin work correctly. If you are familiar with the PHP environnement, you may just need to read the "Short way" section, if you need more help, you can follow the more verbose installation guide.
Short way for PHP experts
- Install PHP runtime with the corresponding xdebug extensions. Version 5.2.6 or newer is required.
- Install PEAR. Version 1.8.0 or newer is required
- Install the following PEAR packages (check the version list to know which versions to install):
- Install PHPUnit
- Install phpcpd
- Install PHPDepend
- Install PHPMD
- Install PHP_CodeSniffer
Long way for PHP dummies
You have to be logged in as an administrator to run the commands below.
- Install PHP version 5.2.6 or newer. You can download PHP at this location and follow these installation instructions.
Install PEAR version 1.8.0 or newer if not included in PHP distribution. To ensure PEAR version and to upgrade it, type the following commands in command prompt:
If you, for some reason, need the latest PEAR and the commands above don't get it then download http://pear.php.net/go-pear.phar and execute it with php (don't use the old go-pear without the .phar extension, it will likely fail):
Install PHPUnit from pear using the following command lines:
- Install XDebug to allow code instrumentation used for instance by phpunit to compute coverage.
If you are running Linux or Mac, you must install phpize (normally found in php dev packages like rpm php5-devel, deb php5-dev) and then compile xdebug via pecl install using the following command line:
And then edit your $PHP_HOME/php.ini file to add the following line:
If you are running Windows, you should download the binary version matching your PHP installation from this location. And then edit your $PHP_HOME/php.ini file to add the following line:
Install PHP Depend:
Install PHPMD:
Install PHP_CodeSniffer:
Only if you're using PHP Plugin < 1.0: install phpcpd
Recommended version is 1.3.5
Start Sonar server and check that everything is correctly installed
You should see different quality profiles for the PHP language on the quality profiles page.
Now, choose how you want to analyze your project!
You are now ready to configure your project for a first analysis. Go to "Analyse a PHP project" to know how to launch a Sonar analysis on your project. Depending on the technology you will choose, you will have to write different configuration files.

