limesurveyインストール グラフ、PDF日本語表示設定

CentOSインストール
日経Linux2010年6月号の付録DVDからCentOS 5.4をインストール
デフォルトのアプリケーションに加え”今すぐカスタマイズ”を選択してFTPサーバー、Postgresqlサーバー、Webサーバー、開発ツール、開発ライブラリパッケージグループも追加インストール
※Webサーバーパッケージグループのphp関連パッケージは外す。

CentOSインストール後の設定
社内で使うのでファイアウォールSELinuxは無効
yum -y update でパッケージを全てアップデート
※プロキシ経由するのでyum.confに proxy=http://myproxyserver:port を追加

サーバー起動設定
# chkconfig --level 345 httpd on
# chkconfig --level 345 postgresql on
# chkconfig --level 345 vsftpd on

PHPをインストールする前準備
# yum install httpd-devel
# yum install postgresql-devel

PHPをインストール
php-5.2.13.tar.bz2をダウンロード
展開後
#./configure --with-bz2 --with-freetype-dir=/usr --with-png-dir=/usr --with-jpeg-dir=/usr --with-openssl --with-png-dir=/usr --with-gd --with-zlib --prefix=/usr/local/php5 --with-apxs2=/usr/sbin/apxs --enable-mbstring --with-pgsql
# make
# make install

PHP動作確認
httpd.confに設定追加
# vi /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php
DirectoryIndex index.html index.html.var index.php

設定を反映させるため
# /etc/init.d/httpd restart

動作確認用phpファイルを用意
# vi /var/www/html/phpinfo.php


ブラウザでhttp://myserver/phpinfo.php にアクセスし表示確認

Postgresql設定
とりあえず起動してデータベース初期化
# /etc/init.d/postgresql start

localhostの認証をPAMにする
# vi /var/lib/pgsql/data/pg_hba.conf
host all all 127.0.0.1/32 pam

サーバーを再起動
# /etc/init.d/postgresql restart

postgresユーザーのパスワードを設定
# passwd postgres
Changing password for user postgres.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

postgresユーザーでデータベースにアクセスできるか確認
# psql -l -U postgres -h localhost
Password for user postgres:
List of databases
Name | Owner | Encoding

                                                                • -

postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
(3 rows)

●limesurveyをインストール
limesurveyをダウンロード、/var/www/html以下に展開
# unzip limesurvey187plus-build8518-20100323.zip

●limesurveyの初期設定
limesurveyディレクトリ以下のアクセス権設定
# chgrp -R apache /var/www/html/limesurvey
# chmod -R o-r-w-x /var/www/html/limesurvey/
# chmod -R -w /var/www/html/limesurvey/
# chmod -R 770 /var/www/html/limesurvey/tmp
# chmod -R 770 /var/www/html/limesurvey/templates
# chmod -R 770 /var/www/html/limesurvey/upload

config.phpを環境に合わせて変更
# cd limesurvey
# vi config.php
$databasetype = 'postgres';
$databaseuser = 'postgres';
$databasepass = '****';

ブラウザで http://myserver/limesurvey/admin/install/ にアクセス
設定完了後、installディレクトリを削除
# rm -rf /var/www/html/limesurvey/admin/install/

http://myserver/limesurvey/admin/admin.php にアクセスしてログイン

各種設定、適当なアンケートを作成、アンケート実施後、集計結果を表示しグラフ画像やPDFの日本語部分が文字化することを確認

●出力フォーマット”HTML” グラフ内日本語表示文字化け修正
日本語フォントダウンロード
IPAフォントをダウンロードして展開
# unzip IPAfont00302.zip

limesurveyのフォントフォルダにフォントファイルをコピー
# cp IPAfont00302/*.ttf /var/www/html/limesurvey/fonts/

config.phpにフォント設定を追加(IPAゴシック指定)
# vi /var/www/html/limesurvey/config.php
$chartfontfile='ipag.ttf';

キャッシュ画像を削除
# rm -f /var/www/html/limesurvey/tmp/*.png

設定を反映させるためApacheを停止、開始
# /etc/init.d/httpd stop
# /etc/init.d/httpd start
※restartでは反映されない

●出力フォーマット”PDF” 日本語文字化け修正(小塚Proゴシック)
TCPDF設定ファイル定数変更
# vi /var/www/html/limesurvey/admin/classes/tcpdf/config/tcpdf_config.php
define ('PDF_FONT_NAME_MAIN', 'kozgopromedium'); ← "helvetica"から変更
define ('PDF_FONT_NAME_DATA', 'kozgopromedium'); ← ”helvetica”から変更

MyPDFクラスのコンストラクタ内でFontFamilyプロパティ設定
# vi /var/www/html/limesurvey/admin/classes/tcpdf/mypdf.php
class MyPDF extends TCPDF
{
function MyPDF($orientation='P', $unit='mm', $format='A4')
{
parent::__construct($orientation,$unit,$format);
$this->SetAutoPageBreak(true,10);
$this->AliasNbPages();
$this->FontFamily = 'kozgopromedium'; ←追加
}

以上