본문으로 바로가기

[Linux] CentOS7 Apache 설치 (아파치 웹 서버)

category OS/Linux 2021. 8. 11. 15:10

목차

    0. APM 설치 전 확인

    0.1. 설치 환경

    - 필자의 설치 환경은 다음과 같습니다.

    CentOS 버전
    # cat /etc/redhat-release
    CentOS Linux release 7.9.2009 (Core)
    
    커널버전
    # cat /proc/version
    Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

    0.2. 필수 패키지 다운로드

    - Yum을 이용해 Apache 설치에 필요한 여러 필수 패키지를 다운로드합니다.

    # yum install libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel pcre-devel acc make
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================
     Package                                                 Arch                                      Version                                                   Repository                                  Size
    ==============================================================================================================================================================================================================
    Installing:
     freetype-demos                                          x86_64                                    2.8-14.el7_9.1                                            updates                                    188 k
     freetype-devel                                          x86_64                                    2.8-14.el7_9.1                                            updates                                    447 k
     gcc-c++                                                 x86_64                                    4.8.5-44.el7                                              base                                       7.2 M
     gd-devel                                                x86_64                                    2.0.35-27.el7_9                                           updates                                     79 k
     gd-progs                                                x86_64                                    2.0.35-27.el7_9                                           updates                                     37 k
     gdbm-devel                                              x86_64                                    1.10-8.el7                                                base                                        47 k
     libjpeg-turbo-devel                                     x86_64                                    1.2.90-8.el7                                              base                                        99 k
     libjpeg-turbo-static                                    x86_64                                    1.2.90-8.el7                                              base                                       120 k
     libjpeg-turbo-utils                                     x86_64                                    1.2.90-8.el7                                              base                                        77 k
     libpng-devel                                            x86_64                                    2:1.5.13-8.el7                                            base                                       122 k
     libpng-static                                           x86_64                                    2:1.5.13-8.el7                                            base                                        92 k
     libpng12                                                x86_64                                    1.2.50-10.el7                                             base                                       171 k
     libpng12-devel                                          x86_64                                    1.2.50-10.el7                                             base                                       111 k
     ncurses-devel                                           x86_64                                    5.9-14.20130511.el7_4                                     base                                       712 k
    Updating:
     freetype                                                x86_64                                    2.8-14.el7_9.1                                            updates                                    380 k
     gd                                                      x86_64                                    2.0.35-27.el7_9                                           updates                                    146 k
    Installing for dependencies:
     expat-devel                                             x86_64                                    2.1.0-12.el7                                              base                                        57 k
     fontconfig-devel                                        x86_64                                    2.13.0-4.3.el7                                            base                                       138 k
     libXpm-devel                                            x86_64                                    3.5.12-1.el7                                              base                                        36 k
     libstdc++-devel                                         x86_64                                    4.8.5-44.el7                                              base                                       1.5 M
     libuuid-devel                                           x86_64                                    2.23.2-65.el7_9.1                                         updates                                     93 k
    Updating for dependencies:
     libblkid                                                x86_64                                    2.23.2-65.el7_9.1                                         updates                                    183 k
     libmount                                                x86_64                                    2.23.2-65.el7_9.1                                         updates                                    185 k
     libsmartcols                                            x86_64                                    2.23.2-65.el7_9.1                                         updates                                    143 k
     libuuid                                                 x86_64                                    2.23.2-65.el7_9.1                                         updates                                     84 k
     util-linux                                              x86_64                                    2.23.2-65.el7_9.1                                         updates                                    2.0 M
    
    Transaction Summary
    ==============================================================================================================================================================================================================
    Install  14 Packages (+5 Dependent packages)
    Upgrade   2 Packages (+5 Dependent packages)
    
    Total size: 14 M
    Total download size: 11 M
    Is this ok [y/d/N]: y
    
    ...
    
    Installed:
      freetype-demos.x86_64 0:2.8-14.el7_9.1 freetype-devel.x86_64 0:2.8-14.el7_9.1    gcc-c++.x86_64 0:4.8.5-44.el7              gd-devel.x86_64 0:2.0.35-27.el7_9            gd-progs.x86_64 0:2.0.35-27.el7_9
      gdbm-devel.x86_64 0:1.10-8.el7         libjpeg-turbo-devel.x86_64 0:1.2.90-8.el7 libjpeg-turbo-static.x86_64 0:1.2.90-8.el7 libjpeg-turbo-utils.x86_64 0:1.2.90-8.el7    libpng-devel.x86_64 2:1.5.13-8.el7
      libpng-static.x86_64 2:1.5.13-8.el7    libpng12.x86_64 0:1.2.50-10.el7           libpng12-devel.x86_64 0:1.2.50-10.el7      ncurses-devel.x86_64 0:5.9-14.20130511.el7_4
    
    Dependency Installed:
      expat-devel.x86_64 0:2.1.0-12.el7    fontconfig-devel.x86_64 0:2.13.0-4.3.el7    libXpm-devel.x86_64 0:3.5.12-1.el7    libstdc++-devel.x86_64 0:4.8.5-44.el7    libuuid-devel.x86_64 0:2.23.2-65.el7_9.1
    
    Updated:
      freetype.x86_64 0:2.8-14.el7_9.1                                                                         gd.x86_64 0:2.0.35-27.el7_9
    
    Dependency Updated:
      libblkid.x86_64 0:2.23.2-65.el7_9.1     libmount.x86_64 0:2.23.2-65.el7_9.1     libsmartcols.x86_64 0:2.23.2-65.el7_9.1     libuuid.x86_64 0:2.23.2-65.el7_9.1     util-linux.x86_64 0:2.23.2-65.el7_9.1
    
    Complete!

     


    1. Apache 설치

    1.1. Apache 설치

    - Yum을 이용하거나 또는 원하는 특정 버전이 있을 경우 rpm파일을 이용해 다운로드해 줍니다.

       (컴파일 설치는 이 게시물에 설명하지 않았습니다.)

    1.1.1. Yum을 이용한 설치

    - 특정한 버전이 필요하지 않은 경우엔 다음 명령어를 이용해 편하게 설치할 수 있습니다.

      (Apache 설치 시에 필요한 apr, apr-util, pcre 등 종속 패키지가 알아서 같이 설치됩니다.)

    # yum install httpd
    
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: ftp.kaist.ac.kr
     * extras: ftp.kaist.ac.kr
     * updates: mirror.navercorp.com
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-97.el7.centos will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-97.el7.centos for package: httpd-2.4.6-97.el7.centos.x86_64
    --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-97.el7.centos.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-97.el7.centos will be installed
    ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================
     Package                                           Arch                                         Version                                                   Repository                                     Size
    ==============================================================================================================================================================================================================
    Installing:
     httpd                                             x86_64                                       2.4.6-97.el7.centos                                       updates                                       2.7 M
    Installing for dependencies:
     apr                                               x86_64                                       1.4.8-7.el7                                               base                                          104 k
     apr-util                                          x86_64                                       1.5.2-6.el7                                               base                                           92 k
     httpd-tools                                       x86_64                                       2.4.6-97.el7.centos                                       updates                                        93 k
     mailcap                                           noarch                                       2.1.41-2.el7                                              base                                           31 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================
    Install  1 Package (+4 Dependent packages)
    
    Total download size: 3.0 M
    Installed size: 10 M

    1.1.2. rpm을 이용한 설치

    - Apache 특정 버전이 필요한 경우 원하는 해당 버전의 rpm파일을 다운로드하여서 설치할 수 도 있습니다. 

    (이 또한 자동으로 알아서 종속 패키지를 설치해 줍니다.)

    # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/httpd-2.4.6-95.el7.centos.x86_64.rpm
    --2021-07-26 16:11:12--  http://mirror.centos.org/centos/7/os/x86_64/Packages/httpd-2.4.6-95.el7.centos.x86_64.rpm
    Resolving mirror.centos.org (mirror.centos.org)... 13.233.140.107, 2406:da14:d02:6501:83d:3d3c:fc36:b359
    Connecting to mirror.centos.org (mirror.centos.org)|13.233.140.107|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2846172 (2.7M) [application/x-rpm]
    Saving to: ‘httpd-2.4.6-95.el7.centos.x86_64.rpm’
    
    100%[====================================================================================================================================================================>] 2,846,172   2.21MB/s   in 1.2s
    
    2021-07-26 16:11:14 (2.21 MB/s) - ‘httpd-2.4.6-95.el7.centos.x86_64.rpm’ saved [2846172/2846172]
    
    # ls
    httpd-2.4.6-95.el7.centos.x86_64.rpm
    
    # yum localinstall httpd-2.4.6-95.el7.centos.x86_64.rpm
    
    Loaded plugins: fastestmirror, langpacks
    Examining httpd-2.4.6-95.el7.centos.x86_64.rpm: httpd-2.4.6-95.el7.centos.x86_64
    Marking httpd-2.4.6-95.el7.centos.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-95.el7.centos will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-95.el7.centos for package: httpd-2.4.6-95.el7.centos.x86_64
    Loading mirror speeds from cached hostfile
     * base: ftp.kaist.ac.kr
     * extras: ftp.kaist.ac.kr
     * updates: mirror.navercorp.com
    --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-95.el7.centos.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-95.el7.centos.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-95.el7.centos.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-95.el7.centos will be installed
    ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================================================================================
     Package                                    Arch                                  Version                                              Repository                                                        Size
    ==============================================================================================================================================================================================================
    Installing:
     httpd                                      x86_64                                2.4.6-95.el7.centos                                  /httpd-2.4.6-95.el7.centos.x86_64                                9.4 M
    Installing for dependencies:
     apr                                        x86_64                                1.4.8-7.el7                                          base                                                             104 k
     apr-util                                   x86_64                                1.5.2-6.el7                                          base                                                              92 k
     httpd-tools                                x86_64                                2.4.6-95.el7.centos                                  base                                                              93 k
     mailcap                                    noarch                                2.1.41-2.el7                                         base                                                              31 k
    
    Transaction Summary
    ==============================================================================================================================================================================================================
    Install  1 Package (+4 Dependent packages)
    
    Total size: 9.7 M
    Total download size: 319 k
    Installed size: 10 M

    1.2. Apache 설치 확인

    - 설치가 잘 완료된 경우 버전 정보가 출력됩니다.

    # httpd -v
    Server version: Apache/2.4.6 (CentOS)
    Server built:   Oct  1 2020 16:52:05

    1.3. Apache 실행(명령어)

    - 아래의 명령어를 이용해 실행, 종료, 상태 확인 등을 할 수 있습니다.

    아파치 실행
    # systemctl start httpd
    
    아파치 상태 확인
    # systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: active (running) since 월 2021-07-26 16:17:00 KST; 4s ago
         Docs: man:httpd(8)
               man:apachectl(8)
     Main PID: 25111 (httpd)
       Status: "Processing requests..."
        Tasks: 6
       CGroup: /system.slice/httpd.service
               ├─25111 /usr/sbin/httpd -DFOREGROUND
               ├─25114 /usr/sbin/httpd -DFOREGROUND
               ├─25115 /usr/sbin/httpd -DFOREGROUND
               ├─25116 /usr/sbin/httpd -DFOREGROUND
               ├─25117 /usr/sbin/httpd -DFOREGROUND
               └─25118 /usr/sbin/httpd -DFOREGROUND
    
     7월 26 16:17:00 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
     7월 26 16:17:00 localhost.localdomain httpd[25111]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName'... this message
     7월 26 16:17:00 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    
    아파치 종료
    # systemctl stop httpd
    
    # systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:httpd(8)
               man:apachectl(8)
    
     7월 26 16:17:00 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
     7월 26 16:17:00 localhost.localdomain httpd[25111]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName'... this message
     7월 26 16:17:00 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
     7월 26 16:18:11 localhost.localdomain systemd[1]: Stopping The Apache HTTP Server...
     7월 26 16:18:12 localhost.localdomain systemd[1]: Stopped The Apache HTTP Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    
    아파치 부팅 시 자동실행 등록
    # systemctl enable httpd
    Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
    
    아파치 부팅 시 자동실행 해제
    # systemctl disable httpd
    Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.

    1.4. 방화벽 설정(80 port)

    - Apache 웹 서버의 외부 접근을 위해 기본 포트인 80 포트의 방화벽을 열어 줍니다.

      (로컬 환경에서만 접근하고 싶을 경우 방화벽을 설정하지 않아도 됩니다.)

    80포트 오픈
    # firewall-cmd --zone=public --permanent --add-port=80/tcp
    success
    
    방화벽 적용
    # firewall-cmd --reload
    success
    
    적용된 방화벽 포트 리스트 확인
    # firewall-cmd --zone=public --list-all
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: enp0s3
      sources:
      services: dhcpv6-client ssh
      ports: 80/tcp
      protocols:
      masquerade: no
      forward-ports:
      source-ports:
      icmp-blocks:
      rich rules:

    1.5. 실행 확인

    - 리눅스의 로컬 GUI 환경에서 브라우저 주소창에 localhost 또는 127.0.0.1로 접속하거나 해당 리눅스 서버의 ip로 접속하면 다음과 같은 화면이 나타납니다.

    Apache 초기화면