Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current ·  View Page History

To be able to run PHP analyses with Sonar, you will need:

  • A Java Runtime Environment (version > 1.5)
  • A database (optional if you're evaluating the plugin)
  • Sonar installed with its PHP plugin
  • All the PHP environment (PHP and tools that are required by the plugin)

Install a Java Runtime Environment (JRE)

Check the different supported Java virtual machines (see "Supported platforms > Java") that you can install.

To be sure you have correctly installed a JVM, open a terminal a run "java -version": you should see the version of Java you've just installed.

Install a database (optional if you're evaluating the plugin)

Check the different supported databases (see "Supported platforms > Database") that you can install.

You are not obliged to install a database if you just plan to evaluate the PHP plugin (Sonar embeds its own Derby database for test purposes). However, if you plan to go into production, do not rely on Derby but install a real RDBMS like MySql, Oracle, Postgres, ...

Install Sonar PHP Plugin

Sonar PHP Plugin is very straightforward: once you have installed sonar in "$SONAR_HOME" directory, just copy the sonar-php-plugin.jar file inside "$SONAR_HOME/extensions/plugins" directory.

Install 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 reed the "Short way" section, if you need more help, you can follow the more verbose installation guide.

Short way for PHP experts
  1. Install PHP runtime with the corresponding xdebug extensions. Version 5.2.6 or newer is required.
  2. Install PEAR. Version 1.8.0 or newer is required
  3. Install the following PEAR packages (check the version listto know which versions to install):
    1. Install PHPUnit
    2. Install phpcpd
    3. Install PHPDepend
    4. Install PHPMD
    5. Install PHP_CodeSniffer
Long way for PHP dummies
  1. Install PHP version 5.2.6 or newer. You can download PHP at this location and follow these installation instructions.
  2. Install PEARversion 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.pharand execute it with php (don't use the old go-pear without the .phar extension, it will likely fail):

  3. Install PHPUnit from pear using the following command lines:

  4. Install XDebug to allow code instrumentation used for instance by phpunit to compute coverage.
    • If you are running Linux or Macyou 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/cli_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/cli_php.ini file to add the following line:

  5. Install PHP Depend

  6. Install PHPMD

  7. Install PHP_CodeSniffer

  8. 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.

Labels
  • None