Apache 웹 서버를 쉽게 설치하기 위해 일반적으로 yum install 명령을 사용합니다. 하지만 이 튜토리얼에서는 CentOS 7 환경에서 소스 코드를 컴파일하여 Apache를 설치합니다.
필요사항
- APR and APR-Util
- Perl-Compatible Regular Expressions Library (PCRE)
- Disk Space
- ANSI-C Compiler and Build System
- Accurate time keeping
- Perl 5 [OPTIONAL]
아파치 설치
# 아파치 설치 및 컴파일에 필요한 도구 설치
$ sudo yum update -y
$ sudo yum install -y wget gcc gcc-c++ expat-devel pcre-devel openssl-devel
# 소스코드 다운로드
# switch to home dir
$ cd ~
$ wget https://archive.apache.org/dist/httpd/httpd-2.4.49.tar.gz
$ wget https://dlcdn.apache.org//apr/apr-1.6.5.tar.gz
$ wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
# 다운로드한 소스들 압축해재
$ tar zxvf httpd-2.4.49.tar.gz
$ tar zxvf apr-1.6.5.tar.gz
$ tar zxvf apr-util-1.6.3.tar.gz
# Apache에서는 컴파일을 위해 APR 라이브러리가 필요합니다. 올바른 디렉토리에 소스 코드를 복사합니다.
# APR 디렉토리에 버전 번호를 포함하지 않는 것이 중요합니다.
# 이름을 변경하지 않고 apr-1.6.5 만 복사하면 apr 디렉토리 누락에 대한 경고가 나타납니다.
$ cp -r apr-1.6.5 httpd-2.4.49/srclib/apr
$ cp -r apr-util-1.6.1 httpd-2.4.49/srclib/apr-util
HTTPD 디렉터리 아래에 있는 srclib 디렉터리 내에 apr 및 apr-util 디렉터리를 배치해야 하며 이름은 apr 및 apr-util에 있어야 합니다.
# apache 컴파일(root 또는 sudo 로 컴파일을 실행하지 마세요.)
# change dir to downloaded apache source
$ cd httpd-2.4.33
$ ./buildconf
$ ./configure --enable-ssl --enable-so --enable-http2 --with-mpm=event --with-included-apr --with-ssl=/usr/local/openssl --prefix=/usr/local/apache2
$ make
기본 Apache 설치 디렉터리 경로를 변경할 수 있습니다. 여기서는 /usr/local/apache2 디렉터리 경로를 지정했습니다 .
# 컴파일 후 sudo로 HTTPD 설치
$ sudo make install
# 다운로드한 소스들 정리
#switch to home dir
$ cd ~
$ rm -rf 1.6.1.tar.gz 1.6.5.tar.gz 2.4.49.tar.gz apr-1.6.5 apr-util-1.6.1 httpd-2.4.49
# HTTPD 명령 수동으로 생성
$ sudo vim /etc/profile.d/httpd.sh
# 아래 내용을 붙여넣고 저장 및 종료
pathmunge /usr/local/apache2/bin
# apache 버전 확인
$ httpd -v
# HTTPD 시스템 항목 추가
httpd 서비스 관리를 위한 초기화 스크립트를 만듭니다 . 따라서 vim 편집기를 사용하여 /etc/init.d/ 디렉터리 에 httpd 파일을 만들고 파일에서 다음과 같이 변경합니다.
$ vim /etc/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl -k graceful
ExecStop=/usr/local/apache2/bin/apachectl -k graceful-stop
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# systemctl 데몬을 다시 로드
$ sudo systemctl daemon-reload
# apache httpd 서비스를 시작하고 활성화
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
# apache 전용 사용자 및 그룹 생성
$ sudo groupadd www
$ sudo useradd httpd -g www --no-create-home --shell /sbin/nologin
# apache httpd.conf 구성
아래 내용을 바탕으로 수정하거나 추가
$ sudo vi /usr/local/apache2/conf/httpd.conf
# Make sure that ServerRoot is set to the same value as --prefix during ./configure
ServerRoot /usr/local/apache2
# Set ServerName to prevent warning on Apache start
ServerName localhost
# Default port set to 80 - HTTP protocol
Listen 80
# Set user and group
User httpd
Group www
# Configure entry file
DirectoryIndex index.php index.html
# Hide Apache version from header and from error files
# not in the config by default so will need to add it in the bottom of the file
ServerTokens Prod
ServerSignature off
# Disable ETag to prevent disposing sensitive values like iNode
# not in the config by default so will need to add it in the bottom of the file
FileETag none
# HTTPD 재시작
$ sudo systemctl restart httpd
참고
https://gist.github.com/rizkhanriaz/9e7d581eda271ecf4fba7dd2636fec9f
https://www.linuxhelp.com/how-to-install-apache-from-source-code-on-centos-7
https://httpd.apache.org/docs/2.4/en/install.html