CakePHP on Ubuntu で pChart を使う
最近話題の pChart を使ってみた。
環境は↓
CakePHP に組み込む
ディレクトリ構造が以下のようになるように展開する。
app/vendors/pChart/
- pChart
- Cache
- Fonts
- include.php
include.php の中身は↓
<?php include("pChart/pData.class"); include("pChart/pChart.class"); ?>
使う側
vendor("pChart/include");
本当はコンポーネントにしたい。
Ubuntu に乗っけてみる
Windows + XAMPP だとうまくいったんだけど
Ubuntu にデプロイして早速使ってみたらなんか怒られた。
Fatal error: Call to undefined function ImageAntiAlias() in /var/www/chart/app/vendors/pChart/pChart/pChart.class on line 116
# apt-get install php5-gd
で入る GD モジュールは PHP5 のバンドルパッケージでないため
いくつかの関数が使えないらしい。
参考:Bug #74647 “php5-gd not using bundled GD library” : Bugs : php5 package : Ubuntu
そのため、PHP を --with-gd オプション付きでビルドし直さなければならない。
だったらビルドしてやろうじゃないの
参考:http://cumu.li/2008/5/13/recompiling-php5-with-bundled-support-for-gd-on-ubuntu
$ cd /usr/src $ sudo su # apt-get install build-essential debhelper fakeroot # apt-get source php5 # apt-get install libsnmp-dev # apt-get build-dep php5 # cd php5-5.2.3
# vim debian/rules
--with-gd=shared,/usr --enable-gd-native-ttf \
を以下に置換
--with-gd=shared --enable-gd-native-ttf \
# dpkg-buildpackage -rfakeroot # cd .. # dpkg -i php5-gd_5.2.3-1ubuntu6.3_i386.deb # apache2ctl restart
mod_rewrite が有効になっていなかったので有効に
# a2enmod rewrite # apache2ctl restart
ここまでやって Ubuntu でも pChart からグラフ生成できた。