작은숲:위키노트/PHP intl 모듈

큰숲백과, 나무를 보지 말고 큰 숲을 보라.

영문, 숫자, 하이픈이 아닌 다른 문자로 이루어진 도메인의 경우, 브라우저, 웹 서버들이 자체적으로 ASCII 문자로 변환된 퓨니코드로 변환하여 이용한다. PHP에서 이런 한글 도메인-퓨니코드 간 변환을 하기 위해서는 intl 확장 기능이 필요하다.

ICU 패키지 설치

우선 intl 모듈을 사용하기 위해 필요한 ICU 패키지를 설치한다.

# yum install icu libicu libicu-devel
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
...
Installed:
  icu.x86_64 0:4.2.1-12.el6    libicu.x86_64 0:4.2.1-12.el6    libicu-devel.x86_64 0:4.2.1-12.el6
Complete!

intl 모듈 다운로드 및 컴파일

http://pecl.php.net/package/intl에서 확인 후 적절한 intl 확장기능 다운로드. 2016년 1월 27일 현재, 최신 안정 버전은 3.0.0.

# cd /usr/local/src
# wget http://pecl.php.net/get/intl-3.0.0.tgz
--2016-01-27 14:51:04--  http://pecl.php.net/get/intl-3.0.0.tgz
Resolving pecl.php.net... 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 248200 (242K) [application/octet-stream]
Saving to: `intl-3.0.0.tgz'
100%[======================================================>] 248,200      151K/s   in 1.6s
2016-01-27 14:51:16 (151 KB/s) - `intl-3.0.0.tgz' saved [248200/248200]
# tar zxvf intl-3.0.0.tgz
...
intl-3.0.0/php_compatshims.h
intl-3.0.0/php_intl.c
intl-3.0.0/php_intl.h
# cd intl-3.0.0

Yum으로 PHP를 설치한 경우가 아니라면 서버에 설치된 phpize의 경로를 찾아 실행한다. PHP가 설치된 경로가 환경변수에 PATH로 설정되어 있다면 그냥 phpize를 실행하면 된다.

# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626

마찬가지로 ./configure를 실행할 때도 PHP 설치 경로가 PATH에 설정되지 않았다면 --with-php-config 옵션을 설정해야 한다.

# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
...
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: creating ./config.status
config.status: creating config.h
# make
...
cp ./.libs/intl.so /usr/local/src/intl-3.0.0/modules/intl.so
cp ./.libs/intl.lai /usr/local/src/intl-3.0.0/modules/intl.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/intl-3.0.0/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/intl-3.0.0/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'.
# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20090626/

설치된 모듈의 위치를 확인한 후 PHP 설정 파일 php.ini에 아래 내용을 추가한다.

extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626/intl.so"

이제 아파치를 다시 시작한 후 phpinfo에서 모듈이 제대로 올라왔는지 확인한다.

# /usr/local/apache/bin/apachectl restart
# /usr/local/php/bin/php -m | grep intl
intl

참고 자료