PHP 專用的 Reporting Service (PHP-Reports安裝教學)
Microsoft(以下稱MS)有個好用的報表系統叫做Reporting Service,但是在php的環境下卻鮮少聽到這類工具!
不可否認地MS Reporting Service的確好用且功能強大!只可惜,Reporting Service可是需要安裝MS SQL Server才能運作,嚴格說來它只能算是SQL Server的附屬功能!
廢話不多說,這次就是要來介紹在php環境之下免費又好用的PHP-Reports。
PHP-Reports 官方網站
CentOS 7, Apache 2.4, MySQL 5.7, PHP 7.0 (PHP 5.6實測OK)
git, curl, php-pdo, php-pecl-mongodb
下載php-reports系統檔
透過git直接下載PHP-Reports系統,系統會被放在『php-reports』的資料夾中。
1 |
[andy@www ~]$ git clone git://github.com/jdorn/php-reports.git |
1 2 3 4 5 6 |
[andy@www ~]$ ls php-reports [andy@www ~]$ cd php-reports/ [andy@www php-reports]$ ls classes composer.lock index.php LICENSE README.md sample_reports composer.json config lib public sample_dashboards templates |
將php-reports移動至apache的網站主目錄下
1 |
[andy@www ~]$ mv php-reports /var/www/ |
安裝Composer
PHP-Reports系統會需要使用Composer
1 2 3 4 5 6 7 |
[andy@www www]$ curl -sS https://getcomposer.org/installer | php Cannot load Zend OPcache - it was already loaded All settings correct for using Composer Downloading... Composer (version 1.5.1) successfully installed to: /var/www/composer.phar Use it: php composer.phar |
1 |
[andy@www ~]$ mv composer.phar /usr/local/bin/composer |
安裝PHP-Reports
切換目錄至php-reports之下,執行composer開始安裝!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[andy@www www]$ cd php-reports [andy@www php-reports]$ composer install Cannot load Zend OPcache - it was already loaded Do not run Composer as root/super user! See https://getcomposer.org/root for details Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Package operations: 11 installs, 0 updates, 0 removals - Installing adodb/adodb-php (dev-master 7d94196): Cloning 7d941967aa - Installing mongodb/mongodb (dev-master 55e871b): Cloning 55e871bfff - Installing alcaeus/mongo-php-adapter (dev-master 7287034): Cloning 72870346ae - Installing google/apiclient (1.0.6-beta): Downloading (100%) - Installing jdorn/file-system-cache (dev-master 08f33ff): Cloning 08f33ff840 - Installing jdorn/sql-formatter (dev-master 7ef9b85): Cloning 7ef9b85961 - Installing lespoilus/spyc (dev-master 5a5bacd): Cloning 5a5bacdef1 The authenticity of host 'github.com (192.30.253.112)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+test+2017-08-17+0803 to retrieve a token. It will be stored in "/root/.config/composer/auth.json" for future use by Composer. Token (hidden): Token stored successfully. - Installing mikecao/flight (dev-master 7f402f8): Cloning 7f402f805a - Installing phpoffice/phpexcel (dev-develop 7fa1609): Cloning 7fa160905b - Installing swiftmailer/swiftmailer (5.x-dev fffbc0e): Cloning fffbc0e2a7 - Installing twig/twig (1.x-dev 3d0afc0): Cloning 3d0afc0389 Generating autoload files [andy@www php-reports]$ |
17行:請輸入yes,讓系統與GitHub連線!
18~21行:用瀏覽器開啟『系統提示的網址』,並且用GitHub帳號登入,取得授權Token!
你可以按照下列圖片進行:
用瀏覽器開啟『系統提示的網址』,並且登入GitHub!
按下『Generate token』產生token的按鈕
複製token,貼回21行的地方,然後按下Enter!
以上,就算是安裝完畢!
編輯PHP-Reports的系統設定檔
在PHP-Reports系統根目錄的子目錄『config』下有設定檔的範例,
複製範例檔,並且更名為『config.php』
1 2 |
[andy@www php-reports]$ cp config/config.php.sample config/config.php [andy@www php-reports]$ vim config/config.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
//這是設定所有報表檔的根目錄『資料夾』 //想更改名稱的話,請連PHP-Reports系統根目錄下的資料夾『sample_reports』一起更改! 'reportDir' => 'sample_reports', //這是設定所有儀表板的根目錄『資料夾』 //想更改名稱的話,請連PHP-Reports系統根目錄下的資料夾『sample_dashboards』一起更改! 'dashboardDir' => 'sample_dashboards', //設定資料庫連線 //如果是與MySQL連線的話,就要修改『pdo』的設定值 'environments' => array( 'main'=>array( // Supports AdoDB connections 'ado'=>array( 'uri'=>'mysql://username:password@localhost/database' ), // Supports and PDO database 'pdo'=>array( 'dsn'=>'mysql:host=localhost;dbname=test', 'user'=>'readonly', 'pass'=>'password', ), // Supports MongoDB 'mongo'=>array( 'host'=>'localhost', 'port'=>'27017' ), ), ), |
設定Apache
盡可能以VirtualHost來設定這個站台比較不容易出問題
(我曾經用Alias設定PHP-Reports根目錄。每次進入報表清單就會出現404錯誤…)
1 |
[andy@www ~]$ sudo vim /etc/httpd/conf/httpd.conf |
設定如下,其中『AllowOverride All』是一定要加入的設定值,若不加入的話會造成系統無法正常運作!
1 2 3 4 5 6 7 8 9 10 |
<VirtualHost *:80> ServerName localhost DocumentRoot "/var/www/php-reports" <Directory '/var/www/php-reports'> Options FollowSymLinks AllowOverride All Allow from all Require all granted </Directory> </VirtualHost> |
重新啟動Apache,大功告成!
1 |
[andy@www ~]$ sudo systemctl restart httpd |