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

반응형
반응형

실습 환경

CentOS 7.8 - (IP : 192.168.56.102)
방화벽(iptables)  - OFF
SELINUX - Disabled

httpd 설치 확인

rpm 명령어로 Apache 패키지 설치 여부를 확인합니다.

현재 설치가 안된 상태입니다,

 

[root@linux-2 ~]# rpm -qa | grep http
[root@linux-2 ~]#

 

 

Apache 설치

yum 명령어로 아파치를 설치합니다.

-> yum [옵션] [명령어] [패키지명]

[root@linux-2 ~]# yum -y install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
base                                                                                          | 3.6 kB  00:00:00
docker-ce-stable                                                                              | 3.5 kB  00:00:00
extras                                                                                        | 2.9 kB  00:00:00
updates                                                                                       | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                     Arch                   Version                               Repository            Size
=====================================================================================================================
Installing:
 httpd                       x86_64                 2.4.6-93.el7.centos                   base                 2.7 M
Installing for dependencies:
 httpd-tools                 x86_64                 2.4.6-93.el7.centos                   base                  92 k

Transaction Summary
=====================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 2.8 M
Installed size: 9.5 M
Downloading packages:
(1/2): httpd-tools-2.4.6-93.el7.centos.x86_64.rpm                                             |  92 kB  00:00:00
(2/2): httpd-2.4.6-93.el7.centos.x86_64.rpm                                                   | 2.7 MB  00:00:00
---------------------------------------------------------------------------------------------------------------------
Total                                                                                5.8 MB/s | 2.8 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : httpd-tools-2.4.6-93.el7.centos.x86_64                                                            1/2
  Installing : httpd-2.4.6-93.el7.centos.x86_64                                                                  2/2
  Verifying  : httpd-tools-2.4.6-93.el7.centos.x86_64                                                            1/2
  Verifying  : httpd-2.4.6-93.el7.centos.x86_64                                                                  2/2

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

Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-93.el7.centos

Complete!

 

 

다시 rpm 명령어로 Apache 패키지 설치 여부를 확인합니다.

[root@linux-2 ~]# rpm -qa | grep httpd
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-2.4.6-93.el7.centos.x86_64

 

Apache 구동

[root@linux-2 ~]# systemctl start httpd
[root@linux-2 ~]#

 

 

Apache 구동 상태를 확인합니다.

[root@linux-2 ~]# 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 수 2020-05-27 16:36:43 KST; 15s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1696 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─1696 /usr/sbin/httpd -DFOREGROUND
           ├─1697 /usr/sbin/httpd -DFOREGROUND
           ├─1698 /usr/sbin/httpd -DFOREGROUND
           ├─1699 /usr/sbin/httpd -DFOREGROUND
           ├─1700 /usr/sbin/httpd -DFOREGROUND
           └─1701 /usr/sbin/httpd -DFOREGROUND

 5월 27 16:36:43 linux-2 systemd[1]: Starting The Apache HTTP Server...
 5월 27 16:36:43 linux-2 httpd[1696]: AH00558: httpd: Could not reliably determine the server's fully qualif...ssage
 5월 27 16:36:43 linux-2 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

 

 

Apache 부팅 시 자동 실행 설정

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

 

설정 내용 확인

이제 부팅시 매번 아파치를 구동해 줄 필요가 없습니다.

[root@linux-2 ~]# systemctl is-enabled httpd
enabled

 

80 포트 LISTEN 확인

[root@linux-2 ~]# netstat -lntup | grep http
[Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      941/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1287/master
tcp6       0      0 :::80                   :::*                    LISTEN      1696/httpd
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1287/master
udp        0      0 0.0.0.0:68              0.0.0.0:*                           705/dhclient
udp        0      0 0.0.0.0:68              0.0.0.0:*                           703/dhclient
udp        0      0 127.0.0.1:323           0.0.0.0:*                           565/chronyd
udp6       0      0 ::1:323                 :::*                                565/chronyd

 

웹서버 접근 확인

Apache 설치 시 기본 화면입니다.

 

Apache 기본 페이지 변경

다음은, Apache 기본 페이지를 한번 바꿔 보겠습니다.

우선, Apache 기본 설정 파일인 httpd.conf 파일의 위치로 이동을 합니다

 

[root@linux-2 conf]# pwd
/etc/httpd/conf
[root@linux-2 conf]# ls
httpd.conf  magic

 

vi로 열어서 "DocumentRoot" 부분을 찾습니다, 저는 119번째 줄에 있네요.

DocumentRoot는 웹서버의 문서(소스)가 있는 위치입니다. 해당 경로로 가보겠습니다.

[root@linux-2 conf]# vi httpd.conf
###
DocumentRoot "/var/www/html"

 

네. 아무 파일도 없네요

[root@linux-2 conf]# cd /var/www/html/
[root@linux-2 html]# ls
[root@linux-2 html]#

 

그럼 간단하게 "This is my first webserver" 내용의  index.html  파일을 하나 만들어보겠습니다.

[root@linux-2 html]# echo "This is my first webserver" > index.html
[root@linux-2 html]# ls
index.html

 

그리고, 다시 브라우저에서 웹서버에 접속해 보겠습니다.

네 바로 화면이 바뀐 것을 확인하실 수 있습니다

 

 

https://sh-safer.tistory.com/31

 

[Linux] Apache Virtualhost로 도메인 여러개 서비스하기

Virtual Host(가상 호스트)는 하나의 서버에서 여러 웹사이트를 서비스함을 의미합니다. 예를 들어, 서버에 a.tistory.com 웹서비스를 하고 있는데. 서비스가 완전히 다른 b.tistory.com 웹서버를 추가로 운

sh-safer.tistory.com

 

반응형

댓글

Designed by JB FACTORY

loading