본문으로 건너뛰기

Apache 서비스를 어떻게 재기동하나요?

💡 요약 정리

  • Apache는 정적/동적 콘텐츠를 처리하는 웹서비스 프로그램입니다.
  • 현재 사용 포트는 netstat -nlp로 확인합니다. 배포판에 따라 출력은 다를 수 있습니다.
  • 패키지 설치 시 서비스명은 CentOS는 httpd, Ubuntu는 apache2입니다.
  • 재기동 명령은 환경별로 다릅니다: systemd, init.d, 또는 apachectl(소스 설치).
  • 일반적으로 80(HTTP), 443(HTTPS) 포트를 사용합니다.

1. Apache란?

  • 멀티 쓰레드 및 멀티 프로세스 기반으로 정적 및 동적 컨텐츠를 처리 가능한 웹서비스 프로그램입니다.

2. Apache 재기동 하기

1) netstat 명령어로 서비스 포트 확인

Apache 서비스가 기동 중인 상태에서 사용하는 포트를 확인하기 위해 다음 명령을 사용할 수 있습니다. 각 리눅스 배포판에 따라 결과가 다를 수 있습니다.

명령어 입력: netstat -nlp

[Example-Centos]

netstat -nlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address                 Foreign Address              State       PID/Program name

tcp        0        0 :::443                      :::*                        LISTEN      3141/httpd
tcp        0        0 :::80                       :::*                        LISTEN      3141/httpd

[Example-Ubuntu]

netstat -nlp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address       Foreign Address       State        PID/Program name
tcp6     512        0 :::80            :::*                   LISTEN      26472/apache2
tcp6       5        0 :::443           :::*                   LISTEN      26472/apache2

참고: CentOS에서는 서비스 명이 httpd, Ubuntu에서는 apache2입니다. 위 예시는 Apache가 80443 포트를 사용하는 것을 보여줍니다.

2) Apache 설치 폴더 찾기

① 패키지로 설치된 경우

  • 명령어 입력: ps -ef |grep httpd

[Example-Centos]

ps -ef | grep httpd

root        26472        1  0 15:09 ?        00:00:01 /usr/sbin/apache2 -k start

설명: CentOS에서 패키지로 설치된 경우, 보통 /etc/httpd 경로에 Apache 설정 파일이 있습니다.

  • 명령어 입력: ps -ef |grep apache2

[Example-Ubuntu]

ps -ef | grep apache2

root        26472        1  0 15:09 ?        00:00:01 /usr/sbin/apache2 -k start

설명: Ubuntu에서 패키지로 설치된 경우, 보통 /etc/apache2 경로에 Apache 설정 파일이 있습니다.

② 소스 설치된 경우

  • Centos의 경우 명령어 입력:
ps -ef | grep httpd
  • Ubuntu의 경우 명령어 입력:
ps -ef | grep apache2

설명: 소스 설치된 경우, 위 예시처럼 /opt/apache와 같이 사용자가 설정한 경로에 설치될 수 있습니다. httpd의 위치를 통해 Apache 설치 경로를 알 수 있습니다.

3) Apache 서비스 기동 명령어

Apache를 기동, 종료, 재기동하는 명령어는 패키지로 설치했는지, 소스로 설치했는지에 따라 다릅니다. 또한, systemd 또는 init 시스템을 사용하여 Apache를 제어할 수 있습니다.

① 패키지로 설치된 경우

systemd 사용 (CentOS 7 이상)

# Apache 기동
systemctl start httpd

# Apache 종료
systemctl stop httpd

# Apache 재기동
systemctl restart httpd

systemd 사용 (Ubuntu)

# Apache 기동
systemctl start apache2

# Apache 종료
systemctl stop apache2

# Apache 재기동
systemctl restart apache2

init.d 사용 (CentOS 6)

# Apache 기동
service start httpd

# Apache 종료
service stop httpd

# Apache 재기동
service restart httpd

② 소스 설치된 경우

[Apache 설치 경로]/bin/apachectl start
[Apache 설치 경로]/bin/apachectl stop
[Apache 설치 경로]/bin/apachectl restart