安裝sonarQube代碼品質管理平台分析PHP代碼

來源:互聯網
上載者:User

標籤:php sonarqube sonar runner

只是說說遇到的坑吧,

第一點:不同的PHP版本,需要安裝不同的sonar,最新的sonar版本,只適用於高版本的php;

第二點,分析php代碼的擴充同樣如此,需要用到對應版本的php程式碼分析擴充;

第三點,在增加php項目,開始分析之後,sonar需要操作資料庫,並分析代碼,可能會大量消耗cpu和讀取資料庫,造成機器負載飆升,同時,分析代碼可能需要很長的時間,在此期間重啟sonar,停止sonar,可能會導致開啟失敗,記憶體溢出報錯,這個要多等一段時間,根據機器效能不等,我的是在半個 小時左右。

下邊貼出安裝的過程

我安裝的是sonarqube-5.2,嘗試最新的6.4版本,發現有錯誤。

第一步安裝

wget -c unzip -n sonarqube-5.2.zip -d /usr/local


第二步配置環境

 vi + /etc/profile

添加

SONAR_HOME=/usr/local/sonarqube-5.2

export SONAR_HOME

儲存退出並使配置生效

source /etc/profile

第三步配置sonar.properties

[[email protected] ~]# vi /usr/local/sonarqube-5.2/conf/sonar.properties

開啟後,找到

sonar.host.url=http://localhost:9999

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.web.host=0.0.0.0

sonar.web.context=

sonar.web.port=9999

sonar.search.port=9998

PS:SonarQube預設監聽9000連接埠。但是我的伺服器的web是nginx,已佔用9000,所以我修改為9999

search連接埠改成9998

第四步啟動服務

cd /usr/local/sonarqube-5.2/bin/linux-x86-64

./sonar.sh start

另外,啟動/停止/重啟命令如下: 
#./sonar.sh start   啟動服務 
#./sonar.sh stop    停止服務 
#./sonar.sh restart 重啟服務

第五步訪問SonarQube Web管理介面。如果能夠看到這個介面證明SonarQube安裝成功啦。

我的是直接存取ip加連接埠號碼  ip:9999

650) this.width=650;" src="https://s4.51cto.com/wyfs02/M01/02/3C/wKiom1mfk1PyfF1UAACLE_10GtI938.png-wh_500x0-wm_3-wmp_4-s_3183935551.png" title="20170825110140.png" alt="wKiom1mfk1PyfF1UAACLE_10GtI938.png-wh_50" />


下邊安裝sonarqube runner

sonar runner是分析項目代碼的工具.

第一步:將下載的http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip解壓後放到/usr/local目錄下。具體步驟如下:

 wget -c http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

unzip -n sonar-runner-dist-2.4.zip -d /usr/local

第二步:配置環境變數

vi + /etc/profile

添加

SONAR_RUNNER_HOME=/usr/local/sonar-runner-2.4/

PATH=.:$SONAR_RUNNER_HOME/bin

export SONAR_RUNNER_HOME

 

#包含sonar和sonar-runner的環境變數設定

export SONAR_HOME=/usr/local/sonarqube-5.2

export SONAR_RUNNER_HOME=/usr/local/sonar-runner-2.4 export

PATH=$PATH:$SONAR_HOME/bin:$SONAR_RUNNER_HOME/bin

儲存並退出

source /etc/profile

第三步:配置sonar-runner.properties

vi /usr/local/sonar-runner-2.4/conf/sonar-runner.properties

找到

sonar.host.url=http://localhost:9999

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.login=admin

sonar.password=admin

將前面的#去掉

PS:剛才我們已經看到SonarQube已經可以訪問了,所以就將sonar.host.url改成了實際的訪問地址。

第四步:運行sonar-runner分析原始碼

Sonar官方已經提供了非常全的代碼範例便於新手入門用。

:https://github.com/SonarSource/sonar-examples/archive/master.zip

下載後使用unzip解壓。進入php執行sonar-runner命令即可。操作命令如下:

wget -c https://github.com/SonarSource/sonar-examples/archive/master.zip

unzip master.zip

 cd sonar-examples-master/projects/languages/php/php-sonar-runner

sonar-runner

如果能夠看到下面的輸出資訊,證明你的SonarQube Runner安裝並配置正確啦。

如果分析自己的項目,可能需要很久


650) this.width=650;" src="https://s1.51cto.com/wyfs02/M00/02/51/wKiom1mfmFnhoLDeAAEQOWtTvpQ073.png-wh_500x0-wm_3-wmp_4-s_892736588.png" title="QQ20170825112341.png" alt="wKiom1mfmFnhoLDeAAEQOWtTvpQ073.png-wh_50" />


參考連結 http://www.cnblogs.com/linky520/p/5594445.html





安裝sonarQube代碼品質管理平台分析PHP代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.