1. centos6.2 최소 설치 (http://ftp.daum.net/centos/6.2/isos/i386/)

2. 네트워크 설정

vi /etc/sysconfig/network-scripts/ifcfg-eth0 의 ONBOOT 를 yes 로 수정

3. 필요하다면 selinux 설정 수정 : vi /etc/selinux/config

4. nginx 의 yum repository 등록

# cat > /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/6/$basearch/

gpgcheck=0

enabled=1

^D

#

5. CentOS 6/5.7 and Red Hat (RHEL) 6.1/6/5.7 Remi repository

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

# vi /etc/yum.repos.d/remi.repo # Edit “enabled=1”

# yum update

6. MySQL 설치

# yum install mysql mysql-server

# /usr/bin/mysql_secure_installation

….

Set root password? [Y/n] Y

New password:

Remove anonymous users? [Y/n] Y

… Success!

Disallow root login remotely? [Y/n] Y

… Success!

….

Remove test database and access to it? [Y/n] Y

– Dropping test database…

Reload privilege tables now? [Y/n] Y

… Success!


# mysqladmin -u root password [password]

7. nginx + php-fpm 설치

# yum install nginx php php-fpm php-common php-pear php-pdo php-mysql php-pgsql php-pecl-memcache php-gd php-mbstring php-mcrypt php-xml

* 의존성 때문에 httpd 가 설치되니, chkconfig에서 조정 할 필요가 있음

8. 방화벽firewall 설정

# vi /etc/sysconfig/iptables

## -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT 추가

9. nginx 확인

# ls -l /usr/share/nginx/html

total 8

-rw-r–r– 1 root root 383 Dec 16 00:26 50x.html

-rw-r–r– 1 root root 151 Dec 16 00:26 index.html

* 웹브라우저로 확인


10. php-fpm 세팅

# vi /etc/nginx/conf.d/default.conf

## 1) pass the PHP scripts to FastCGI server 항목 주석 해제

## 2) fastcgi_param 수정


location ~ .php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;

include fastcgi_params;

}


# service nginx configtest

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

# service nginx restart

Stopping nginx: [ OK ]

Starting nginx: [ OK ]

# cat > /usr/share/nginx/html/test.php

<?php phpinfo(); ?>

^D

#

* 웹브라우저로 확인


Reference

* 우분투 10.04 LTS, nginx+php-fastcgi+mysql 설치하기 (http://folderfile.net/xe/2028)

* Nginx proxy to Apache (http://groups.drupal.org/node/50168)

* LEMP( Linux + Nginx + Mysql + php) (http://www.if-not-true-then-false.com/2011/lemp-on-fedora-centos-red-hat-rhel-linux-nginx-mysql-php-fpm/)

출처: <http://noizze.net/post/374>

기본 등록 되어 있는 해외 yum server를 사용해서 yum update라도 하는 날이면,

근 한시간 가량을 업데이트만 하고 있을 것이다.

 

daum에서 제공하는 yum 서버로 변경한다.

repo파일수정

 vi /etc/yum.repos.d/CentOS-Base.repo

 

vi에서 다음과 같이 명령어를 쳐서 수정 해준다.

아래는 :%s를 이용해 치환하는 것이다.

mirror.centos.org가 아니라면 현재 적용 되어 있는 주소로 변경 하면 된다.

vi 환경이라면 편집모드 사용하지 않고 복사 => 붙여넣기 해도 적용 가능하다.

  1. :%s/mirrorlist=/#mirrorlist=/g
  2. :%s/#baseurl=/baseurl=/g
  3. :%s/mirror.centos.org/ftp.daum.net/g

1. Source Download
• http://nginx.org/download/
설치전 라이브러리 install
• # yum -y install gcc pcre-devel bzip2-devel openssl-dev libxml2-devel gdbm-devel libjpeg-devel libpng-devel freetype-devel apr ncurses-devel

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.0.11.tar.gz
# tar xvfzp nginx-1.0.11.tar.gz
# cd /usr/local/src/nginx-1.0.11
# ./configure –prefix=/usr/local/nginx –with-http_ssl_module
# make
# make install

• init.d 데몬 작성
• # vi /etc/rc.d/init.d/nginx

#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: – 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0
nginx=”/usr/local/nginx/sbin/nginx”
prog=$(basename $nginx)
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -
options=$nginx -V 2>&1 | grep 'configure arguments:'
for opt in $options; do
if [ echo $opt | grep '.*-temp-path' ]; then
value=echo $opt | cut -d "=" -f 2
if [ ! -d “$value” ]; then
# echo “creating” $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $”Starting $prog: ”
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $”Stopping $prog: ”
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case “$1″ in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $”Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}”
exit 2
esac

스크립트 실행 권한 추가
• # chmod 755 /etc/rc.d/init.d/nginx

chkconfig 통한 시작 프로그램 추가 등록
# chkconfig –add level 35 nginx
# chkconfig –list | grep nginx
nginx 0:off 1:off 2:off 3:on 4:off 5:on 6:off

설정 파일 수정
# vi /usr/local/nginx/conf/nginx.conf
user nginx nginx;
error_log /var/log/nginx/error.log; # 에러로그 위치
events {
worker_connections 1024; # 커넥션 임계치
}
http {
include mime.types;
default_type application/octet-stream;

log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
server {
listen 80;
server_name localhost; # 도메인 이름
location / {
root /var/www/html # 홈디렉토리
index index.html index.htm; # index 형식 지정
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

# /etc/rc.d/init.d/nginx start
• # ps -aux | grep nginx