티스토리 뷰

Developer

[php-fpm] php fpm installation guide

rocksea 2014. 1. 16. 01:59

php fpm installation guide

오랜만에 PHP를 다룰 일이 생겨 포스팅을 하게 되었다.

PHP-FPM는 PHP FastCGI Process Manager의 약자이며 PHP를 기존의 Process생성 & 종료 형태의 

동작이 아닌 데몬서버 형태의 FastCGI 모드로 동작하도록 해준다.

PHP5.4 RC부터 기본 패키징 되었다.


설치 환경

OS :  CentOS release 6.5

PHP : php-5.5.8


download url : http://kr1.php.net/get/php-5.5.8.tar.gz/from/this/mirror


Step 1. 소스 설치

필요에 따라 Library를 추가 하거나 삭제하여 아래와 같이 설치한다.

$ sudo wget http://www.php.net/get/php-5.4.13.tar.gz/from/kr1.php.net/mirror

$ tar xvfz php-5.4.13.tar.gz

CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" \

./configure \

--prefix=/usr/local/php-5.5.8 \

--with-config-file-path=/usr/local/php-5.5.8/etc \

--with-config-file-scan-dir=/usr/local/php-5.5.8/etc/conf.d \

--disable-debug \

--enable-fpm \

--enable-bcmath \

--enable-exif \

--enable-ftp \

--enable-gd-native-ttf \

--enable-inline-optimization \

--enable-intl \

--enable-mbregex \

--enable-mbstring \

--enable-mod-charset \

--enable-sigchild \

--enable-soap \

--enable-sockets \

--enable-sysvsem=yes \

--enable-sysvshm=yes \

--enable-xml \

--enable-zip \

--with-bz2 \

--with-iconv \

--with-curl \

--with-zlib \

--with-gd \

--with-gettext \

--with-ldap=/usr/lib64 \

--with-mcrypt \

--with-mhash \

--with-mysql \

--with-mysqli \

--with-openssl \

--with-xmlrpc \

--with-freetype-dir=/usr/include/freetype2 \

--with-jpeg-dir=/usr/lib64 \

--with-libxml-dir=/usr/lib64 \

--with-png-dir=/usr/lib64 \

--with-zlib-dir=/usr/lib64 \

--with-fpm-user=nobody \

--with-fpm-group=nobody


Compile

$ sudo make


# MODIFIED 2014.03.19 :  error: mcrypt.h not found. Please reinstall libmcrypt 발생

$ tar -xvzf libmcrypt-2.5.0.tar.gz
$ cd libmcrypt-2.5.0
$ ./configure
$ make
$ sudo  make install
$ vi /etc/ld.so.conf
 /usr/local/lib
$ sudo ldconfig

위 방법으로 해결 완료.



※ libiconv 이놈때문에 문제가 있었는데 그건 아래를 참고한다. ( 무슨이유인지 모르겠으나 EXTRA_LIBS에 iconv가 빠져있어서 발생한 문제 )

$ vim Makefile

EXTRA_LIBS = -lcrypt -lz -lcrypt -lrt -lmcrypt -lltdl -lldap -llber -lstdc++ -lpng -lz -ljpeg -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -lssl -lcrypto -lfreetype -licui18n -licuuc -licudata -lm -licuio -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lssl -lcrypto -lcrypt -liconv


$ sudo make install



Step 2. php-cgi 실행

아래의 실행 스크립트를 사용하여 php-cgi 를 실행한다.

php_start.sh

# /bin/sh

## ABSOLUTE path to the PHP binary

PHPFCGI="/usr/local/php/bin/php-cgi"


## tcp-port to bind on

FCGIPORT="9000"


## IP to bind on

FCGIADDR="127.0.0.1"


## number of PHP children to spawn

PHP_FCGI_CHILDREN=5


## number of request before php-process will be restarted

PHP_FCGI_MAX_REQUESTS=1000


## if this script is run as root switch to the following user

USERID="rocksea"


## php config file

PHP_CONFIG_FILE="/etc/php.ini"



if test x$PHP_FCGI_CHILDREN = x; then

  PHP_FCGI_CHILDREN=5

fi


ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN"

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS"

##ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS"


if test x$UID = x0; then

  EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT -c $PHP_CONFIG_FILE\" $USERID"

else

  EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT -c $PHP_CONFIG_FILE"

fi


echo $EX


# copy the allowed environment variables

E=


for i in $ALLOWED_ENV; do

  E="$E $i=$(eval echo \$${i})"

done


# clean environment and set up a new one

/usr/bin/nohup env - $E sh -c "$EX" > /tmp/test.log > /dev/null 2>&1 &


실행 및 확인

$ sudo ./php_start.sh

$ netstat -ntpl | grep 9000

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      31623/php-cgi


nginx 연동

    location ~ \.php($|/) {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        fastcgi_param  DOCUMENT_ROOT    $document_root;

        include        fastcgi_params;

        # 2014.01.16 by rocksea

        #fastcgi_buffer_size   1k;                             

        #fastcgi_buffers       128 1k;  # up to 1k + 128 * 1k

        fastcgi_max_temp_file_size 0;

        gzip off;

    }


위와 같이 설정이 끝나면 php화면을 드디어 볼 수 있을 것이다.



.by rocksea

댓글