Skip to content

Instantly share code, notes, and snippets.

@textarcana
Last active September 12, 2016 05:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save textarcana/4679293 to your computer and use it in GitHub Desktop.
Save textarcana/4679293 to your computer and use it in GitHub Desktop.
Sonar for PHP installation steps for CentOS 6. See also http://docs.codehaus.org/display/SONAR/Installing+PHP+Environment as well as my Pinboard bookmarks for Sonar installation: https://pinboard.in/u:noahsussman/t:sonar+install
# Sonar for PHP installation for CentOS 6
# See http://docs.codehaus.org/display/SONAR/Installing+PHP+Environment
/sbin/service mysqld start
sudo /usr/bin/mysql_secure_installation
# for non-production instances, choose not to create a root password
mkdir /var/sonar
wget http://dist.sonar.codehaus.org/sonar-3.4.1.zip
unzip sonar-3.4.1.zip
# edit sonar-3.4.1/conf/sonar.properties
# and update sonar.web.host
# then comment out the default sonar.jdbc.url
# and uncomment the lines for jdbc mysql driver
wget --no-check-certificate https://raw.github.com/SonarSource/sonar/master/sonar-application/src/main/assembly/extras/database/mysql/create_database.sql
mysql -u root -p < create_database.sql
# edit /etc/my.cnf and add the following line to the [mysqld] block:
# max_allowed_packet=500M
# start sonar
sonar-3.4.1/bin/linux-x86-64/sonar.sh start
# Installing Sonar as a service.
# See http://docs.codehaus.org/display/SONAR/Running+Sonar+as+a+Service+on+Linux
#
# copy the etc_init_d_sonar file from this repo, to /etc/init.d/sonar
ln -s /var/sonar/sonar-3.4.1/bin/linux-x86-64/sonar.sh /usr/bin/sonar
chmod 755 /etc/init.d/sonar
chkconfig --add sonar
# download the sonar CLI
wget http://repository.codehaus.org/org/codehaus/sonar-plugins/sonar-runner/2.0/sonar-runner-2.0.zip
unzip sonar-runner-2.0.zip
# edit /var/sonar/sonar-runner-2.0/conf/sonar-runner.properties
# and uncomment the lines pertaining to mysql
# and uncomment and update the domain name of the sonar host
# and the line specifying character-encoding (the default of utf-8 is fine)
pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit-3.5.5
yum -y install php-devel
pecl install xdebug
# edit /etc/php.ini and add this line:
# zend_extension="/usr/lib64/php/modules/xdebug.so"
pear channel-discover pear.pdepend.org
pear install pdepend/PHP_Depend-1.0.3
pear channel-discover pear.phpmd.org
pear install --alldeps phpmd/PHP_PMD-1.3.2
pear install PHP_CodeSniffer-1.3.2
# Now visit your sonar instance in a browser and install the PHP plugin.
# See http://docs.codehaus.org/display/SONAR/PHP+Plugin
# Note the default Sonar user is named "admin" with password "admin"
#
# Sign in and go to Configuration (top nav) > Update Center (left nav)
# then click PHP > install and restart sonar
#
# Note when restarting Sonar that it takes about 30 seconds between
# the CLI says "starting sonar" and when the Web UI actually becomes
# available.
# Now test the install:
# Check out the example PHP project
# See https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/php/php-sonar-runner
git clone https://github.com/SonarSource/sonar-examples
cd sonar-examples/projects/languages/php/php-sonar-runner
/var/sonar/sonar-runner-2.0/bin/sonar-runner
#!/bin/sh
#
# rc file for Sonar
#
# chkconfig: 345 96 10
# description: Sonar system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Sonar system (www.sonarsource.org)
# Description: Sonar system (www.sonarsource.org)
### END INIT INFO
/usr/bin/sonar $*

Jenkins integration

My Jenkins master config looks like this (Using the default Sonar Web and MySQL DB passwords.):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment