Apache 2.4.x 소스 설치

Jeongkuk Seo
sjk5766
Published in
9 min readJan 1, 2019

--

소스 설치와 패키지 설치 나름의 장,단점이 있지만 이미 옛날부터 회사에서 소스 설치로 Apache를 꾸려왔었기 때문에.. 저도 소스설치부터 시작해서 정리하게 되었습니다. 최종적으로 PHP도 같이 연동해야 하지만 이 포스팅에 정리하기엔 양이 많아 Apache 설치 및 구동, OpenSSL 과 같이 설치 이 두 가지에 대해 정리하겠습니다. 설치에 사용한 Apache 버전은 2.4.37 이며 OS는 CentOS 6 bin-DVD로 설치했습니다. (minimal 버전이 아닙니다.)

1. Apache 소스 설치 및 구동

우선 설치 할 apache 소스는 wget 명령어 또는 winscp로 CentOS로 옮깁니다. tar -zxvf httpd-2.4.37.tar.gz로 압축을 풀면 아래와 같이 폴더가 생깁니다.

httpd-2.4.37

apache 설치에는 apr과 apr-util 모듈이 필요합니다. 아래와 같이 모듈을 다운받습니다.

wget http://apache.tt.co.kr/apr/apr-1.6.5.tar.gz
wget http://apache.tt.co.kr/apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-1.6.5.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz

압축 풀린 apr과 apr-util을 httpd-2.4.37/srclib/ 하위로 옮겨야 합니다. 이 때, 파일 이름 그대로 옮기면 안되고 apr과 apr-util로 이름을 변경해야 합니다.

mv apr-1.6.5 apr
mv apr-util-1.6.1 apr-util
mv apr httpd-2.4.37/srclib/
mv apr-util httpd-2.4.37/srclib/

apache 설치에는 pcre와 zlib가 필요합니다. pcre 설치 과정에서 g++ 이 없으면 에러가 발생하므로 설치 후 pcre를 다운받아 설치 작업을 진행합니다.

yum install -y gcc-c++    // g++ 설치
yum install -y zlib-devel // zlib 설치
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42
./configure
make && make install

현 상태에서 configure 입력 후 make 작업을 하면 아래와 같이 에러가 발생합니다.

xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’

이런 에러를 보지 않으려면 아래와 같이 expat-devel을 설치합니다.

yum install -y expat-devel

이제 configure 명령을 입력합니다. 제 경우는 이미 설치된 apache 옵션이 아래와 같은 형태라서 그대로 따라했습니다.

cd ../httpd-2.4.37
./configure --prefix=/home1/apache --enable-module=so --enable-mods-shared=all --enable-so --enable-deflate --enable-rewrite --with-included-apr
make && make install

위 과정에 에러가 없다면 apache 설치 경로는 prefix 경로인 /home1/apache입니다. 이동해서 확인해 보겠습니다.

[root@localhost apache]# ll
total 60
drwxr-xr-x. 2 root root 4096 Jan 1 16:45 bin
drwxr-xr-x. 2 root root 4096 Jan 1 16:46 build
drwxr-xr-x. 2 root root 4096 Jan 1 16:45 cgi-bin
drwxr-xr-x. 4 root root 4096 Jan 1 17:02 conf
drwxr-xr-x. 3 root root 4096 Jan 1 16:45 error
drwxr-sr-x. 2 root root 4096 Oct 18 07:33 htdocs
drwxr-xr-x. 3 root root 4096 Jan 1 16:45 icons
drwxr-xr-x. 2 root root 4096 Jan 1 16:45 include
drwxr-xr-x. 3 root root 4096 Jan 1 16:45 lib
drwxr-xr-x. 2 root root 4096 Jan 1 17:03 logs
drwxr-xr-x. 4 root root 4096 Jan 1 16:46 man
drwxr-sr-x. 14 root root 12288 Oct 18 07:34 manual
drwxr-xr-x. 2 root root 4096 Jan 1 16:45 modules

bin 폴더로 들어가면 apachectl 바이너리가 있는데, 이를 통해 apache를 실행할 경우 아래 에러가 발생합니다.

[root@localhost conf]# /home1/apache/bin/apachectl start
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message

http.conf에서 ServerName을 찾아 주석을 해제합니다.

#ServerName www.example.com:80  // 변경전
ServerName www.example.com:80 // 변경후

최종적으로 실행하기 전에 iptables 서비스를 해제하고 실행합니다.

[root@localhost conf]# service iptables stop
[root@localhost conf]# /home1/apache/bin/apachectl start

CentOS IP로 웹에 접속하면 확인할 수 있습니다.

2. OpenSSL 설정하기

Apache 설치 시, 보안을 위해 https 프로토콜로 접근할 수 있게 하겠습니다. 우선 위에 정리한 1번에서 configure 명령을 입력하기 전 단계, expat-devel 설치까지는 동일하게 작업하고 configure 옵션부터 달라집니다.

[root@localhost httpd-2.4.37]# ./configure --prefix=/home1/apache2 --enable-module=so --enable-mods-shared=all --enable-so --enable-deflate --enable-rewrite --with-included-apr --enable-module=ssl  --enable-ssl=shared --with-ssl --enable-ssl
[root@localhost httpd-2.4.37]# make && make install

위에서 굵게 표시한 부분이 ssl 설정을 위해 추가한 부분입니다. 이렇게 설치 할 경우 기본적으로 OS에 설치 된 openssl 을 이용합니다. prefix 옵션으로 준 경로로 이동하면 apache ssl 설정에 필요한 라이브러리를 확인할 수 있습니다.

[root@localhost modules]# ll | grep ssl
-rwxr-xr-x. 1 root root 905021 Jan 1 17:00 mod_ssl.so

반대로 위에서 ssl 설정을 주지 않은 /home1/apache 경로에선 이 모듈이 없습니다.

[root@localhost modules]# cd /home1/apache/modules/
[root@localhost modules]# ll | grep ssl
[root@localhost modules]#

ssl 설정을 준 /home1/apache2/conf 경로로 이동하여 httpd.conf를 수정합니다.

ServerName www.example.com:80  // 주석을 해제한다.
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so // 주석해제
LoadModule ssl_module modules/mod_ssl.so // 주석해제
Include conf/extra/httpd-ssl.conf // 주석해제

SSL에 필요한 인증서를 생성해야 합니다. 제 경우 회사에서 인증서를 생성하는 스크립트가 있어 그걸 그대로 사용했습니다. 해당 부분은 검색해보면 많이 나오므로 다른 사이트를 참조하시길 바랍니다. 이제 동일하게 실행한 다음에 IP에 https로 접속해보겠습니다.

/home1/apache2/bin/apachectl start

OS의 OpenSSL 버전으로 설치되었는지 비교해 보겠습니다.

[root@localhost conf]# openssl
OpenSSL> version
OpenSSL 1.0.1e-fips 11 Feb 2013 // OS 버전
[root@localhost conf]# curl --head localhost
HTTP/1.1 200 OK
Date: Wed, 02 Jan 2019 02:15:51 GMT
Server: Apache/2.4.37 (Unix) OpenSSL/1.0.1e-fips // Apache OpenSSL
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html

더 보면 좋은 것

위에서 예시로 선택한 OpenSSL 버전이 1.0.1로 낮습니다. 따라서 보안 취약점을 강화하기 위해 OpenSSL 높은 버전으로 업그레이드 하는 방법에 대해선 아래 포스팅을 참조하세요.

PHP와 연동하는 포스팅은 아래를 참조합니다.

--

--