CentOS6.9 Apache 소스 설치

ETC

(Update : 2018-04-12)

Language :

APACHE

01-1. 기존 설치 확인 (YUM)

# yum list httpd
Loaded plugins: fastestmirror
base
base/primary_db			: 3.7 kB	00:00
extras				: 4.7 MB	00:00
extras/primary_db		:  30 kB	00:00
updates				: 3.4 kB	00:00
updates/primary_db		: 7.0MB	00:56
Available Packages
httpd.x86_64	2.2.15-60.el6.centos.6	updates
# yum list apache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Error: No matching Packages to list

01-2. 기존 설치 확인 (RPM)

# rpm -qa | grep apache
# rpm -qa | grep httpd

02. Apache 패키지의 의존성 파일 설치

# yum install -y make wget gcc g++ gcc-c++ autoconf automake libtool pkgconfig findutils openssl openssl-devel openldap-devel pcre-devel libxml2-devel lua-devel curl curl-devel libcurl-devel expat-devel flex zlib-devel

Complete!

  • yum install [package name]
  • make : 파일 관리 유틸리티
  • wget : 네트워크에서 데이터를 다운로드한다.

03. Apache 패키지 다운로드

Apache https://httpd.apache.org/download.cgi 

APR : http://mirror.23media.de/apache/apr/

PCRE 모듈 : https://ftp.pcre.org/pub/pcre/

# cd /usr/local/src					                  // 파일 저장할 경로
src]# wget http://apache.tt.co.kr//httpd/httpd-2.4.29.tar.gz		  // Apache
src]# wget http://mirror.23media.de/apache/apr/apr-1.6.2.tar.gz	          // APR 모듈
src]# wget http://mirror.23media.de/apache/apr/apr-util-1.6.0.tar.gz      // APR-util 모듈
src]# wget http://mirror.23media.de/apache/apr/apr-iconv-1.2.1.tar.gz     // APR-iconv
src]# wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz	          // PCRE 모듈

04. 설치 (cd /usr/local/src에서 진행)

  • APR(Apache Portable Runtime) 모듈
src]# tar xzf apr-1.6.2.tar.gz						// 압축 해제
src]# cd apr-1.6.2
apr-1.6.2]# ./configure --prefix /usr/local/apr-1.6.2
apr-1.6.2]# make && make install

config.status: executing default commands                                                                   // configure 완료

make[1]: Leaving directory '/usr/local/src/apr-1.6.2'                                                    // make 완료

/usr/bin/install -c -m 755 apr-config.out /usr/local/apr-1.6.2/bin/apr-1-config        // make install 완료

- ./configure 완료후 마지막 문장 위에 다음 문구가 있을 경우

rm: cannot remove 'libtoolT': No such file or directory
⇒ # cp -arp libtool libtoolT 해준 후 다시 configure
  • APR-util 모듈
src]# tar xzf apr-util-1.6.0.tar.gz
src]# cd apr-util-1.6.0
apr-util-1.6.0]# ./configure --prefix /usr/local/apr-util-1.6.0 --with-apr=/usr/local/apr-1.6.2
apr-util-1.6.0]# make && make install

config.status: executing default commands                                                                                // configure

make[1]: Leaving directory ‘/usr/local/src/apr-uril-1.6.1                                                            // make

/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util-1.6.0/bin/apu-1-config             // make install

  • APR-iconv
src]# tar xzf apr-iconv-1.2.1.tar.gz
src]# cd apr-iconv-1.2.1
apr-iconv-1.2.1]# ./configure --prefix /usr/local/apr-iconv-1.2.1 --with-apr=/usr/local/apr-1.6.2
apr-iconv-1.2.1]# make && make install

config.status: creating lib/apr_iconv_private.h                                                                     // configure

make[2]: Leaving directory ‘/usr/local/src/apr-iconv-1.2.1/util

make[1]: Leaving directory ‘/usr/local/src/apr-iconv-1.2.1/util                                          // make

libtool: install: cp .libs/apriconv /usr/local/apr-iconv-1.2.1/bin/apriconv                        // make install

  • PCRE(Perl Compatible Regular Expressions) 모듈
src]# tar xzf pcre-8.41.tar.gz
src]# cd pcre-8.41
pcre-8.41]# ./configure --prefix=/usr/local/pcre-8.41
pcre-8.41]# make && make install

Code coverage ……………………… : no                                                                                            //configure

make[1]: Leaving directory ‘/usr/local/src/pcre-8.41’                                                               // make

make[3]: Leaving directory ‘/usr/local/src/pcre-8.41’

make[2]: Leaving directory ‘/usr/local/src/pcre-8.41’

make[1]: Leaving directory ‘/usr/local/src/pcre-8.41’                                                              // make install

  • Apache httpd (아파치 웹서버)
src]# tar xzf httpd-2.4.29.tar.gz
src]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
src]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
src]# cd httpd-2.4.29
httpd-2.4.29]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr-1.6.2 --with-apr-util=/usr/local/apr-util-1.6.0 --with-pcre=/usr/local/pcre-8.41 --enable-mods-shared=all --enable-so --enable-rewrite --enable-auth-digest
httpd-2.4.29]# make && make install

config.status: executing default commands

configure: summary of build options:

    Server Version: 2.4.29

    Install prefix: /usr/local/apache

    C compiler:gcc -std=gnu99

    CFLAGS:-g -02 -pthread                                                                                        // 옵션 지정에 따라 추가됨

    CPPFLAGS:-DLINUX -D_REENTRANT -D_GNU_SOURCE

    LDFLAGS:

    LIBS:

    C preprocessor:gcc -E                                                                                                                    // configure

make[4]: Leaving directory ‘/usr/local/src/httpd-2.4.29/modules/mappers’

make[3]: Leaving directory ‘/usr/local/src/httpd-2.4.29/modules/mappers’

make[2]: Leaving directory ‘/usr/local/src/httpd-2.4.29/modules’

make[2]: Entering directory ‘/usr/local/src/httpd-2.4.29/support’

make[2]: Leaving directory ‘/usr/local/src/httpd-2.4.29/support’

make[1]: Leaving directory ‘/usr/local/src/httpd-2.4.29’                                                             // make 

make[1]: Leaving directory ‘/usr/local/src/httpd-2.4.29                                                             // make install

[Error]

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
⇒ # yum install pcre-devel
checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
⇒ # yum -y install zlib-devel
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures ⇒ # yum install openssl-devel

05. httpd.conf 수정

httpd-2.4.29]# vi /usr/local/apache/conf/httpd.conf
(...)
;ServerName localhost
(...)
httpd-2.4.29]# ps -ef | grep httpd					   // Apache 확인
root	5698	1231	0	21:36	tty1	00:00:00 grep httpd	   // Apache 작동 안함
httpd-2.4.29]# /usr/local/apache/bin/apachectl start			   // Apache 실행
httpd-2.4.29]# ps -ef | grep httpd
root	5702	1	0	21:28	?	00:00:00 /usr/local/apache/bin/httpd -k start
daemon	5703	5702	0	21:28	?	00:00:00 /usr/local/apache/bin/httpd -k start
daemon	5704	5702	0	21:28	?	00:00:00 /usr/local/apache/bin/httpd -k start
daemon	5705	5702	0	21:28	?	00:00:00 /usr/local/apache/bin/httpd -k start
root	5788	1231	0	21:28	tty1	00:00:00 grep httpd

06. iptables 설정 (방화벽 설정) - 사용할 포트 추가

src]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
(...)
-A INPUT -m state --state NEW -m tcp -p -tcp --dport 20 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p -tcp --dport 80 -j ACCEPT 
src]# service iptables restart							// 방화벽 재시작
iptables: Setting chains to policy ACCEPT: filter				[ OK ]
iptables: Flushing firewall rules:						[ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

07. 아파치 웹서버를 서비스에 등록 및 수정

서비스 스크립트를 /etc/init.d/ 위치에 httpd라는 이름으로 복사하여 사용 가능하도록 처리한다.

src]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd 
src]# vi /etc/init.d/httpd		
#!/bin/sh
# chkconfig: 2345 90 90
# description: init file for Apache server daemon
# processname: /usr/local/apache/bin/apachectl	
# config: /usr/local/apache/conf/httpd.conf
# pidfile: /usr/local/apache/logs/httpd.pid
# chkconfig --add httpd
  • cp : 복사. [복사파일] [붙여넣을위치/이름]
  • description의 daemon : httpd.conf의 User, Group
  • processname : apachectl 원본 위치
  • chkconfig --add [service name] : 서비스 등록

08. 서비스 정상 등재 확인

# chkconfig --list | grep httpd
httpd	0:off	1:off	2:on	3:on	4:on	5:on	6:off

09. 실행

  • 서비스를 통해 아파치 웹서버 실행
# service httpd start
  • 실행2
# /etc/init.d/httpd start

10. 80포트 Listen 확인

# netstat -lnpt | grep httpd
tcp	0	0	:::80	:::*	LISTEN	5702/httpd
  • netstat : 네트워크 접속, 라우팅 테이블, 네트워크 인터페이스의 통계 정보를 보여주는 도구

11. 리눅스 시작 시 httpd 서비스 자동실행

# chkconfig httpd on

민갤

Back-End Developer

백엔드 개발자입니다.