본문 바로가기
Linux

How To Install LEMP? on CentOS 7 [mariadb, php 설치편]

by 듀빈 2015. 11. 17.
반응형

안녕하세요.

듀빈입니다. 이번에는 CentOS7 에 LEMP (Linux + Nginx(발음이 엔진이어서 E) 1.8 + MariaDB + php5.6) 설치 방법을 포스팅 하고자 합니다.

설치 환경은 Hyper-v 에 메모리 2기가를 할당하여서 서버를 구동 하였고, 아직 리눅스 초보이기 때문에 모르는 것 투성이니.. 충고나 의견 부탁드립니다~!

 

Install MariaDB 5.5

첫 번째 단계 : MariaDB 버전 확인

1
# yum list mariadb mariadb-server
cs

1
2
3
Available Packages
mariadb.x86_64                    1:5.5.44-1.el7_1             updates
mariadb-server.x86_64             1:5.5.44-1.el7_1             updates
cs

 

두 번째 단계 : MariaDB 설치

1
# yum install -y mariadb mariadb-server
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Installed:
  mariadb.x86_64 1:5.5.44-1.el7_1
  mariadb-server.x86_64 1:5.5.44-1.el7_1
 
Dependency Installed:
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
  perl-DBD-MySQL.x86_64 0:4.023-5.el7
  perl-DBI.x86_64 0:1.627-4.el7
  perl-Data-Dumper.x86_64 0:2.145-3.el7
  perl-IO-Compress.noarch 0:2.061-2.el7
  perl-Net-Daemon.noarch 0:0.48-5.el7
  perl-PlRPC.noarch 0:0.2020-14.el7
 
Complete!
cs

MariaDB, MariaDB-Server 와 의존 파일들이 설치 된 것을 확인 할 수 있습니다.

세 번째 단계 : MariaDB 시작 및 설정

1
2
# systemctl start mariadb
# systemctl enable mariadb.service
cs

 

네 번째 단계 : MYSQL 보안 설정

1
# mysql_secure_installation
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.
 
Set root password? [Y/n] [y 입력]
New password: [패스워드 입력]
Re-enter new password: [패스워드 재 입력]
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] [y 입력]
 ... 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] [y 입력]
 ... Success!
 
By default, MariaDB 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] [y 입력]
 - 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] [y 입력]
 ... Success!
 
Cleaning up...
 
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!
 
cs

 

이렇게 MariaDB 5.5 버전이 설치가 완료 되었습니다. 다음은 php 설치 입니다.

 

Install PHP 5.6

필자는 php5.6 버전을 설치하도록 하겠습니다. 우선 yum 에 php 5.6가 있는지 확인합니다.

 

첫 번째 단계 : php5.6 버전 확인

1
# yum list php
cs

1
2
Available Packages
php.x86_64                   5.4.16-36.el7_1                   updates
cs

이용가능한  버전이 5.4 로 뜨게 됩니다. 필자는 5.6을 설치해야 하니 조금 수정하겠습니다.

1
2
# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
cs

1
# yum list php56w php56w-mysql php56w-fpm php56w-common
cs

1
2
3
4
5
Available Packages
php56w.x86_64                      5.6.14-2.w7                webtatic
php56w-common.x86_64               5.6.14-2.w7                webtatic
php56w-fpm.x86_64                  5.6.14-2.w7                webtatic
php56w-mysql.x86_64                5.6.14-2.w7                webtatic
cs

php5.6이 설치가능한 모습을 볼 수 있습니다.

 

두 번째 단계 : PHP 5.6 설치

1
yum -y install php56w php56w-common php56w-mysql php56w-fpm php56w-opcache
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Installed:
  php56w.x86_64 0:5.6.14-2.w7      php56w-common.x86_64 0:5.6.14-2.w7
  php56w-fpm.x86_64 0:5.6.14-2.w7  php56w-mysql.x86_64 0:5.6.14-2.w7
  php56w-opcache.x86_64 0:5.6.14-2.w7
 
Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7
  apr-util.x86_64 0:1.5.2-6.el7
  httpd.x86_64 0:2.4.6-31.el7.centos.1
  httpd-tools.x86_64 0:2.4.6-31.el7.centos.1
  mailcap.noarch 0:2.1.41-2.el7
  php56w-cli.x86_64 0:5.6.14-2.w7
  php56w-pdo.x86_64 0:5.6.14-2.w7
 
Complete!
cs

PHP 5.6버전과 의존파일들이 설치된 것을 확인할 수 있습니다.

 

세 번째 단계 : PHP 5.6 과 Nginx 1.8 연동

1
# vi /etc/php.ini
cs

1
2
3
4
5
6
7
8
9
10
[PHP]
 
;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;
 
~~~~~~~~~~~~~~~~~~~~~~~
 
;cgi.fix_pathinfo=1 // 주석 제거 후 1에서 0으로 수정
cgi.fix_pathinfo=0
cs

1
# vi /etc/php-fpm.d/www.conf
cs

1
2
3
4
5
6
7
listen = /var/run/php-fpm/php-fpm.sock
 
listen.owner = nginx
listen.group = nginx
 
user = nginx
group = nginx
cs

빨간 색 부분을 수정 해 줍니다. 주석이 있을 경우 주석을 제거합니다.

 

네 번째 단계 : php-fpm 실행 및 자동 실행

1
2
# systemctl start php-fpm
# systemctl enable php-fpm.service
cs

 

다섯 번째 단계 : Nginx 호스트 설정

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
server {
    listen       80;
    server_name  도메인 이름 or IP or LocalHost;
 
    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html; // 기본적으로 읽어올 폴더
    index index.php index.html index.htm; // 앞 순서로 파일을 먼저 읽음
 
    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
 
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
cs

기본 파일이 있으면 빨간색 부분만 수정 OR 추가 해주시고 없으시면 전체 복사하시면 됩니다.

 

여섯 번째 단계 : 테스트 프로그램 작성

1
# vi /usr/share/nginx/html/index.php
cs

1
<?php phpinfo();?>
cs

 

일곱 번째 단계 : 실행 테스트

 

 

정상적으로 실행되는 것을 확인 할 수 있습니다! 이로서 LEMP 설치가 완료되었습니다~

반응형

'Linux' 카테고리의 다른 글

How To Install LEMP? on CentOS 7 [Nginx 설치편]  (0) 2015.11.16