さくらのVPSにLighttpd+PHPをインストール その2

2011年2月11日

さくらのVPSにLighttpd+PHPをインストール その1の続き。

FastCGIのインストール

Lighttpdは、PHPを外部のCGIとして実行する。それにFastCGIを使用する。
ソースを、http://www.fastcgi.com/dist/からダウンロードする。インストールした時点での最新版は、2.4.0。
サーバ上で以下の手順を実施。

#tar -zxvf fcgi-2.4.0.tar.gz
#cd fcgi-2.4.0
#./configure
#make
#make install

FastCGIはこれで終わり。

PHPのインストール

せっかくなのでPHPも最新版をソースからインストールした。
CentOSでのインストールなのでhttp://redmine.lighttpd.net/wiki/lighttpd/TutorialLighttpdAndPHP#Othersを参照する。
ソースを、http://www.php.net/downloads.phpからダウンロードする。インストールした時点での最新版は、5.3.5。
サーバ上で以下の手順を実施。

#tar -zxvf php-5.3.5.tar.gz
#cd php-5.3.5
#./configure \
  --enable-mbstring \
  --with-pear

ここで、configure: error: xml2-config not found. Please check your libxml2 installation. のエラーが出たので、libxml2,libxml2-develをインストールして再度実行。

#tar -zxvf php-5.3.5.tar.gz
#yum install libxml2
#yum install libxml2-devel
#./configure \
  --enable-mbstring \
  --with-pear
#make
#make install

configureのパラメータが異なっているが、PHP5.3以降では、cgi-phpがデフォルトで作成される。–disable-cgiオプションでFastCGIを有効にする設定となる。
訂正:どうも–disable-cgiがあると、php-cgiが作成されない模様。ちょっと混乱しているので後で調べて書き直す
それ以前のPHPの場合には、http://redmine.lighttpd.net/wiki/lighttpd/TutorialLighttpdAndPHP#Othersの例に沿う。
参考:http://www.php.net/manual/ja/install.unix.lighttpd-14.php

Lighttpdの設定

PHP関連の設定は、http://redmine.lighttpd.net/wiki/lighttpd/TutorialLighttpdAndPHP#Configurationを参照する。

#vi /etc/lighttpd/conf.d/fastcgi.conf
fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/local/bin/php-cgi",
                     "socket" => "/tmp/php.socket"
                 )))

#vi /etc/lighttpd/modules.conf
include "conf.d/fastcgi.conf" ← #でコメントアウトされているので、コメントアウトをはずす。

ここまでの設定で、ひとまずPHPも動作する、はず。

#service lighttpd restart