Sonarqube code detection
Install the java environment
Slightly
2. Download the sonarqube package
Download address of sonarqube and sonar-runner: http://www.sonarqube.org/downloads/
Extract the downloaded package to the specified directory and configure the environment variables:
Mkdir / usr/local/sonarunzip-o sonarqube-5.1.1.zip-d / usr/local/sonarunzip-o sonar-runner-dist-2.4.zip-d / usr/local/sonarvim / etc/profileexport JAVA_HOME=/usr/java/latestexport CLASSPATH=/usr/java/latest/lib:/usr/java/latest/jre/libexport SONAR_HOME=/usr/local/sonar/sonarqube-5.1.1export SONAR_RUNNER_HOME=/usr/local/sonar/sonar-runner-2.4export PATH=$PATH:$JAVA_ HOME/bin:$JAVA_HOME/jre/bin:$RONAR_RUNNER_HOME/bin
3. Configure mysql, create sonar database, and authorize
Mysql > create database sonar;mysql > grant all on sonar.* to sonar@'localhost' identified by 'sonar'
4. Modify the configuration file of sonarqube
Vim / usr/local/sonar/sonarqube-5.1.1/conf/sonar.propertiessonar.jdbc.username=sonarsonar.jdbc.password=sonarsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
5. Modify the configuration file of sonar-runner
Vim / usr/local/sonar/sonar-runner-2.4/conf/sonar-runner.propertiessonar.host.url= http://0.0.0.0:9000sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8sonar.jdbc.username=sonar sonar.jdbc.password=sonarsonar.sourceEncoding=UTF-8sonar.login=adminsonar.password=admin
6. Start sonarqube
Cd / usr/local/sonar/sonarqube-5.1.1/bin/linux-x86-64/./sonar.sh start
7. Install the plug-in
Open sonarqube through http://IP:9000 and log in. You can see various plug-ins under settings-- > system-- > update center. You can install them directly. Chinese plug-ins and php plug-ins are all installed in this way.
8. Use sonar-runner to analyze php source code
Create a sonar-project.properties configuration file in the root directory of the project source code
Sonar.projectKey=apps # projectKey must be unique. You can specify sonar.projectName=apps # specify the name of project, sonar.projectVersion=1.0 # project version number, and specify sonar.sources=. at will. # Source code directory,. Represents the current directory
Change to the directory where the project is located and perform the analysis:
/ usr/local/sonar/sonar-runner-2.4/bin/sonar-runner