install nginx with php

case ubuntu 12.04-LTS, precise(on aws) :

referance : http://wiki.nginx.org/Install
case : ubuntu 12.04-LTS, precise(on aws)

sudo vi /etc/apt/source.list
deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx

sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update 
apt-get install nginx
# W: GPG error: http://nginx.org precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXX

만일 apt-get update 시에 다음과 같은 오류가 날시에는 다음과 같이 한다.

gpg --keyserver keys.gnupg.net --recv-key XXXXXX && gpg -a --export XXXXXX | apt-key add -

with php-fastcgi(ubuntu 12.04) :

referance : http://davidwinter.me/articles/2009/06/13/php-and-nginx-the-easy-way/

sudo apt-get install php5 php5-cgi php5-cli
sudo vi /etc/init.d/php-fastcgi

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL
sudo chown 755 /etc/init.d/php-fastcgi

with php-fpm(ubuntu 12.04) :

sudo apt-get install php5 php5-fpm php5-cli
# use socket
sudo vi /etc/php5/fpm/pool.d/www.conf

;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

sudo vi /etc/nginx/sites-available/default

	location ~ \.php$ {
		# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
		# With php5-cgi alone:
		#fastcgi_pass 127.0.0.1:9000;
		# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		
		fastcgi_index  index.php;
		fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
		fastcgi_param  PATH_INFO $fastcgi_path_info;
		fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_path_info;
		fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include        fastcgi_params;
	}

case amazon linux ami(on aws)

sudo apt-get install nginx

case centos

sudo vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

sudo yum install nginx

이방법이 싫다면 직접 컴파일 한다.

yum install gcc pcre-devel bzip2-devel openssl-devel
wget http://nginx.org/download/nginx-1.2.6.tar.gz
tar xvfz nginx-1.2.6.tar.gz
cd nginx-1.2.6
./configure \
--sbin-path=/usr/sbin \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/subsys/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-mail \
--with-mail_ssl_module \
--with-cc-opt="-I /usr/include/pcre"

make;make install

인스톨한 내용은 다음과 같다.

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/sbin"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/tmp/nginx/client/"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

init script는 다음 링크에서 다운 받아 nginx로 저장한다.
http://wiki.nginx.org/RedHatNginxInitScript

cp nginx /etc/init.d/
chmod 755 /etc/init.d/nginx
/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx -s /sbin/nologin -c "Nginx" -M nginx
mkdir /var/tmp/nginx/
# chkconfig --add nginx
# chkconfig nginx on

혹 버젼 1.0.0 에선 해결 일단 문제가 있는데, initscript로 restart가 잘 안된다. worker 프로세스가 죽는 시간이 좀 걸리는데, 그상태에서 start하는게 문제가 되는 듯하다. 근데 nginx는 꼭 restart로 서버를 리스타팅 할 필요가 없다

ps aux|egrep (PID|nginx) # 여기서 master [pid]를 알아낸후
kill -HUP [pid]
이렇게 하면 무정지로 서버 리스타팅이 가능하다.

yum install spawn-fcgi

vi /etc/init.d/php-fastcgi

#!/bin/sh
#
# php-cgi - php-fastcgi swaping via  spawn-fcgi
#
# chkconfig:   - 85 15
# description:  Run php-cgi as app server
# processname: php-cgi
# config:      /etc/sysconfig/phpfastcgi (defaults RH style)
# pidfile:     /var/run/php_cgi.pid
# Note: See how to use this script : 
# http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
spawnfcgi="/usr/bin/spawn-fcgi"
php_cgi="/usr/bin/php-cgi"
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nginx
server_group=nginx
server_childs=5
pidfile="/var/run/php_cgi.pid"
 
# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi
 
start() {
    [ -x $php_cgi ] || exit 1
    [ -x $spawnfcgi ] || exit 2
    echo -n $"Starting $prog: "
    daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
    retval=$?
    echo
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} $prog -QUIT
    retval=$?
    echo 
    [ -f ${pidfile} ] && /bin/rm -f ${pidfile}
    return $retval
}
 
restart(){
	stop
	sleep 2
	start
}
 
rh_status(){
	status -p ${pidfile} $prog
}
 
case "$1" in
    start)
        start;;
    stop)
        stop;;
    restart)
        restart;;
    status)
        rh_status;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 3
esac

case : mac osx + mac port(2.0.3)

sudo port install nginx
cd /opt/local/etc/nginx/
sudo cp fastcgi.conf.default fastcgi.conf
sudo cp fastcgi_params.default fastcgi_params
sudo cp mime.types.default mime.types
sudo cp nginx.conf.default nginx.conf

sudo port load nginx
sudo port install php54-fpm
cd /opt/loca/etc/nginx/
sudo cp php-fpm.conf.default php-fpm.conf

sudo port load php54-fpm

글쓴이

yupmin

Inside Deep Throat.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.