본문 바로가기

CentOS7에 아파치(Apache) 설치하는 방법

728x90
반응형

PHPs.KR에서 VPS(가상서버호스팅)을 받고 있다. 두 번째인데 첫번째는 기본세팅을 그대로 사용했었다. 그런데 APM(Apache + PHP + MySQL) 버전이 낮아 업그레이드 하려니 기존에 RPM으로 설치 된 프로그램들은 서버 초보자인 내가 하기엔 어려움이 있었다. 그리고 그동안 서버 설정한다고 이것저것 테스트 한다고 바꿔놓은 것들이 많아 서버가 지저분해졌다.

같은 사양의 VPS를 다시 신청하고 이번엔 APM 설치를 직접하기 위해 웹호스팅 회사에 APM 설치 신청을 하지 않았다.

서버 세팅이 끝났다는 메일이 왔다.
일단 아파치를 먼저 설치해 보기로 한다.

○ 서버에 아파치가 있는지 확인 한다.

#] which httpd
/usr/bin/which: no httpd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

어디에도 아파치가 설치 되지 않았다는 안내가 나온다.

○ yum을 이용해서 설치하기 위해 아파치 최신 버전을 확인 해 본다.

]# yum list | grep httpd

httpd.x86_64                                2.4.6-80.el7.centos.1      updates  
httpd-devel.x86_64                          2.4.6-80.el7.centos.1      updates  
httpd-manual.noarch                         2.4.6-80.el7.centos.1      updates  
httpd-tools.x86_64                          2.4.6-80.el7.centos.1      updates  
keycloak-httpd-client-install.noarch        0.6-3.el7                  base     
libmicrohttpd.i686                          0.9.33-2.el7               base     
libmicrohttpd.x86_64                        0.9.33-2.el7               base     
libmicrohttpd-devel.i686                    0.9.33-2.el7               base     
libmicrohttpd-devel.x86_64                  0.9.33-2.el7               base     
libmicrohttpd-doc.noarch                    0.9.33-2.el7               base     
python2-keycloak-httpd-client-install.noarch

아파치 버전이 2.4.6이라고 나온다.

○ 아파치를 설치한다.

]# yum install httpd

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.neowiz.com
 * extras: ftp.neowiz.com
 * updates: ftp.neowiz.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos.1 for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 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-80.el7.centos.1                    updates                    2.7 M
Installing for dependencies:
 httpd-tools                    x86_64                    2.4.6-80.el7.centos.1                    updates                     90 k
 mailcap                        noarch                    2.1.41-2.el7                             base                        31 k
Transaction Summary
========================================================================================Install  1 Package (+2 Dependent packages)

Total download size: 2.8 M
Installed size: 9.6 M
Is this ok [y/d/N]: y

y를 입력해 아파치 설치 파일을 다운로드하고 설치하는데 동의한다.

Downloading packages:
(1/3): mailcap-2.1.41-2.el7.noarch.rpm                                                                       |  31 kB  00:00:00     
(2/3): httpd-tools-2.4.6-80.el7.centos.1.x86_64.rpm                                                          |  90 kB  00:00:00     
(3/3): httpd-2.4.6-80.el7.centos.1.x86_64.rpm                                                                | 2.7 MB  00:00:00     
------------------------------------------------------------------------------------------------------------------
Total                                                                                               4.9 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-80.el7.centos.1.x86_64                                                                         1/3 
  Installing : mailcap-2.1.41-2.el7.noarch                                                                                      2/3 
  Installing : httpd-2.4.6-80.el7.centos.1.x86_64                                                                               3/3 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                                      1/3 
  Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                                                         2/3 
  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                                                                               3/3 
Installed:
  httpd.x86_64 0:2.4.6-80.el7.centos.1                                                                                              
Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-80.el7.centos.1                              mailcap.noarch 0:2.1.41-2.el7                             
Complete!

설치가 끝났다.

○ 아파치 버전 확인

]# httpd -v

Server version: Apache/2.4.6 (CentOS)
Server built:   Jun 27 2018 13:48:59

○ 아파치를 실행해 본다.

]# service httpd start
Redirecting to /bin/systemctl start httpd.service

○ 아파치 실행 상태 확인

]# service httpd status

Redirecting to /bin/systemctl status httpd.service
? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 紐?2018-11-22 19:03:43 KST; 10min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 3298 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ?쒋?3298 /usr/sbin/httpd -DFOREGROUND
           ?쒋?3299 /usr/sbin/httpd -DFOREGROUND
           ?쒋?3300 /usr/sbin/httpd -DFOREGROUND
           ?쒋?3301 /usr/sbin/httpd -DFOREGROUND
           ?쒋?3302 /usr/sbin/httpd -DFOREGROUND
           ?붴?3303 /usr/sbin/httpd -DFOREGROUND

11??22 19:03:43 wonjustory.vps.phps.kr systemd[1]: Starting The Apache HTTP Server...
11??22 19:03:43 wonjustory.vps.phps.kr systemd[1]: Started The Apache HTTP Server.

# systemctl status httpd도 같은 역할을 한다.

systemctl stats 데몬이름

이 명령은 실행 오류를 찾아낼 때 유용하다. 만약 httpd, vsftp, mysql 등 데몬을 실행했는데 별다른 문구 없이 실행이 되지 않을 때 이 명령을 이용하면 왜 오류가 나왔지, 설정 파일 몇 번 라인에서 오류가 났는지 확인 할 수 있다.

○ 리부팅 할 때 아파치를 자동으로 실행되도록 시스템 설정을 한다.

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

○ 시스템 설정이 제대로 적용 됐는지 확인 해 본다.

]# systemctl list-unit-files --type=service | grep httpd
httpd.service                                 enabled 
enabled면 정상적으로 적용 되고 있다는 의미다.
localhost로 서버가 제대로 작동하는지 웹브라우저로 확인 할 수 있다. 만약 가상서버호스팅을 받은 것이면 httpd 설정이 조금 더 필요하다.

여기까지 확인 됐으면 아파치는 정상적으로 설치 된 것이다.

○ 이제 방화벽을 열어줘야 한다.
[root@wonjustory etc]# firewall-cmd --permanent --add-service=http
success

http는 80번 포트를 사용한다. 80번 포트를 열어 웹페이지 접근이 가능해졌다.

]# firewall-cmd --permanent --add-service=https
success

https는 443번 보안 포트를 사용한다. 443번 포트를 열어 준 것이다.

]# firewall-cmd --reload
success

방화벽 설정을 다시 로드한다. 이제 웹서버 사용이 가능해 졌다. 추가적으로 Python이나 PHP, MySQL 등 추가 설치가 필요하다.

리눅스 웹서버 CentOS, PHP5.3에 Zend Guard Loader 설치하기  https://zibsin.tistory.com/2482리눅스 서버 CentOS에 PHP5.x 설치하기  https://zibsin.tistory.com/2480
리눅스 서버에 APM 설치 https://zibsin.tistory.com/2481

 

728x90
반응형