freetds 설치 및 PHP 연동하는 방법은 무엇인가요?
💡 요약 정리
- 이 가이드는 CentOS 5.x에서 freetds-0.91을 설치하고 PHP 5.2.17과 연동하는 방법을 설명합니다.
- freetds는 SQL Server 접속을 위해 사용하는 라이브러리입니다.
- 설치 후 PHP에서 mssql 모듈을 활성화하기 위해 phpize를 실행하고, php.ini에 설정을 추가해야 합니다.
- 설치 및 설정 과정은 명령어 중심으로 구성되어 있으 므로, 모든 이미지를 포함해 단계를 따라야 합니다.
- 설치 위치는 '/usr/local/freetds'입니다.
1. 설치 환경
- CentOS 5.x (64bit)
- PHP 5.2.17
- freetds 0.91
설치 위치:
/usr/local/freetds
2. freetds 설치
- freetds 스테이블 버전을 다운로드한 후 설치합니다.
[root@cafe24 src]# wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
[root@cafe24 src]# tar zxvf freetds-stable.tgz
[root@cafe24 src]# cd freetds-0.91
[root@cafe24 freetds-0.91]# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --disable-odbc --disable-debug --enable-dbmfix --enable-msdblib
.
.
.
config.status: creating win32/version.rc
config.status: creating win32/freetds.nsh
config.status: creating vms/Makefile
config.status: creating include/config.h
config.status: include/config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
[root@cafe24 freetds-0.91]# make && make install
.
.
.
make[2]: Entering directory `/root/src/freetds-0.91'
make[2]: Nothing to be done for `install-exec-am'.
/bin/sh ./mkinstalldirs /usr/local/freetds/etc
if test ! -f /usr/local/freetds/etc/freetds.conf; then
/usr/bin/install -c -m 644 ./freetds.conf /usr/local/freetds/etc/freetds.conf;
fi
if test ! -f /usr/local/freetds/etc/locales.conf; then
/usr/bin/install -c -m 644 ./locales.conf /usr/local/freetds/etc/locales.conf;
fi
make[2]: Leaving directory `/root/src/freetds-0.91'
make[1]: Leaving directory `/root/src/freetds-0.91'
[root@cafe24 freetds-0.91]#
3. phpize를 이용하여 PHP 모듈 생성
- PHP 설치 원본 소스 디렉터리로 이동한 다음,
phpize를 실행하여 mssql 모듈을 생성합니다.
[root@cafe24 freetds-0.91]# cd /root/src/php-5.2.17/ext/mssql/
[root@cafe24 mssql]# /home/APM/php/bin/phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
[root@cafe24 mssql]# ./configure --with-mssql=/usr/local/freetds/ --with-php-config=/home/APM/php/bin/php-config
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
[root@cafe24 mssql]# make
----------------------------------------------------------------------
Libraries have been installed in:
/root/src/php-5.2.17/ext/mssql/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
[root@cafe24 mssql]# make install
Installing shared extensions: /home/APM/php/lib/php/extensions/no-debug-non-zts-20060613/
[root@cafe24 mssql]#
4. php.ini 파일에 모듈 등록
php.ini파일의 가장 하단에 다음 내용을 추가합니다.
[root@cafe24 mssql]# vi /home/APM/apache/conf/php.ini
----------------------------------------------------------------------------------------------------------------------------------------------------------------
[freetds]
extension_dir=/home/APM/php/lib/php/extensions/no-debug-non-zts-20060613 <-- 추가합니다.
extension="mssql.so"
----------------------------------------------------------------------------------------------------------------------------------------------------------------
[root@cafe24 mssql]# php -m
[PHP Modules]
bcmath
calendar
ctype
curl
date
dba
dbase
dom
eAccelerator
exif
filter
ftp
gd
gettext
hash
iconv
imap
json
ldap
libxml
mbstring
mcrypt
mhash
mssql
mysql
pcre
PDO
pdo_sqlite
posix
Reflection
session
SimpleXML
sockets
SPL
SQLite
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
Zend Optimizer
zlib
[Zend Modules]
Zend Optimizer
eAccelerator
[root@cafe24 mssql]#
5. 연동 확인
- 위 단계를 모두 완료한 후
php -m명령을 통해mssql모듈이 활성화되었는지 반드시 확인해야 합니다. - 만약
mssql항목이 출력되지 않는다면 설정 파일 경로, 모듈 경로, 오타 등을 다시 확인해 주세요.
참고 사항
- 본 가이드는 CentOS 5.x와 PHP 5.2.17 기준입니다. 다른 버전에서는 옵션이나 경로가 다를 수 있습니다.
- freetds.conf 설정이나 MS-SQL 서버 정보 등록 등은 별도로 진행해야 합니다.
마무리
이상으로 freetds 설치 및 PHP 연동 과정을 마쳤습니다. 정상적으로 모듈이 로드되었는지 최종적으로 확인하는 것이 중요합니다.