본 글은 CentOS 6.3에서 Nginx, PHP-FPM, MySQL을 설치하는 방법이며 설치 순서는 MySQL, Nginx, PHP-FPM 입니다.

1. 설치
– epel
기본 저장소에는 nginx와 php-fpm, 각종 php extension들이 없기 때문에 사용하겠습니다.

[root@ruo91 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
[root@ruo91 ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

 

epel, remi 저장소가 우선시 되도록 priority 설치 및 설정

[root@ruo91 ~]# yum install -y yum-priorities

[root@ruo91 ~]# nano /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 – $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
priority=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[root@ruo91 ~]# nano /etc/yum.repos.d/remi.repo
[remi]
name=Les RPM de remi pour Enterprise Linux $releasever – $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
priority=1

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority

 

– MySQL

[root@ruo91 ~]# yum install -y mysql mysql-server
[root@ruo91 ~]# chkconfig –levels 235 mysqld on

 

– Nginx

[root@ruo91 ~]# yum install -y nginx
[root@ruo91 ~]# chkconfig –levels 235 nginx on

 

– PHP

[root@ruo91 ~]# yum install -y php-fpm php-cli php-mysql php-gd php-imap php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash php-shout php-snmp php-soap php-tidy php-pecl-apc
[root@ruo91 ~]# chkconfig –levels 235 php-fpm on

 

2. 설정
– MySQL

[root@ruo91 ~]# nano /etc/my.cnf
[mysqld]
skip-networking
……….

 

MySQL 데몬 시작

[root@ruo91 ~]# /etc/init.d/mysqld start
MySQL 데이타베이스 초기화 중: Installing MySQL system tables…
OK
Filling help tables…
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h ruo91 password ‘new-password’

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[ OK ]
mysqld (을)를 시작 중: [ OK ]

 

root 암호와 기타 보안 설정

[root@ruo91 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): Enter
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Enter
New password: 새암호 입력
Re-enter new password: 새암호 재입력
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Enter
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Enter
… Success!

By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Enter
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Enter
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

 

– PHP
cgi.fix_pathinfo값을 0으로 변경

[root@ruo91 ~]# nano /etc/php.ini
cgi.fix_pathinfo=0

 

timezone 설정

[root@ruo91 ~]# cat /etc/sysconfig/clock
ZONE=”Asia/Seoul”

[root@ruo91 ~]# cat /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = “Asia/Seoul”

 

php-fpm을 띄울 user, group 설정

[root@ruo91 ~]# /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

 

php-fpm 시작

[root@ruo91 ~]# /etc/init.d/php-fpm start
php-fpm (을)를 시작 중: [ OK ]

 

php-fpm 프로세스 확인

[root@ruo91 ~]# ps aux | grep -v grep | grep php-fpm
root 2803 0.0 2.1 116372 5428 ? Ss 00:23 0:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 2804 0.0 2.0 116372 5056 ? S 00:23 0:00 php-fpm: pool www
nginx 2805 0.0 2.0 116372 5056 ? S 00:23 0:00 php-fpm: pool www
nginx 2806 0.0 2.0 116372 5056 ? S 00:23 0:00 php-fpm: pool www
nginx 2807 0.0 2.0 116372 5056 ? S 00:23 0:00 php-fpm: pool www
nginx 2808 0.0 2.0 116372 5056 ? S 00:23 0:00 php-fpm: pool www

 

– Nginx

[root@ruo91 ~]# nano /etc/nginx/conf.d/default.conf
# 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 $document_root$fastcgi_script_name;
include fastcgi_params;
}

 

Nginx 시작

[root@ruo91 ~]# /etc/init.d/nginx start
nginx (을)를 시작 중: [ OK ]

– phpinfo test

[root@ruo91 ~]# echo “<?php phpinfo();” > /usr/share/nginx/html/phpinfo.php

Thanks 😀