개발 블로그

[교육] Apache 2.4 설치하기 본문

리눅스 | 서버

[교육] Apache 2.4 설치하기

토도 2024. 5. 27. 16:33

0. Apache 설치하기 전

2트 시도하는 도중에 yum install 명령어가 안되더라 이유는

 

이 오류는 CentOS 7의 공식 리포지토리 URL이 더 이상 유효하지 않아서 발생합니다. CentOS 7은 이제 더 이상 주기적인 업데이트가 제공되지 않고, 오래된 패키지는 vault.centos.org라는 아카이브 서버에서 관리됩니다. 따라서 baseurl을 vault.centos.org로 변경해야 합니다.

해결 방법:

/etc/yum.repos.d/CentOS-Base.repo 파일의 설정을 변경하여 mirror.centos.org 대신 vault.centos.org를 사용해야 합니다.

1. 리포지토리 파일 수정

다음과 같이 설정을 변경하세요:

  1. /etc/yum.repos.d/CentOS-Base.repo 파일을 엽니다:
  2.  
    vi /etc/yum.repos.d/CentOS-Base.repo
  3. [base], [updates], [extras] 섹션의 mirrorlist를 주석 처리하고 baseurl을 활성화합니다.

2. yum 캐시 정리 및 설치 재시도

리포지토리 설정을 변경한 후에는 yum clean 명령어로 캐시를 정리하고 다시 시도합니다.

yum clean all
 
yum install httpd

 

이제 패키지를 정상적으로 설치할 수 있을 것입니다.


 

yum install -y httpd

 

gcc 및 관련 패키지 파일을 설치한다.

 

yum update -y

 

...

 

한참 글자가 써진 후에 Complete! 가 보이면  

 

yum install -y gcc gcc-c++ pcre-devel expat-devel

 

 

얘 역시도 Complete가 되었다면 

 


1. Apache 관련 설치 파일 다운로드

 

Apache HTTP Server를 설치하기 위해서는 다음과 같은 파일의 설치가 필요하다.

1) pcre(Perl Compatible Regular Expressions) : https://sourceforge.net/projects/pcre/files/pcre/

2) httpd

3) apr(Apache Portable Runtime)

4) apr-util : https://downloads.apache.org

 

wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
wget http://archive.apache.org/dist/httpd/httpd-2.4.49.tar.gz

wget https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz

wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz

 

engine/apache2.4 로 다운 받은 파일 이동하기

 

[root@localhost ~]# cd /engine

[root@localhost engine]# mkdir apache2.4
[root@localhost engine]# ls
apache2.4

 

[root@localhost ~]# mv apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.49.tar.gz pcre-8.45.tar.gz /engine/apache2.4

( 바보짓 같은게 /engine/apach2.4 폴더로 미리 이동하고 다운로드 했으면 굳이 안 이래도 된다)

 

engine/apache2.4에 다 옮기고 압축을 tar 명령어로 풀어준다

 

tar zxvf apr-1.7.0.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
tar zxvf httpd-2.4.49.tar.gz
tar zxvf pcre-8.45.tar.gz

 

tar zxvf 명령어에서 각 옵션의 의미는 다음과 같습니다:

  • z: gzip 형식으로 압축된 파일을 처리한다는 의미입니다.
  • x: 압축을 해제(extract)한다는 의미입니다.
  • v: 자세한 정보를 표시(verbose)한다는 의미입니다. 압축 해제 과정에서 어떤 파일이 처리되고 있는지를 화면에 출력합니다.
  • f: 파일 이름을 지정한다는 의미입니다. tar 명령어에서 f 옵션 다음에 올 파일 이름을 지정해줍니다.

 

2. 컴파일 설치 

1) PCRE 컴파일 설치

* PCRE: Perl 호환 정규 표현식, 정규식 패턴 일치를 구현하는 함수의 집합.

 

 


 

2) Apache HTTP Server(httpd) 컴파일 설치

Apache Portable Runtime은 Apache 웹 서버를 지원하는 라이브러리이다.

apr, apr-util 파일을 httpd 디렉터리에 옮긴 후 컴파일 설치 진행

 

 

 

[root@localhost httpd-2.4.49]# ./configure --prefix=/engine/apache2.4 --with-included-apr --with-pcre=/engine/apache2.4/bin/pcre-config

 

 


3. 심볼릭 링크 설정

Apache 설치 디렉토리를 /engine/apache로 심볼릭 링크를 설정합니다.


4. 서비스 등록

Apache를 systemd 서비스로 등록하여 쉽게 관리할 수 있도록 한다

 

4.1. 서비스 파일 생성

Apache의 서비스 파일을 생성

sudo nano /etc/systemd/system/httpd.service

 

아래 내용을 파일에 추가함

 

[Unit]
Description=The Apache HTTP Server
After=network.target

[Service]
Type=forking
ExecStart=/engine/apache/bin/apachectl start
ExecStop=/engine/apache/bin/apachectl stop
ExecReload=/engine/apache/bin/apachectl graceful

[Install]
WantedBy=multi-user.target

 

 

 

sudo systemctl daemon-reload
sudo systemctl enable httpd
sudo systemctl start httpd

 

서비스를 등록하고 시작한다

 

상태도 확인 해보니 초록색 active 가 뜨고 있다

 

 

참고: 

https://t-okk.tistory.com/200