IT_Server/Web_Server & WAS

[펌][NGINX] CentOS기반 Nginx, PHP-FPM, APC MySql 환경 구성 Quick 가이드

JJun ™ 2013. 5. 24. 13:47


 출처: http://lovedev.tistory.com/664






1. yum 설치를 위한 remi 레파지토리 추가

CentOS 6버전대 64Bit

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm


CentOS 6버전대 32Bit

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm


CentOS 6버전대 공통 추가

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


CentOS 5버전대 64Bit 

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm


CentOS 5버전대 32Bit

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm


CentOS 5버전대 공통 추가

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



2. nginx 레파지토리 추가(nginx.repo 파일 생성)

$] vi /etc/yum.repos.d/nginx.repo 


[nginx]

name=nginx repo

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

gpgcheck=0

enabled=1


3. nginx, php 설치

yum --enablerepo=remi,remi-test install nginx


yum --enablerepo=remi,remi-test install php php-fpm php-common php-gd php-mbstring php-mcrypt php-xml php-pear php-pdo php-mysql php-pecl-apc


4. nginx.conf 설정

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


server {

    listen       80;

    server_name  localhost;


    #charset koi8-r;

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


    location / {

        root   /usr/share/nginx/html;

        index  index.php index.html index.htm;

    }


    #error_page  404              /404.html;


    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }


    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass   http://127.0.0.1;

    #}


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ \.php$ {

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index index.php;

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

        include        fastcgi_params;

    }


    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    location ~ /\.ht {

        deny  all;

    }

}


5. php-fpm.conf 수정 

#]  vi /etc/php-fpm.d/www.conf 

...

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user's group

;  will be used.

; RPM: apache Choosed to be able to access some dir as httpd

user =nginx

; RPM: Keep a group allowed to write in log dir.

group = nginx

...


6. php 로그 생성 권한 추가 

#] chown -R nginx:nginx /var/log/php-fpm



7. 시작서비스 추가

chkconfig --add nginx

chkconfig --levels 235 nginx on

chkconfig --add php-fpm

chkconfig --levels 235 php-fpm on



8. 서비스 시작

service nginx start

service php-fpm start 


9. index.php 생성

echo "<? phpinfo(); ?>" > /usr/share/nginx/html/index.php


접속 확인 http://000.000.000.000/


10. Mysql5.5 설치

yum --enablerepo=remi,remi-test install mysql mysql-server


11. Mysql 시작

service mysqld start


12. Mysql 보안 설정 

/usr/bin/mysql_secure_installation



13. Mysql 접속

mysql -u root -p [위의 보안설정에서 설정한 비번]



 nginx, php-fpm, php apc모듈 및 mysql 설치 완료 




[참고]


방화벽 설정

 # vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


 # /etc/rc.d/init.d/iptables restart