본문으로 건너뛰기

Apache HTTPD 설치와 기본 환경 구성

Apache HTTPD(이하 Apache)는 세계에서 가장 오랜 역사를 가진 웹서버 중 하나입니다. 다양한 운영 체제를 지원하며 모듈 기반 확장성이 뛰어납니다. 이 장에서는 Ubuntu·CentOS·Windows·Docker 환경별 설치 방법과 디렉터리 구조, MPM(Multi-Processing Module) 선택, 서비스 관리 명령을 다룹니다.


MPM(Multi-Processing Module) 이해​

Apache를 설치하기 전에 MPM을 먼저 이해해야 합니다. MPM은 Apache가 요청을 어떻게 병렬 처리할지 결정하는 핵심 모듈입니다.

MPM방식특징권장 환경
Prefork멀티 프로세스 (스레드 없음)각 요청에 독립 프로세스 할당, 안정적, mod_php 호환PHP + mod_php
Worker멀티 프로세스 + 멀티 스레드메모리 효율 향상, 스레드 안전 모듈 필요중간 규모
EventWorker 개선 (비동기 Keep-Alive)Keep-Alive 연결을 별도 스레드로 관리, 고성능현재 권장
# 현재 사용 중인 MPM 확인
apache2ctl -V | grep MPM
# 또는
httpd -V | grep MPM

Ubuntu / Debian 설치​

# 패키지 목록 업데이트
sudo apt update

# Apache2 설치
sudo apt install -y apache2

# 서비스 시작 및 자동 시작 등록
sudo systemctl start apache2
sudo systemctl enable apache2

# 상태 확인
sudo systemctl status apache2

설치 후 http://서버IP에 접속하면 "Apache2 Ubuntu Default Page"가 표시됩니다.

MPM 변경 (Prefork → Event)​

# 현재 활성화된 MPM 확인
ls /etc/apache2/mods-enabled/ | grep mpm

# Prefork 비활성화, Event 활성화
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event

# 재시작 적용
sudo systemctl restart apache2

# 확인
apache2ctl -V | grep MPM
# Server MPM: event

SSL 모듈 활성화​

# HTTPS 지원을 위한 SSL 모듈 활성화
sudo a2enmod ssl
sudo systemctl reload apache2

CentOS / RHEL / Rocky Linux 설치​

# httpd 설치
sudo yum install -y httpd

# 서비스 시작 및 자동 시작 등록
sudo systemctl start httpd
sudo systemctl enable httpd

# 방화벽에서 HTTP/HTTPS 허용
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

MPM 설정 (CentOS)​

CentOS에서는 /etc/httpd/conf.modules.d/00-mpm.conf에서 MPM을 설정합니다.

# /etc/httpd/conf.modules.d/00-mpm.conf
# 원하는 MPM만 주석 해제, 나머지는 주석 처리

# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
# LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule mpm_event_module modules/mod_mpm_event.so

macOS 설치 (Homebrew)​

# Homebrew로 설치
brew install httpd

# 서비스 시작 (포트 8080 기본)
brew services start httpd

# 설정 파일 위치
# /opt/homebrew/etc/httpd/httpd.conf (Apple Silicon)
# /usr/local/etc/httpd/httpd.conf (Intel)

Windows 설치​

Windows에서 Apache를 직접 설치하거나 XAMPP, WampServer 같은 패키지를 사용합니다.

XAMPP 사용 (권장)​

  1. https://www.apachefriends.org에서 XAMPP 다운로드
  2. 설치 후 XAMPP Control Panel에서 Apache 시작
  3. 설정 파일 위치: C:\xampp\apache\conf\httpd.conf

직접 설치 (MSI)​

# Apache Lounge (https://www.apachelounge.com/download/) 에서 Win64 zip 다운로드
# C:\Apache24 에 압축 해제

# Windows 서비스로 등록
C:\Apache24\bin\httpd.exe -k install

# 서비스 시작
net start Apache2.4

# 설정 파일: C:\Apache24\conf\httpd.conf

Docker로 Apache 실행​

# 최신 버전 실행
docker run -d --name apache -p 80:80 httpd

# 설정 파일과 웹 루트 마운트
docker run -d \
--name apache \
-p 80:80 \
-v $(pwd)/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro \
-v $(pwd)/html:/usr/local/apache2/htdocs:ro \
httpd

# 컨테이너에서 설정 리로드
docker exec apache apachectl graceful

docker-compose.yml 예시:

version: '3.8'
services:
apache:
image: httpd:2.4-alpine
container_name: apache
ports:
- "80:80"
- "443:443"
volumes:
- ./conf/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
- ./conf/extra:/usr/local/apache2/conf/extra:ro
- ./html:/usr/local/apache2/htdocs:ro
restart: unless-stopped

Apache 디렉터리 구조​

Ubuntu/Debian 기준​

/etc/apache2/                     ← 설정 파일 루트
apache2.conf ← 메인 설정 파일
ports.conf ← 리슨 포트 설정
envvars ← 환경 변수 설정
conf-available/ ← 추가 설정 (비활성 포함)
conf-enabled/ ← 활성화된 추가 설정 (심볼릭 링크)
mods-available/ ← 사용 가능한 모듈
mods-enabled/ ← 활성화된 모듈 (심볼릭 링크)
sites-available/ ← 가상 호스트 설정 (비활성 포함)
000-default.conf ← 기본 가상 호스트
default-ssl.conf ← 기본 SSL 가상 호스트
sites-enabled/ ← 활성화된 가상 호스트 (심볼릭 링크)

/var/www/html/ ← 기본 웹 루트
/var/log/apache2/ ← 로그 디렉터리
access.log
error.log
/usr/sbin/apache2 ← Apache 실행 파일
/usr/sbin/apache2ctl ← Apache 제어 스크립트

CentOS/RHEL 기준​

/etc/httpd/
conf/
httpd.conf ← 메인 설정 파일
conf.d/ ← 추가 설정 파일 (*.conf 자동 로딩)
ssl.conf
welcome.conf
conf.modules.d/ ← 모듈 로딩 설정
00-base.conf
00-mpm.conf
00-ssl.conf

/var/www/html/ ← 기본 웹 루트
/var/log/httpd/ ← 로그 디렉터리
access_log
error_log
/usr/sbin/httpd ← Apache 실행 파일

Apache 서비스 관리 명령​

systemctl 명령​

sudo systemctl start apache2      # 시작 (Ubuntu)
sudo systemctl start httpd # 시작 (CentOS)
sudo systemctl stop apache2 # 중지
sudo systemctl restart apache2 # 재시작 (연결 끊김 발생)
sudo systemctl reload apache2 # 설정 리로드 (graceful, 권장)
sudo systemctl status apache2 # 상태 확인
sudo systemctl enable apache2 # 부팅 시 자동 시작 등록

apachectl / apache2ctl 명령​

sudo apache2ctl start            # 시작
sudo apache2ctl stop # 중지
sudo apache2ctl restart # 재시작
sudo apache2ctl graceful # 처리 중인 요청 완료 후 재시작 (무중단)
sudo apache2ctl graceful-stop # 처리 중인 요청 완료 후 종료
sudo apache2ctl configtest # 설정 파일 문법 검사
sudo apache2ctl -V # 버전 및 컴파일 옵션 확인
sudo apache2ctl -M # 활성화된 모듈 목록
sudo apache2ctl -S # 가상 호스트 설정 요약

핵심: 설정 변경 후 restart 대신 graceful을 사용하세요. graceful은 처리 중인 요청이 완료된 후 워커를 교체하여 무중단으로 설정을 적용합니다.


설치 확인​

# Apache 버전 확인
apache2 -v # Ubuntu
httpd -v # CentOS

# 컴파일 옵션 확인
apache2ctl -V

# 설정 파일 문법 검사
sudo apache2ctl configtest
# Syntax OK

# 80 포트 리슨 확인
sudo ss -tlnp | grep :80

정리​

항목UbuntuCentOS비고
패키지명apache2httpd같은 소프트웨어
설정 루트/etc/apache2//etc/httpd/구조 다름
웹 루트/var/www/html//var/www/html/동일
로그/var/log/apache2//var/log/httpd/다름
제어 명령apache2ctlapachectl동일 기능
권장 MPMEventEvent성능 최적