CentOS 8 - 웹 서버 구축 [APM] 설치

    CentOS 8 - Web Server [APM] - YUM install

    LINUX APM란?
    APM은 하나의 소프트웨어가 아닌 [Apache, MariaDB(Mysql), PHP] 3개의 오픈소스 소프트웨어 앞글자를 딴 줄임말입니다.
    Apache [공식 홈페이지] - HTTP를 통해 웹페이지(텍스트/그림)등을 요청 처리해주는 웹서버 프로그램
    PHP(Hypertext Preprocessor) [공식 홈페이지] - 오픈 소스 범용 스크립팅 언어
    MariaDB [공식 홈페이지] - 오픈 소스의 관계형 데이터베이스 관리 시스템

    3개의 다른 오픈소스 소프트웨어는 서로 호환성 및 범용성이 좋아 현재는 대부분의

    개인 웹호스팅 업체에서 기본적으로 제공을 하고 있습니다.

     

    ※ Mysql의 경우는 오라클 업체에서 인수 및 상용화되고 나서부터는 대부분이 무료 오픈 소스인 MariaDB 대체되고 있습니다. MariaDB는 핵심 개발자가 나와서 Mysql과 동일한 소스 코드를 기반으로 개발하였기 때문에 API와 명령어는 거의 동일합니다. 현재는 마리아 DB [10.X] 변경되어 새로운 기능이 추가되고 독립적인 오픈 소스 기반으로 운영되고 있습니다.

    ■ [설치환경 및 준비물]

    릴리즈 설치 테스트 : 2020-06-17

    CentOS 8 리눅스 설치 서버 [포스팅 참고]

    OS버전

    [root@localhost ~]# cat /etc/redhat-release

    CentOS Linux release 8.1.1911 (Core)

     

    ※ CentOS 8 커널 5.7 적용 후 테스트 진행 [기본 커널에서 작업해도 상관없음]
    [root@localhost ~]# uname -r

    5.7.2-1.el8.elrepo.x86_64

    ※ CentOS 8부터는 별도의 미러 경로를 잡지 않아도 YUM 설치만으로 최신 릴리즈 버전이 설치됩니다.
    [2020-06-17] 기준으로 설치되는 버전들
    Apache(Httpd) : 2.4.X
    PHP : 7.2.X [REMI저장소 : 7.4.X]

    MariaDB : 10.3.X [마리아 저장소 : 10.4.X]

    원래는 웹을 개발하려는 환경에 따라 버전에 맞게 RPM/소스파일로 설치하는 게 좋겠지만 크게 영향을 받지 않는다면 일반적으로 YUM(자동 설치)로 쉽게 진행하는 게 좋습니다. 소스로 설치하는 방법은 따로 포스팅하도록 하겠습니다.


    ■ [APM] Apache, PHP, MariaDB Install Guide 시작

    ※ 설치하기 전 APM 설치하기 위한 필수 의존성 라이브러리 설치 필요

    라이브러리 설치 확인
    [root@localhost ~]# rpm -qa libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel

    freetype-2.9.1-4.el8.x86_64

    libpng-1.6.34-5.el8.x86_64

    libjpeg-turbo-1.5.3-10.el8.x86_64

    gcc-8.3.1-4.5.el8.x86_64

    gcc-c++-8.3.1-4.5.el8.x86_64

     

    YUM을 이용하여 한번에 설치

    [root@localhost ~]# yum install libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel

    ==============================================================================
     Package                             Architecture            Version                         Repository                 Size
    ==============================================================================
    Installing:
     gd-devel                                 x86_64             2.2.5-6.el8                    AppStream              50 k
     libjpeg-turbo-devel           x86_64             1.5.3-10.el8                  AppStream             109 k
     libjpeg-turbo-utils             x86_64             1.5.3-10.el8                  AppStream              93 k
     libpng12                                x86_64             1.2.57-5.el8                   AppStream             160 k
     libpng15                                x86_64             1.5.30-7.el8                   AppStream              88 k
     freetype-devel                    x86_64             2.9.1-4.el8                       BaseOS                    464 k
     gdbm-devel                         x86_64             1:1.18-1.el8                    BaseOS                    66 k
     libpng-devel                        x86_64             2:1.6.34-5.el8                 BaseOS                   327 k
    Upgrading:
     cpp                                         x86_64             8.3.1-5.el8.0.2                AppStream              10 M
     gcc                                          x86_64             8.3.1-5.el8.0.2                AppStream              23 M
     gcc-c++                                 x86_64             8.3.1-5.el8.0.2                AppStream              12 M
     gcc-gdb-plugin                 x86_64             8.3.1-5.el8.0.2                AppStream             117 k
     libX11                                    x86_64             1.6.8-3.el8                       AppStream             611 k
     libX11-common                noarch             1.6.8-3.el8                       AppStream             158 k
     libXpm                                  x86_64             3.5.12-8.el8                     AppStream              58 k
     libstdc++-devel                 x86_64             8.3.1-5.el8.0.2                AppStream             2.0 M
     libtiff                                      x86_64             4.0.9-17.el8                    AppStream             188 k
     libxcb                                     x86_64             1.13.1-1.el8                   AppStream             229 k
     libblkid                                 x86_64             2.32.1-22.el8                  BaseOS                   214 k
     libfdisk                                 x86_64             2.32.1-22.el8                   BaseOS                   249 k
     libgcc                                    x86_64             8.3.1-5.el8.0.2                BaseOS                   78 k
     libgomp                               x86_64             8.3.1-5.el8.0.2                BaseOS                   203 k
     libmount                              x86_64             2.32.1-22.el8                  BaseOS                   231 k
     libsmartcols                       x86_64             2.32.1-22.el8                  BaseOS                   174 k
     libstdc++                              x86_64             8.3.1-5.el8.0.2                BaseOS                  451 k
     libuuid                                  x86_64             2.32.1-22.el8                  BaseOS                   94 k
     util-linux                              x86_64             2.32.1-22.el8                  BaseOS                   2.5 M
     util-linux-user                   x86_64             2.32.1-22.el8                  BaseOS                    98 k
    Installing dependencies:
     libX11-devel                      x86_64             1.6.8-3.el8                      AppStream             976 k
     libX11-xcb                          x86_64             1.6.8-3.el8                      AppStream              14 k
     libXau-devel                      x86_64             1.0.8-13.el8                   AppStream              20 k
     libXpm-devel                    x86_64             3.5.12-8.el8                   AppStream              39 k
     libtiff-devel                        x86_64             4.0.9-17.el8                   AppStream             511 k
     libwebp-devel                  x86_64             1.0.0-1.el8                      AppStream              37 k
     libxcb-devel                      x86_64             1.13.1-1.el8                   AppStream             1.1 M
     xorg-x11-proto-devel    noarch             2018.4-1.el8                  AppStream             283 k
     bzip2-devel                       x86_64             1.0.6-26.el8                    BaseOS                    224 k
     expat-devel                       x86_64             2.2.5-3.el8                      BaseOS                    55 k
     fontconfig-devel             x86_64             2.13.1-3.el8                    BaseOS                    151 k
     libuuid-devel                    x86_64             2.32.1-22.el8                 BaseOS                    95 k

    Transaction Summary
    =============================================================================

    설치        20 Packages
    업그레이드  20 Packages


    Is this ok [y/N]: y
    Total download size: 58 M

    ...

    업그레이드됨:
      cpp-8.3.1-5.el8.0.2.x86_64                  gcc-8.3.1-5.el8.0.2.x86_64           gcc-c++-8.3.1-5.el8.0.2.x86_64

      gcc-gdb-plugin-8.3.1-5.el8.0.2.x86_64    libX11-1.6.8-3.el8.x86_64          libX11-common-1.6.8-3.el8.noarch  

      libXpm-3.5.12-8.el8.x86_64                  libstdc++-devel-8.3.1-5.el8.0.2.x86_64       libtiff-4.0.9-17.el8.x86_64

      libxcb-1.13.1-1.el8.x86_64                  libblkid-2.32.1-22.el8.x86_64                libfdisk-2.32.1-22.el8.x86_64
      libgcc-8.3.1-5.el8.0.2.x86_64               libgomp-8.3.1-5.el8.0.2.x86_64               libmount-2.32.1-22.el8.x86_64
      libsmartcols-2.32.1-22.el8.x86_64           libstdc++-8.3.1-5.el8.0.2.x86_64             libuuid-2.32.1-22.el8.x86_64
      util-linux-2.32.1-22.el8.x86_64             util-linux-user-2.32.1-22.el8.x86_64

     

    설치됨:
      gd-devel-2.2.5-6.el8.x86_64            libjpeg-turbo-devel-1.5.3-10.el8.x86_64   libjpeg-turbo-utils-1.5.3-10.el8.x86_64

      libpng12-1.2.57-5.el8.x86_64               libpng15-1.5.30-7.el8.x86_64              freetype-devel-2.9.1-4.el8.x86_64
      gdbm-devel-1:1.18-1.el8.x86_64             libpng-devel-2:1.6.34-5.el8.x86_64        libX11-devel-1.6.8-3.el8.x86_64
      libX11-xcb-1.6.8-3.el8.x86_64              libXau-devel-1.0.8-13.el8.x86_64          libXpm-devel-3.5.12-8.el8.x86_64
      libtiff-devel-4.0.9-17.el8.x86_64          libwebp-devel-1.0.0-1.el8.x86_64          libxcb-devel-1.13.1-1.el8.x86_64

      xorg-x11-proto-devel-2018.4-1.el8.noarch   bzip2-devel-1.0.6-26.el8.x86_64           expat-devel-2.2.5-3.el8.x86_64
      fontconfig-devel-2.13.1-3.el8.x86_64       libuuid-devel-2.32.1-22.el8.x86_64

     

    완료되었습니다!

    ■ Apache, MariaDB, PHP 설치 순서로 진행

    1. 아파치(Apache) 설치

    [root@localhost ~]# yum install httpd

    ======================================================================================
     Package                                    Architecture               Version                                    Repository                 Size 
    ======================================================================================
    Installing:
     httpd                                            x86_64        2.4.37-21.module_el8.2.0+382+15b0afa8      AppStream            1.7 M
    Installing dependencies:
     apr                                                x86_64                  1.6.3-9.el8                                    AppStream             125 k
     apr-util                                        x86_64                  1.6.1-6.el8                                    AppStream             105 k
     httpd-filesystem                     noarch        2.4.37-21.module_el8.2.0+382+15b0afa8      AppStream              36 k
     httpd-tools                               x86_64        2.4.37-21.module_el8.2.0+382+15b0afa8     AppStream              103 k
     mod_http2                               x86_64        1.11.3-3.module_el8.2.0+307+4d18d695      AppStream              157 k
     centos-logos-httpd               noarch                  80.5-2.el8                                       BaseOS                   24 k
    Installing weak dependencies:
     apr-util-bdb                              x86_64                  1.6.1-6.el8                                     AppStream              25 k
     apr-util-openssl                      x86_64                  1.6.1-6.el8                                     AppStream              27 k
    Enabling module streams:
     httpd                                                                          2.4

    Transaction Summary
    ======================================================================================
    설치  9 Packages

     

    Total download size: 2.3 M
    Installed size: 6.0 M
    Is this ok [y/N]:y

    설치됨:
      httpd-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64   apr-util-bdb-1.6.1-6.el8.x86_64

      apr-util-openssl-1.6.1-6.el8.x86_64  apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64

      httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch

      httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64

      mod_http2-1.11.3-3.module_el8.2.0+307+4d18d695.x86_64 centos-logos-httpd-80.5-2.el8.noarch

     

    완료되었습니다!

    2. 마리아(Maria DB) 설치

    기본 미러 사이트에서 YUM으로 설치해도 10.3.X 버전이 설치가 되지만 MariaDB의 경우는
    자체 공식 미러 사이트를 제공하고 있으므로 직접 저장소 생성하여 진행하는 게 좋습니다. (버전별로 가능)

    배포 사이트 : [링크]

    버전별 세팅 방법(스크린샷 참고) : [링크]

    먼저 YUM 저장소 생성[파일 생성 후 저장]

    [root@localhost ~]# vi /etc/yum.repos.d/MariaDB.repo

    # MariaDB 10.4 CentOS repository list - created 2020-06-18 04:58 UTC

    # http://downloads.mariadb.org/mariadb/repositories/

    [mariadb]
    name = MariaDB

    baseurl = http://yum.mariadb.org/10.4/centos8-amd64

    module_hotfixes=1

    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    gpgcheck=1

    MariaDB 설치

    [root@localhost ~]# yum install MariaDB-server MariaDB-client

    Dependencies resolved.
    =======================================================================================
     Package                                  Architecture               Version                  Repository                             Size
    =======================================================================================
    Installing:
     MariaDB-client                          x86_64             10.4.13-1.el8                 mariadb                              12 M
     MariaDB-server                         x86_64             10.4.13-1.el8                 mariadb                              26 M
    Installing dependencies:
     boost-program-options        x86_64             1.66.0-7.el8                    AppStream                       140 k
     perl-DBI                                        x86_64             1.641-3.module_el8.1.0+199+8f0a6bbd     AppStream        740 k
     perl-Math-BigInt                       noarch             1:1.9998.11-7.el8         BaseOS                               196 k
     perl-Math-Complex                 noarch             1.59-416.el8                   BaseOS                               108 k
     MariaDB-common                   x86_64             10.4.13-1.el8                   mariadb                               87 k
     MariaDB-shared                       x86_64             10.4.13-1.el8                   mariadb                              115 k
     galera-4                                       x86_64              26.4.4-1.rhel8.0.el8      mariadb                              13 M

    Transaction Summary
    ======================================================================================
    설치  9 Packages

    ..

    Total download size: 53 M
    Installed size: 251 M
    Is this ok [y/N]: y

    ..

    GPG키 0x1BB943DB를 불러옵니다:
     사용자     : "MariaDB Package Signing Key <package-signing-key@mariadb.org>"

      GPG 지문: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB

     출처        : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

    Is this ok [y/N]: y

    ..

     

    설치됨:
      MariaDB-client-10.4.13-1.el8.x86_64                MariaDB-server-10.4.13-1.el8.x86_64

      boost-program-options-1.66.0-7.el8.x86_64      perl-DBI-1.641-3.module_el8.1.0+199+8f0a6bbd.x86_64

      perl-Math-BigInt-1:1.9998.11-7.el8.noarch        perl-Math-Complex-1.59-416.el8.noarch

      MariaDB-common-10.4.13-1.el8.x86_64           MariaDB-shared-10.4.13-1.el8.x86_64

      galera-4-26.4.4-1.rhel8.0.el8.x86_64

     

    완료되었습니다!

    3. PHP 설치

    기본 미러 사이트에서 YUM으로 설치해도 7.2.X 버전이 설치가 되지만 동일하게 버전(모듈) 별로 자유롭게 설치하기 위해서는 REMI 저장소를 이용하는 게 좋습니다.

    공식 블로그 사이트 : [링크]

    버전별 세팅 방법(스크린샷 참고) : [링크]

    먼저 [REMI] 저장소 설치

    [root@localhost ~]# yum install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

     

    Dependencies resolved.
    ===========================================================================
     Package                                   Architecture            Version                   Repository                      Size
    ===========================================================================
    Installing:
     remi-release                               noarch                8.1-2.el8..remi       @commandline            23 k
    Installing dependencies:
     epel-release                                noarch                8-8.el8                       extras                                23 k

    Transaction Summary
    ===========================================================================
    설치  2 Packages

    Total size: 46 k
    Total download size: 23 k
    Installed size: 49 k
    Is this ok [y/N]: y

    ..

    설치됨:
      remi-release-8.1-2.el8.remi.noarch      epel-release-8-8.el8.noarch

     

    완료되었습니다!

    설치 가능한 리스트 확인

    [root@localhost ~]# yum module list php

    CentOS-8 - AppStream
    Name                Stream                    Profiles                                                           Summary                                
    php                    7.2 [d]                     common [d], devel, minimal                  PHP scripting language
    php                    7.3                            common [d], devel, minimal                  PHP scripting language

    Remi's Modular repository for Enterprise Linux 8 - x86_64
    Name                Stream                     Profiles                                                           Summary
    php                    remi-7.2                  common [d], devel, minimal                  PHP scripting language
    php                    remi-7.3                  common [d], devel, minimal                  PHP scripting language
    php                    remi-7.4                  common [d], devel, minimal                  PHP scripting language

    Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

    PHP [7.4] 모듈을 사용하기 위한 활성화 및 디폴트 설정

    [root@localhost ~]# yum module enable php:remi-7.4

     

    Dependencies resolved.
    ================================================================================
     Package                                    Architecture               Version                      Repository                   Size
    ================================================================================

    Enabling module streams:
     php                                                 remi-7.4 

     

    Transaction Summary
    ================================================================================

    Is this ok [y/N]: y

    완료되었습니다!

    PHP설치

    [root@localhost modules]# yum install php

    Dependencies resolved.

    ================================================================================
     Package                                  Architecture               Version                      Repository                   Size
    ================================================================================

    Installing:
     php                                               x86_64             7.4.7-1.el8.remi                 remi-modular             3.0 M

    Installing dependencies:
     libsodium                                  x86_64             1.0.18-2.el8                           epel                                162 k

     php-common                          x86_64             7.4.7-1.el8.remi                   remi-modular             1.2 M

     php-json                                    x86_64             7.4.7-1.el8.remi                   remi-modular              75 k

     oniguruma5php                     x86_64             6.9.5+rev1-2.el8.remi        remi-safe                      206 k

    Installing weak dependencies:
     nginx-filesystem                     noarch    1:1.14.1-9.module_el8.0.0+184+e34fea82         AppStream           24 k

     php-cli                                        x86_64             7.4.7-1.el8.remi                   remi-modular             4.6 M

     php-fpm                                    x86_64             7.4.7-1.el8.remi                    remi-modular             1.6 M

     php-mbstring                          x86_64             7.4.7-1.el8.remi                   remi-modular             528 k

     php-opcache                           x86_64             7.4.7-1.el8.remi                   remi-modular             334 k

     php-pdo                                    x86_64             7.4.7-1.el8.remi                    remi-modular             143 k

     php-sodium                             x86_64             7.4.7-1.el8.remi                    remi-modular              87 k

     php-xml                                     x86_64             7.4.7-1.el8.remi                    remi-modular             215 k

    Enabling module streams:
     nginx                                                                              1.14                                                                              

    Transaction Summary
    ============================================================================

    설치  13 Packages

    Total download size: 12 M
    Installed size: 59 M
    Is this ok [y/N]: y

    ..

    php-7.4.7-1.el8.remi.x86_64                         nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch

    php-cli-7.4.7-1.el8.remi..x86_64                                php-fpm-7.4.7-1.el8.remi.x86_64

    php-mbstring-7.4.7-1.el8.remi.x86_64                   php-opcache-7.4.7-1.el8.remi.x86_64

    php-pdo-7.4.7-1.el8.remi.x86_64                             php-sodium-7.4.7-1.el8.remi.x86_64

    php-xml-7.4.7-1.el8.remi.x86_64                              libsodium-1.0.18-2.el8.x86_64

    php-common-7.4.7-1.el8.remi.x86_64                   php-json-7.4.7-1.el8.remi.x86_64

    oniguruma5php-6.9.5+rev1-2.el8.remi.x86_64


    완료되었습니다!

    자주 사용되는 PHP모듈 추가 설치 [fpm/pdo/mbstring/xml 이미 설치되어 제외]

    [root@localhost ~]# yum install php-mysqlnd php-pgsql php-odbc php-pdo-dblib php-gd php-pear php-xmlrpc php-pecl-mcrypt

     

    ependencies resolved.
    ==================================================================================
     Package                                       Architecture                 Version                             Repository               Size
    ==================================================================================

    Installing:
     php-gd                                         x86_64                7.4.7-1.el8.remi                      remi-modular             91 k

     php-mysqlnd                             x86_64                7.4.7-1.el8.remi                      remi-modular            259 k

     php-odbc                                    x86_64                7.4.7-1.el8.remi                      remi-modular             98 k

     php-pdo-dblib                          x86_64                7.4.7-1.el8.remi                      remi-modular             67 k

     php-pear                                     noarch                1:1.10.12-1.el8.remi              remi-modular           365 k

     php-pecl-mcrypt                     x86_64                1.0.3-1.el8.remi.7.4               remi-modular             35 k

     php-pgsql                                   x86_64                7.4.7-1.el8.remi                      remi-modular            140 k

     php-xmlrpc                                x86_64                7.4.7-1.el8.remi                      remi-modular             93 k

    Installing dependencies:
     libpq                                             x86_64                12.1-3.el8                                  AppStream                 195 k

     unixODBC                                   x86_64                2.3.7-1.el8                                 AppStream                 458 k
     freetds                                         x86_64                1.1.20-1.el8                               epel                               411 k
     freetds-libs                                x86_64                1.1.20-1.el8                               epel                               378 k
     libmcrypt                                   x86_64                2.5.8-26.el8                                epel                              109 k

     php-fedora-autoloader       noarch                1.0.1-2.el8.remi                       remi-modular            13 k

     php-process                             x86_64                7.4.7-1.el8.remi                       remi-modular             96 k

     

    Transaction Summary

    ===================================================================================

    설치  15 Packages

    Total download size: 2.7 M
    Installed size: 10 M
    Is this ok [y/N]: y

    ..

    설치됨:
      php-gd-7.4.7-1.el8.remi.x86_64                          php-mysqlnd-7.4.7-1.el8.remi.x86_64               

      php-odbc-7.4.7-1.el8.remi.x86_64                      php-pdo-dblib-7.4.7-1.el8.remi.x86_64

      php-pear-1:1.10.12-1.el8.remi.noarch               php-pecl-mcrypt-1.0.3-1.el8.remi.x86_64

      php-pgsql-7.4.7-1.el8.remi.x86_64                      php-xmlrpc-7.4.7-1.el8.remi.x86_64                   

      libpq-12.1-3.el8.x86_64                                            unixODBC-2.3.7-1.el8.x86_64                                               

      freetds-1.1.20-1.el8.x86_64                                    freetds-libs-1.1.20-1.el8.x86_64                                           

      libmcrypt-2.5.8-26.el8.x86_64                              php-fedora-autoloader-1.0.1-2.el8.remi.noarch

      php-process-7.4.7-1.el8.remi.x86_64


    완료되었습니다!

    [참고]

    [root@localhost html]# php -m

     

    다음 명령어를 이용하면 적용되어있는 모듈을 확인 하실 수 있습니다.

    [PHP Modules]
    bz2
    calendar
    Core
    ctype
    curl
    date
    dom
    exif
    fileinfo
    filter
    ftp
    gd
    gettext
    hash
    iconv
    json
    libxml
    mbstring
    mcrypt
    mysqli
    mysqlnd
    odbc
    openssl
    pcntl
    pcre
    PDO
    pdo_dblib
    pdo_mysql
    PDO_ODBC
    pdo_pgsql
    pdo_sqlite
    pgsql
    Phar
    posix
    readline
    Reflection
    session
    shmop
    SimpleXML
    sockets
    sodium
    SPL
    sqlite3
    standard
    sysvmsg
    sysvsem
    sysvshm
    tokenizer
    xml
    xmlreader
    xmlrpc
    xmlwriter
    xsl
    Zend OPcache
    zlib

    [Zend Modules]
    Zend OPcache

    □ 설치 버전 확인

    [root@localhost ~]# httpd -v
    Server version: Apache/2.4.37 (centos)
    Server built:   Jun  8 2020 20:14:33

     

    [root@localhost ~]# php -v
    PHP 7.4.7 (cli) (built: Jun  9 2020 10:57:17) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies

     

    옵션 대문자

    [root@localhost ~]# mysql -V
    mysql  Ver 15.1 Distrib 10.4.13-MariaDB, for Linux (x86_64) using readline 5.1


    ■ [APM] Apache, PHP, MariaDB config(설정) 및 구동

    1. 아파치(Apache) 설정 및 구동

    □ 1-1 기본 설정(수정 후 저장)

    [root@localhost ~]# vi /etc/httpd/conf/httpd.conf

         65 # User/Group: The name (or #number) of the user/group to run httpd as.
         66 # It is usually good practice to create a dedicated user and group for
         67 # running httpd, as with most system services.
         68 #
         69 User nobody                  (apache → nobody 변경)
         70 Group nobody               (apache → nobody 변경)

    ..
         92 # ServerName gives the name and port that the server uses to identify itself.
         93 # This can often be determined automatically, but we recommend you specify
         94 # it explicitly to prevent problems during startup.
         95 #
         96 # If your host doesn't have a registered DNS name, enter its IP address here.
         97 #

         98 #ServerName www.example.com:80
         99 ServerName 192.168.232.128:80                      (도메인 또는 해당 서버 IP 입력 추가)

    [참고]
    apache → nobody 변경
    ROOT 권한으로 실행된 아파치의 하위 프로세스를 이곳에서 지정한 사용자로 실행한다는 의미,
    기본값으로 apache 또는 daemon으로 되어있지만 대부분 nobody로 변경하여 이용한다. 약간 보안적인 의미를 포함

     

     ServerName
    자기 서버가 이 도메인을 사용한다는 것을 알리기 위한 수단, 예를 들어

    ServerName www.test.com:80 → 홈페이지 접속 시 해당 도메인(http://www.test.com)으로 연결

    ServerName 192.168.122.128:80 → 홈페이지 접속 시 해당 도메인(http://192.168.122.128)으로 연결 (도메인이 없을 경우 IP 입력)

     

     IP는 자기 서버 IP 세팅
    [root@localhost ~]# ifconfig
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.232.128 (이 부분)  netmask 255.255.255.0  broadcast 192.168.232.255

    □ 1-2 방화벽 설정(수정 후 저장)

    환경설정이 완료가 되었으니 웹을 열기 위해선 방화벽 80번 포트를 오픈해야 합니다.

    [root@localhost ~]# vi /etc/sysconfig/iptables


    # sample configuration for iptables service
    # you can edit this manually or use system-config-firewall
    # please do not ask us to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT                 [라인 추가]
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT

    [참고]
    iptables에서 순서는 매우 중요합니다. 일반적으로 적용되는 순서는 위에서부터 아래로 순차적으로 읽어옵니다.
    예를 들어 추가한 맨 아래의 라인 쪽에 추가를 하게 되면 적용이 정상적으로 안됩니다. 이해가 안 될 경 우는 스크린샷 그대로 따라 진행해주세요. 나중에 별도로 iptables 설명을 하도록 하겠습니다.

    □ 1-3 방화벽 재시작(service iptables restart 명령어 사용 가능)

    [root@localhost ~]# systemctl restart iptables

    □ 1-4 적용 확인

    [root@localhost ~]# iptables -nL
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:8888
    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80   [오픈 확인]
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination
    REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination

    □ 1-5 아파치 시작

    아파치 구동[service httpd start(stop) 명령어 사용 가능]

    [root@localhost ~]# systemctl start httpd

     

    부팅 후 자동 실행 설정[비활성화 시 disable]
    [root@localhost ~]# systemctl enable httpd
    Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

    □ 1-6 아파치 구동 확인

    [root@localhost ~]# ps -ef |grep httpd
    root             6275      1      0 22:17 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    nobody     6276   6275  0 22:17 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    nobody     6277   6275  0 22:17 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    nobody     6278   6275  0 22:17 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    nobody     6279   6275  0 22:17 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
    root            6548   6097  0 22:21 pts/0    00:00:00 grep --color=auto httpd

    □ 1-7 웹 구동 확인 테스트(스크린샷 참고)

     

    2. PHP 환경설정 및 구동(경로)

    □ 2-1 httpd 설정 기본 파일 PHP MINE 기본 설정(수정 후 저장)

    [root@localhost ~]# vi /etc/httpd/conf/httpd.conf


        164 # DirectoryIndex: sets the file that Apache will serve if a directory
        165 # is requested.
        166 #
        167 <IfModule dir_module>
        168     DirectoryIndex index.html index.htm index.php         [일부 추가]

        169 </IfModule>

     

        284     # If the AddEncoding directives above are commented-out, then you
        285     # probably should define those extensions to indicate media types:
        286     #
        287     AddType application/x-compress .Z
        288     AddType application/x-gzip .gz .tgz
        289    AddType application/x-httpd-php .php             [라인 추가]
        290    AddType application/x-httpd-phps .phps        [라인 추가]

    [참고]
    실제 PHP환경설정을 관리하는 파일은 아래의 경로입니다.

    [root@localhost conf.modules.d]# vi /etc/php.ini

    위 httpd.conf 쪽에 세팅하는 건 아파치에 php 관련 처리를 할 수 있게 추가를 하는 부분입니다.  php.ini 파일 설정은 사용하려는 웹 환경에 맞게튜닝을 해야 하지만 현재는 기본 세팅으로 갑니다. 나중에 따로 설명하도록 하겠습니다.

     

    YUM설치 시 PHP7 모듈 파일 경로

    [root@localhost httpd]# ls -al /etc/httpd/modules/ | grep php7

    -rwxr-xr-x 1 root root 5737848  6월  9 07:52 libphp7-zts.so

    -rwxr-xr-x 1 root root 5588904  6월  9 07:52 libphp7.so

     

    PHP7 모듈 적용 설정 파일 경로[이미 세팅되어있음]

    [root@localhost httpd]# vi /etc/httpd/conf.modules.d/15-php.conf

    LoadModule php7_module modules/libphp7.so

    □ 2-2 PHP-FPM 기본 설정(수정 후 저장)

    [root@localhost ~]# vi /etc/php-fpm.d/www.conf

         24 user = nobody            (apache → nobody 변경)

         26 group = nobody          (apache → nobody 변경)

     

         52 ; When POSIX Access Control Lists are supported you can set them using
         53 ; these options, value is a comma separated list of user/group names.
         54 ; When set, listen.owner and listen.group are ignored
         55 ; listen.acl_users = apache,nginx     [; 주석처리]
         56 listen.acl_groups = nobody        [라인 추가]

    [참고]

    PHP-FPM (PHP FastCGI Process Manager)란?
    웹서버(apache/nginx)와 상호작용(동적)으로 통신 처리하기 위한 프로그램입니다. CGI의 상위 버전이며 통신 시 발생되는 부하를 줄이고 서버가 한 번에 더 많은 웹페이지 요청을 관리할 수 있게 합니다. 예를 들어 [XE/그누보드/워드프레스] 게시판 같은 로그인과 게시글 등록 등의 변화가 많은 사이트에 적합하다고 할 수 있습니다. Apache 보다는 Nginx과 많이 연동하여 사용하며 Remi를 이용해 YUM 설치하면 같이 설치되다 보니 Apache 사용하는 김에 이용하면 좋을 것으로 판단되어 같이 설정합니다.

     

    listen.acl_groups 옵션은 listen.owner 및 listen.group 권한으로 실행되는 것을 제외하는 옵션

    아마 검색해서 들어오시는 대부분의 사용자가 아래와 같은 경험을 하신 분들이 많을 것으로 예상됩니다.

    Apache와 연동하는 경우에는 이상하게 아래의 옵션을 적용을 한 뒤에 PHP-FPM 재시작을 해도

     

    listen.owner  = nobody

    listen.group = nobody

    isten.mode = 0660

     

    [root@localhost php-fpm]# ls -al /var/run/php-fpm/

    -rw-r--r--   1 root root   5  6월 24 01:00 php-fpm.pid

    srw-rw----+  1 root root   0  6월 24 01:00 www.sock

     

    무조건 ROOT 권한으로 실행이 됩니다. 이상태에서. PHP를 열게 되면 아래와 같이 권한 때문에 페이지 에러 발생

     

    [웹 페이지 에러메세지(스크린샷 참고)]

    Service Unavailable

    The server is temporarily unable to service your request due to maintenance downtime or capacity problems.

    Plsase try again later.

     

    [서버 로그 메세지]

    [Tue Jun 23 21:13:02.896505 2020] [proxy:error] [pid 38425:tid 140299678566144] (13)Permission denied: AH02454: F CGI: attempt to connect to Unix domain socket /run/php-fpm/www.sock (*) failed

    [Tue Jun 23 21:13:02.896554 2020] [proxy_fcgi:error] [pid 38425:tid 140299678566144] [client 192.168.232.1:49559] AH01079: failed to make connection to backend: httpd-UDS

     

    이문제는 순수 권한 문제로 발생했기 때문에 실행 권한이 있는 계정과 동일하게 맞춰주면 해결은 됩니다.

     

    [root@localhost ~]# chown -R nobody:nobody /var/run/php-fpm/

    [root@localhost php-fpm]# ls -al /var/run/php-fpm/

    -rw-r--r--   1 nobody nobody   5  6월 24 01:00 php-fpm.pid

    srw-rw----+  1 nobody nobody   0  6월 24 01:00 www.sock

     

    다만 재시작 시 원상 복구되므로 할 때마다 위 명령어를 해줘야 하는 불편함이 있으므로 [listen.acl_groups = nobody] 명령어를 이용해 ROOT로 시작돼도 해당 계정은 예외 될 수 있도록 하는 게 더 좋습니다.

    □ 2-3 PHP-FPM 활성화 및 설정 적용을 위한 재시작

    PHP-FPM 재시작[service php-fpm start(stop) 명령어 사용 가능]
    [root@localhost ~]# systemctl restart php-fpm

     

    부팅 후 자동 실행 설정[비활성화 시 disable]
    [root@localhost ~]# systemctl enable php-fpm
    Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service  → /usr/lib/systemd/system/php-fpm.service.

     

    httpd.conf 설정 변경으로 동일하게 재시작

    [root@localhost ~]# systemctl restart httpd

    □ 2-4 PHP-FPM 구동 확인

    [root@localhost ~]# ps -ef |grep php
    root      31717      1  0 01:00 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)

    nobody    31720  31717  0 01:00 ?        00:00:00 php-fpm: pool www
    nobody    31721  31717  0 01:00 ?        00:00:00 php-fpm: pool www
    nobody    31722  31717  0 01:00 ?        00:00:00 php-fpm: pool www
    nobody    31723  31717  0 01:00 ?        00:00:00 php-fpm: pool www
    nobody    31724  31717  0 01:00 ?        00:00:00 php-fpm: pool www

    □ 2-5 PHP 적용 확인

    Yum 설치 시 기본 html 업로드 기본 디렉터리 경로 이동

    [root@localhost php74]# cd /var/www/html/

     

    해당 경로에서 PHP의 정보를 보여주는 함수 파일 생성 후 저장
    [root@localhost html]# vi /var/www/html/phpinfo.php

     

    <?php phpinfo();?>      [라인 추가]

    파일 생성 확인
    [root@localhost html]# ls
    phpinfo.php

    □ 2-6 PHP 웹 연동 확인 테스트(스크린샷 참고)

    3. MariaDB 구동 및 설정

    □ 3-1 MariaDB 구동

    [root@localhost ~]# systemctl start mariadb

     

    부팅 시 자동 시작 활성화

    [root@localhost ~]# systemctl enable mariadb
    Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.

    Created symlink /etc/systemd/system/mysqld.service  → /usr/lib/systemd/system/mariadb.service.

    Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

     

    구동 확인

    [root@localhost ~]# ps -ef | grep mysql

    mysql 32149 1 6 02:29 ? 00:00:00 /usr/sbin/mysqld

    root 32182 32106 0 02:29 pts/0 00:00:00 grep --color=auto mysql

    □ 3-2 Maria DB 기본 설정 (DB가 구동된 상태에서 진행 가능)

    [root@localhost ~]# mysql_secure_installation

     

    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

    haven't set the root password yet, you should just press enter here.

     

    Enter current password for root (enter for none): (패스워드가 없기 때문에 엔터)

    OK, successfully used password, moving on...

     

    Setting the root password or using the unix_socket ensures that nobody

    can log into the MariaDB root user without the proper authorisation.

     

    You already have your root account protected, so you can safely answer 'n'.

    Switch to unix_socket authentication [Y/n] Y    (MariaDB 실행 시 통신 소켓 생성 여부? Y 엔터)


    You already have your root account protected, so you can safely answer 'n'.
    Change the root password? [Y/n] Y   (DB ROOT 패스워드 설정할 것인가? 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  (익명의 접근을 막을 것인지? 보안을 위해 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 (DB ROOT 원격을 막을 것인지? 보안을 위해 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] (Test 용으로 생성된 데이터베이스를 삭제할 것인가? 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 (현재 설정한 값을 적용할 것인지? 당연히 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! [설정 완료]

    □ 3-3 MariaDB 접속

    [root@localhost ~]# mysql -u root -p
    Enter password: 패스워드 입력
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 18
    Server version: 10.4.13-MariaDB MariaDB Server

    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]> status [기본적인 상태 확인]
    --------------
    mysql  Ver 15.1 Distrib 10.4.13-MariaDB, for Linux (x86_64) using readline 5.1

    Connection id:          19
    Current database:
    Current user:           root@localhost
    SSL:                    Not in use
    Current pager:          stdout
    Using outfile:          ''
    Using delimiter:        ;
    Server:                 MariaDB
    Server version:         10.4.13-MariaDB MariaDB Server
    Protocol version:       10
    Connection:             Localhost via UNIX socket
    Server characterset:    latin1
    Db     characterset:    latin1
    Client characterset:    utf8
    Conn.  characterset:    utf8
    UNIX socket:            /var/lib/mysql/mysql.sock

    Uptime:                 23 min 38 sec

    Threads: 7  Questions: 26  Slow queries: 0  Opens: 20  Flush tables: 1  Open tables: 14  Queries per second avg: 0.018
    --------------

    참고

     MariaDB(Mysql) 환경설정을 관리하는 파일은 아래의 경로입니다.

    [root@localhost ~]# vi /etc/my.cnf

     

    my.cnf 파일 설정은 사용하려는 DB 환경에 맞게 튜닝을 해야 하지만 현재는 기본 세팅으로 갑니다.

    이 내용은 따로 포스팅하도록 하겠습니다.


    이상 위에 순서대로 웹 구축만 하여도 웹서버를 구동하는 데에는 크게 문제가 없습니다.
    만약 직접 웹홈페이지 개발을 한다면 충분히 연습할 수 있는 공간을 만들 수 있을 것으로 보입니다.
    APM 설치 포스팅이었습니다.

    댓글

    Designed by JB FACTORY