<NPM : Nginx + PHP + MySQL 설치하기>

1) Nginx 설치하기 : http://tb.chan.je/390

2) MySQL 설치하기 : http://tb.chan.je/445

3) PHP, PHP-FPM 설치하기 : http://tb.chan.je/324


PHP 배포판으로 설치하기

  1. apt-get install libjpeg-dev libpng-dev libmcrypt-dev
  2. ./configure --enable-zend-multibyte --with-zlib --with-xmlrpc --with-gd --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-mbstring --enable-fpm --with-fpm-user="nginx" --with-freetype-dir --with-fpm-group=="nginx" --without-SQLite --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mcrypt --with-openssl --with-openssl-dir=/usr/bin/openssl --enable-zip --with-gmp

    5.5.x 이후 MySQL deprecated 되어서 아래 옵션은 제거했음.
     --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql

    (mysql client만 설치시 : apt-get install libmysqlclient-dev 설치 후 아래 conf 이용)
    ./configure --enable-zend-multibyte --with-zlib --with-xmlrpc --with-gd --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-mbstring --enable-fpm --with-fpm-user="nginx" --with-freetype-dir --with-fpm-group=="nginx" --without-SQLite --with-mcrypt --with-openssl --with-openssl-dir=/usr/bin/openssl --enable-zip --enable-mysql=/usr --with-mysql --with-mysqli --with-pdo-mysql --with-gmp

    (CentOS)
    ./configure --with-zlib --with-xmlrpc --with-gd --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-mbstring --enable-fpm --with-fpm-user="nginx" --with-freetype-dir --with-fpm-group=="nginx" --with-mysqli=/usr/bin/mysql_config --with-mcrypt --with-openssl --with-openssl-dir=/usr/bin/openssl --enable-zip --with-libdir=lib64 --enable-gmp

  3. The errors which I encountered during configure:
    001. configure: error: xml2-config not found. Please check your libxml2 installation.
    soln. apt-get install libxml2-dev

    002. configure: error: Please reinstall the libcurl distribution -
    easy.h should be in /include/curl/
    soln. apt-get install libcurl4-gnutls-dev

    003. configure: error: libjpeg.(a|so) not found.
    soln. ln -s /usr/lib/libjpeg.so.62.0.0 /usr/lib/libjpeg.so

    004. configure: error: libpng.(a|so) not found.
    soln. ln -s /usr/lib/compiz/libpng.so /usr/lib/libpng.so

    005. configure: error: png.h not found.
    soln. apt-get install libpng12-dev

    006. configure: error: freetype.h not found.
    soln. apt-get install libfreetype6-dev

    007. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    soln. apt-get install libmcrypt-dev
    ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

    008. configure: error: Please reinstall libmhash - I cannot find mhash.h
    soln. apt-get install libmhash-dev

    The errors which I encountered during make:
    009. make: *** [ext/gd/libgd/gd_jpeg.lo] Error 1
    soln. apt-get install libjpeg-dev

    010. configure: error: Please reinstall the iconv library.
    soln. Download iconv from http://www.gnu.org/software/libiconv/ and compile it

    011. 
    configure: error: Cannot find OpenSSL's <evp.h>
    openssl을 새로 깔자. # ./config --prefix=/usr/local --openssldir=/usr/local/openssl # make # make test # make install
    이후 이 옵션으로 다시 configure
    ./configure --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-zlib --with-xmlrpc --with-gd --with-curl --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-mbstring --enable-fpm --with-fpm-user="nginx" --with-freetype-dir --with-fpm-group=="nginx" --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mcrypt --with-openssl --with-openssl-dir=/usr/local --enable-zip

  4. make && make install , /etc/ld.so.conf 에 /usr/local/lib 추가 후 sudo ldconfig
  5. apt-get install autoconf
    cd ~/php-5.6.1/sapi/cli/
    pecl install memcache
  6. /usr/local/etc/php-fpm.conf.default 를 php-fpm.conf 로 수정
    1. php-fpm.conf 에 group = =nginx 되어 있을 수 있는데, nginx로 수정 (= 제거)
  7. php --ini 로 ini 경로 확인가능.
    1. <php source dir>/php.ini-development
    2. extension=memcache.so 추가.
    3. date.timezone = Asia/Seoul
    4. short_open_tag = On
    5. error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
    6. error_log = /var/log/php_errors.log
    7. upload_max_filesize = 20M
    8. sendmail_path = /usr/sbin/sendmail -t -i
  8. PHP-FPM init.d 스크립트
    1. PHP 소스 디렉토리의 sapi/fpm/init.d.php-fpm.in 파일을 /etc/init.d/php-fpm 으로 저장합니다. 
    2. php-fpm 스크립트를 열어 상단 경로를 수정해주세요 
      php_fpm_BIN=/usr/local/sbin/php-fpm
      php_fpm_CONF=/usr/local/etc/php-fpm.conf
      php_fpm_PID=/usr/local/var/run/php-fpm.pid
  9. Session handler memcached로 설정.
    1. apt-get install memcached 로 설치한 다음 /etc/memcached.conf 에서 포트 설정하고,
    2. /usr/local/lib/php.ini에 다음과 같이 변경

      session.save_handler = memcached
      session.save_path = "127.0.0.1:11211"
      session.gc_maxlifetime = 200000
      session.cookie_lifetime = 2000000
      https://www.digitalocean.com/community/tutorials/how-to-store-php-sessions-in-memcached-on-a-centos-vps
      http://drupal.stackexchange.com/questions/125259/why-is-session-cookie-lifetime-set-to-23-days

Nginx PHP-FPM 설정하기

location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
  try_files $uri =404;
}

php-fpm에 간단한 튜닝 작업이 필요하다.
/usr/local/etc/php-fpm.conf

> suhosin http://suhosin.org/stories/install.html

Posted by ejnahc


티스토리 툴바