PHPとFreeTDS
サーバーにPHPのmssqlモジュールをインストールしようと、まず、FreeTDSをインストールしようとしたわけなんですが、まずはFreeTDSのソースにspecファイルがあったのでRPM作成。
PHPのマニュアル*1に
また、FreeTDS は --enable-msdblib を指定してコンパイルする必要があります。
ということなのでspecファイルのconfigureの箇所に該当の記載を行なったのちにrpmbuildしてみる。
(基本なことなんだけど、知らんうちにrootでrpmbuildしてたらコケてたので一般ユーザーでrpmbuildすること!)
次にPHPのmssqlエクステンションをインストールするわけなんですが
root# cd /usr/local/src/php/php-5.2.x/ext/mssql root# phpize root# ./configure --with-mssql=/usr
とかやると
checking for gawk... gawk
checking for MSSQL support via FreeTDS... yes, shared
configure: error: Directory /usr is not a FreeTDS installation directory
とかわけのわからないことを言い出す始末。
で、configureをviで開いて何を基準にis not a FreeTDS installation directoryとかホザいているのか見てみたら。。。
if test -f $PHP_MSSQL/include/tds.h; then FREETDS_INSTALLATION_DIR=$PHP_MSSQL FREETDS_INCLUDE_DIR=$PHP_MSSQL/include elif test -f $PHP_MSSQL/include/freetds/tds.h; then FREETDS_INSTALLATION_DIR=$PHP_MSSQL FREETDS_INCLUDE_DIR=$PHP_MSSQL/include/freetds else { { echo "$as_me:$LINENO: error: Directory $PHP_MSSQL is not a FreeTDS installation directory" >&5 echo "$as_me: error: Directory $PHP_MSSQL is not a FreeTDS installation directory" >&2;}
ということで、$PHP_MSSQL(今回の場合/usr)/include/freetds/の中にtds.hがあればということなんだけど、そもそも/usr/includeの中に「freetds」というディレクトリは存在していない。。。
また、/usr/includeの中に「tds.h」自体が無いというわけのわからない状態。
で、RPMを作った時のFreeTDSのソースコードがまだ残っていたので見てみたらincludeの中にtds.hが!!
とりあえずそのincludeディレクトリを/usr/include/freetdsという名前でコピー。
すると。。。
checking for MSSQL support via FreeTDS... yes, shared checking for dnet_addr in -ldnet_stub... no checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes (以下略)
通りやがった。。。
あとは普通にmake/make installして、php.iniにextension=mssql.soを追加してあげれば終わり。めでたしめでたし。。。
と、わけわからんし、specファイル直すパッチか何か書こうかと思って、まずはPHPのマニュアル*2をよく下まで見てみると。。。
Matt Mason
09-Jul-2008 05:42
Had a problem compiling PHP with --with-mssql=/usr/local/freetds , kept saying that it wasn't a valid FreeTDS directory...Check that when you install FreeTDS from source, that it actually puts the required files from the source directory to where the installation directory was specified, so to fix:
cp [tds source]/include/tds.h /usr/local/freetds/include
cp [tds source]src/tds/.libs/libtds.a /usr/local/freetds/lib{in this example I installed FreeTDS to /usr/local/freetds}
This may make it a little easier for some else too.