■ php 에서 Mbstring 라이브러리를 연동하는 목적
PHP에서 mbstring(extension for multibyte strings)을 연동하는 목적은 다국어(멀티바이트) 문자열 처리를 개선하는 것입니다.
PHP는 기본적으로 한 바이트 문자열(ASCII)을 처리하기 위해 설계되어 있으며, mbstring 확장을 사용하면 멀티바이트 문자열(UTF-8 등)을 처리할 수 있습니다.
mbstring 라이브러리를 추가하면
1) UTF-8과 같은 멀티바이트 인코딩을 사용하는 다국어 문자열을 제대로 처리할 수 있음
예) 한국어, 중국어, 일본어 등을 포함한 다양한 언어의 텍스트를 PHP에서 사용 가능
2) mbstring을 사용하면 기본 문자열 함수들(`strlen()`, `substr()`, `strpos()` 등)이 멀티바이트 문자열을 사용할 수 있음
3) 멀티바이트 문자열에서도 올바르게 문자열을 자를 수 있도록 사용 가능
4) 멀티바이트 문자열에서도 대소문자 변환이 정확하게 이루어질 수 있도록 지원함
만약 mbstring 활성화를 누락한경우 아래와 같이 라이버러리를 수동 추가하여 활성화 할 수 있습니다.
■ php 소스에 mbstring 라이브러리 추가하기(요약본)
1) php 소스 디렉토리로 이동
#cd /php-5.4.45/ext/mbstring
※ php소스 경로가 기역이 안난다면 find / -name mbstring 로 검색
2) phpize를 실행하여 확장 모듈파일 생성을 위한 준비 시작
#/usr/local/bin/phpize
※ configure 를 위한 파일이 생성됨
3) 추가 컴파일 진행
#./configure --with-php-config=/usr/local/bin/php-config
4) so 파일 생성
#make
※ mbstring.so 파일은 make한경로 아래의 modules경로 밑에 mbstring.so 파일이 생성됨
5) mbstring.so 모듈 복사
#cat php.ini | grep extension_dir
※ extension_dir로 나온 경로가 모듈을 인식하는 경로이다.
#cp /php-5.4.45/ext/mbstring/modules/mbstrings.so /usr/local/php/module/
※ 기본 경로는 /usr/local/php/module/ 이다.
6) php.ini 편집
#vi php.ini
extension=mbstring.so // 라인추가
7) 적용을 위한 apache 재시작: apachectl restart
8) phpinfo 페이지 생성 후 웹에서 확인
php 테스트 페이지 생성: <? phpinfo(); ?>
9) 참고: mb_get_info 사용방법
■ php 소스에 mbstring 라이브러리 추가하기(상세본)
[root@boy /]#cd /php-5.4.45/ext/mbstring
[root@boy mbstring]#/usr/local/bin/phpize
Configuring for:
PHP Api Version: 20181225
Zend Module Api No: 20160613
Zend Extension Api No: 2200901106
[root@boy mbstring]#
[root@boy mbstring]# ./configure --with-php-config=/usr/local/bin/php-config
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking whether gcc and cc understand -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20060613
checking for PHP installed headers prefix... /usr/local/include/php
checking for re2c... no
configure: WARNING: You will need re2c 0.12.0 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable multibyte string support... yes, shared
checking whether to enable multibyte regex support... yes
checking whether to check multibyte regex backtrack... yes
checking for external libmbfl... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for variable length prototypes and stdarg.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking for unistd.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/times.h usability... yes
checking sys/times.h presence... yes
checking for sys/times.h... yes
checking stdarg.h usability... yes
checking stdarg.h presence... yes
checking for stdarg.h... yes
checking for int... yes
checking size of int... 4
checking for short... yes
checking size of short... 2
checking for long... yes
checking size of long... 4
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for working memcmp... yes
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if gcc static flag works... yes
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc supports -c -o file.o... yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
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@boy mbstring]#make
*내용생략*
so
creating mbstring.la
(cd .libs && rm -f mbstring.la && ln -s ../mbstring.la mbstring.la)
/bin/sh /install_source/src/php-5.4.45/ext/mbstring/libtool --mode=install cp ./mbstring.la /install_source/src/php-5.4.45/ext/mbstring/modules
cp ./.libs/mbstring.so /install_source/src/php-5.4.45/ext/mbstring/modules/mbstring.so
cp ./.libs/mbstring.lai /install_source/src/php-5.4.45/ext/mbstring/modules/mbstring.la
PATH="$PATH:/sbin" ldconfig -n /install_source/src/php-5.4.45/ext/mbstring/modules
----------------------------------------------------------------------
Libraries have been installed in:
/install_source/src/php-5.4.45/ext/mbstring/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@boy mbstring]#cp /php-5.4.45/ext/mbstring/modules/mbstrings.so /usr/local/php/module/
[root@boy mbstring]#vi /usr/local/apache2/conf/php.ini
[root@boy mbstring]#/usr/local/apache2/bin/apachectl restart