본문 바로가기
Linux/서버구축 1.2.3...

(6) 워드프레스를 위한 리눅스 서버 구축 - 웹서버1 (설치와 기본설정)

by aegypius 2021. 4. 18.
728x90
반응형

APACHE 설치와 기본 설정


웹서버를 구축하기 위해서 apache를 설치할 것이다. nginx / apache 사이에서의 고민은 나중(?)에 하자.

redhat 계열의 리눅스에서는 rpm이나 yum으로 패키지를 관리한다. CentOS 8 부터는 dnf가 추가되었지만 CentOS Stream이 아직 검증되지 않았기에.... CentOS 7에서 다른 리눅스로 갈아탈지....CentOS Stream을 사용할 지는 2024년도 이후에 결정할 것이다.

아파치(apache)가 설치되었는지의 여부를 확인하자. rpm을 이용할 수 있고 yum을 이용할 수 있다.

[root@webpress /]# rpm -qa httpd*
package httpd* is not installed

----------------------------------------------

[root@webpress /]# yum list installed httpd*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * elrepo: ftp.ne.jp
 * extras: mirrors.cat.net
 * updates: ftp.yz.yamagata-u.ac.jp
Error: No matching Packages to list
[root@webpress /]#

 

  • apache의 설치
[root@webpress /]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cat.net
 * elrepo: ftp.ne.jp
 * extras: mirrors.cat.net
 * updates: ftp.yz.yamagata-u.ac.jp
base                                                                          | 3.6 kB  00:00:00
elrepo                                                                        | 3.0 kB  00:00:00
extras                                                                        | 2.9 kB  00:00:00
updates                                                                       | 2.9 kB  00:00:00
(1/2): elrepo/primary_db                                                      | 349 kB  00:00:00
(2/2): updates/7/x86_64/primary_db                                            | 7.1 MB  00:00:01
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
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-7.el7.x86_64.rpm                                             | 104 kB  00:00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                                        |  92 kB  00:00:00
(3/5): mailcap-2.1.41-2.el7.noarch.rpm                                        |  31 kB  00:00:00
(4/5): httpd-tools-2.4.6-97.el7.centos.x86_64.rpm                             |  93 kB  00:00:00
(5/5): httpd-2.4.6-97.el7.centos.x86_64.rpm                                   | 2.7 MB  00:00:01
-----------------------------------------------------------------------------------------------------
Total                                                                2.4 MB/s | 3.0 MB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-7.el7.x86_64                                                            1/5
  Installing : apr-util-1.5.2-6.el7.x86_64                                                       2/5
  Installing : httpd-tools-2.4.6-97.el7.centos.x86_64                                            3/5
  Installing : mailcap-2.1.41-2.el7.noarch                                                       4/5
  Installing : httpd-2.4.6-97.el7.centos.x86_64                                                  5/5
  Verifying  : httpd-2.4.6-97.el7.centos.x86_64                                                  1/5
  Verifying  : apr-1.4.8-7.el7.x86_64                                                            2/5
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                       3/5
  Verifying  : httpd-tools-2.4.6-97.el7.centos.x86_64                                            4/5
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                       5/5

Installed:
  httpd.x86_64 0:2.4.6-97.el7.centos

Dependency Installed:
  apr.x86_64 0:1.4.8-7.el7                               apr-util.x86_64 0:1.5.2-6.el7
  httpd-tools.x86_64 0:2.4.6-97.el7.centos               mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@webpress /]#

 

성공적으로 설치를 마쳤다면 httpd 데몬을 구동시켜서 현재의 상태를 확인해보자.

[root@webpress /]# systemctl start httpd
[root@webpress /]# 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 Sat 2021-04-17 12:29:38 KST; 3s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 4123 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
           ├─4123 /usr/sbin/httpd -DFOREGROUND
           ├─4124 /usr/sbin/httpd -DFOREGROUND
           ├─4125 /usr/sbin/httpd -DFOREGROUND
           ├─4126 /usr/sbin/httpd -DFOREGROUND
           ├─4127 /usr/sbin/httpd -DFOREGROUND
           └─4128 /usr/sbin/httpd -DFOREGROUND

Apr 17 12:29:38 webpress systemd[1]: Starting The Apache HTTP Server...
Apr 17 12:29:38 webpress httpd[4123]: AH00558: httpd: Could not reliably determine the server's f...sage
Apr 17 12:29:38 webpress systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@webpress /]# systemctl status httpd -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-04-17 12:29:38 KST; 19s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 4123 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─4123 /usr/sbin/httpd -DFOREGROUND
           ├─4124 /usr/sbin/httpd -DFOREGROUND
           ├─4125 /usr/sbin/httpd -DFOREGROUND
           ├─4126 /usr/sbin/httpd -DFOREGROUND
           ├─4127 /usr/sbin/httpd -DFOREGROUND
           └─4128 /usr/sbin/httpd -DFOREGROUND

Apr 17 12:29:38 webpress systemd[1]: Starting The Apache HTTP Server...
Apr 17 12:29:38 webpress httpd[4123]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5400:3ff:fe4d:4875. Set the 'ServerName' directive globally to suppress this message
Apr 17 12:29:38 webpress systemd[1]: Started The Apache HTTP Server.
[root@webpress /]#

밑에서 세 번째 줄에 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5400:3ff:fe4d:4875. Set the 'ServerName' directive globally to suppress this message 라는 메시지가 보인다. 서버의 도메인 이름을 설정하라는 것인데... 지금 수정해보자.

아파치의 설정파일은 /etc/httpd/conf/httpd.conf 이다. 편집기로 열어보자. (37행부터 97행 까지의 내용이다.)

     37 #
     38 # Change this to Listen on specific IP addresses as shown below to
     39 # prevent Apache from glomming onto all bound IP addresses.
     40 #
     41 #Listen 12.34.56.78:80
     42 Listen 80
     43
     44 #
     45 # Dynamic Shared Object (DSO) Support
     46 #
     47 # To be able to use the functionality of a module which was built as a DSO you
     48 # have to place corresponding `LoadModule' lines at this location so the
     49 # directives contained in it are actually available _before_ they are used.
     50 # Statically compiled modules (those listed by `httpd -l') do not need
     51 # to be loaded here.
     52 #
     53 # Example:
     54 # LoadModule foo_module modules/mod_foo.so
     55 #
     56 Include conf.modules.d/*.conf
     57
     58 #
     59 # If you wish httpd to run as a different user or group, you must run
     60 # httpd as root initially and it will switch.
     61 #
     62 # User/Group: The name (or #number) of the user/group to run httpd as.
     63 # It is usually good practice to create a dedicated user and group for
     64 # running httpd, as with most system services.
     65 #
     66 User apache
     67 Group apache
     68
     69 # 'Main' server configuration
     70 #
     71 # The directives in this section set up the values used by the 'main'
     72 # server, which responds to any requests that aren't handled by a
     73 # <VirtualHost> definition.  These values also provide defaults for
     74 # any <VirtualHost> containers you may define later in the file.
     75 #
     76 # All of these directives may appear inside <VirtualHost> containers,
     77 # in which case these default settings will be overridden for the
     78 # virtual host being defined.
     79 #
     80
     81 #
     82 # ServerAdmin: Your address, where problems with the server should be
     83 # e-mailed.  This address appears on some server-generated pages, such
     84 # as error documents.  e.g. admin@your-domain.com
     85 #
     86 ServerAdmin root@localhost
     87
     88 #
     89 # ServerName gives the name and port that the server uses to identify itself.
     90 # This can often be determined automatically, but we recommend you specify
     91 # it explicitly to prevent problems during startup.
     92 #
     93 # If your host doesn't have a registered DNS name, enter its IP address here.
     94 #
     95 #ServerName www.example.com:80
     96
     97 #

95행의 ServerName 구문의 주석을 해제하고 아래와 같이 서버에서 운영할 도메인 네임이나 ip 주소를 입력하자. (도메인 네임이나 ip주소에 포트번호를 추가할 필요는 없다.)

95 ServerName webpress.click
96 ServerName 123.123.123.123

운영할 도메인이 2개 이상이라면 ServerName 구문을 여러번 반복해도 상관없지만 대표도메인 하나만 등록해도 무방하며 도메인 네임 대신에 ip주소로 대체해도 된다.

위와 같이 수정했다면 다시 한 번 httpd의 상태를 확인해보자.

[root@webpress conf]# systemctl status httpd -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-04-17 13:02:11 KST; 2min 33s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 4256 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 4261 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─4261 /usr/sbin/httpd -DFOREGROUND
           ├─4262 /usr/sbin/httpd -DFOREGROUND
           ├─4263 /usr/sbin/httpd -DFOREGROUND
           ├─4264 /usr/sbin/httpd -DFOREGROUND
           ├─4265 /usr/sbin/httpd -DFOREGROUND
           └─4266 /usr/sbin/httpd -DFOREGROUND

Apr 17 13:02:11 webpress systemd[1]: Starting The Apache HTTP Server...
Apr 17 13:02:11 webpress systemd[1]: Started The Apache HTTP Server.
[root@webpress conf]#

오류메시지가 사라졌다. 오류라기보다는 일종의 안내 메시지이다.

네임서버(named)와 마찬가지로 시스템을 리부팅하더라도 웹서버가 활성화 되도록 아래의 명령을 실행하자.

[root@webpress conf]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@webpress conf]#

 

방화벽에서 웹서버를 허용하는 것도 잊지 말아야 한다.

[root@webpress conf]# firewall-cmd --permanent --zone=public --add-port=80/tcp
success
[root@webpress conf]# firewall-cmd --reload
success
[root@webpress conf]#

 

웹브라우저에 서버의 ip 주소를 넣었을 때 아래와 같은 모습을 볼 수 있다면 아파치 웹서버가 성공적으로 설치되어 작동하는 것이다.

 

이제 도메인에 대한 세부적인 네임서버의 설정과 각 도메인별 웹서버의 설정을 할 차례이다.


참고로 웹서버의 방화벽 허용은 아래와 같이 할 수도 있다.

# firewall-cmd --permanent --zone=public --add-service=http

service로 열어주나 직접 포트 80을 열어주나 결과는 같으므로 편한 것을 사용하자. 또한 보안서버를 설정할 계획이라면 https(포트 443)도 함께 열어두어야 한다. 이것도

# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --permanent --zone=public --add-port=443/tcp

둘 중 하나를 선택하면 될 것이다.

728x90
반응형

댓글