CentOS 7 Apache (httpd) 설치
Linux 서버에서 웹 서비스를 제공하기 위해 가장많이 사용하는 웹서버는 Apache(http)입니다.
※ Apache HTTP 서버(Apache HTTP Server)는 2.x 버전 업데이트 이후부터 "httpd"로 배포되고 있습니다.
웹 서버를 설치하면 브라우저 URL에 IP주소나 도메인 주소를 입력하여
사용자가 만든 웹 페이지를 오픈할 수 있습니다.
이를 통해 회사 소개 홈페이지를 노출하거나 상품 홍보 및 커뮤니티 사이트 운영, 스틑리밍 모듈을 추가하여
영상 재생 등의 다양한 서비스를 활용할 수 있습니다.
하단은 CentOS7 환경에서 httpd 2.4.54 버전 prefork를 중심으로 설치하는 과정을 소개합니다.
Apache 설치
1. 필수 구성요소 설치
# yum install -y vim wget epel-release # mkdir -p /usr/local/src/APM_Setup # yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm # yum update -y # yum install -y libdb-devel enchant-devel libxslt libxslt-devel net-snmp-devel readline-devel readline aspell-devel unixODBC unixODBC-devel libicu-devel icu libicu libc-client libc-client-devel libc-client-2007f freetype-devel freetype* freetype libXpm libXpm-devel libpng-devel libpng* libvpx-devel libvpx libcurl libcurl-devel curl* curl-devel curl tcp_wrappers-devel libzip environment-modules uw-imap-utils uw-imap-devel uw-imap uw-imap-static pam-devel libldb-devel openldap-devel cyrus-sasl-devel bzip2-devel bzip2 bzip2-libs ncurses-devel ncurses mysql-devel libjpeg-devel libjpeg* libjpeg-devel openssl-devel openssl* openssl-libs libxml* libxml2 libxml2-devel libmcrypt libmcrypt-devel libmcrypt* mcrypt mhash* mhash mhash-devel libmhash libmhash-devel expat-devel expat expat* gmp* gmp gmp-devel krb5* krb5-devel db4 db4-devel wget make cmake libtool* pcre* gdbm* gdbm gdbm-devel libtiff* libtiff libtiff-devel flex zlib* zlib-devel zlib gd* gd gd-devel patch t1lib t1lib-devel readline libedit-devel libtidy libtidy-devel gcc* gcc gcc-c++ libtermcap-devel dialog sqlite-devel oniguruma oniguruma-devel libzip5 mod_ssl postgresql-devel lcov systemtap-sdt-devel mod_ldap elfutils-devel libwebp-devel libwebp git gzip libnghttp2-devel valgrind* mod_proxy* editline editline-devel patchelf systemd-devel ImageMagick-devel libzstd-devel libffi libffi-devel libraqm-devel libraqm libsodium libsodium-devel
imap 관련 64비트 32비트 라이브러리 설정 # ln -s /usr/lib64/libc-client.a /usr/lib/libc-client.a # unlink /usr/include/db.h # ln -s /usr/include/libdb4/db.h /usr/include/db.h # ln -s /usr/include/sqlext.h /usr/local/include/sqlext.h # ln -s /usr/lib64/libgdbm_compat.so /usr/local/lib64/libdbm.so
openldap 라이브러리 32비트 호환 # \cp -arpf /usr/lib64/libldap* /usr/lib/ # ln -sf /usr/lib64/libm.so /usr/lib/libm.so # ln -sf /usr/lib64/libssl.so /usr/lib/libssl.so
libXpm 모듈 설치를 위한 라이브러리 32비트 호환 # ln -s /usr/lib64/libXpm.so /usr/lib/ # ln -s /usr/lib64/libXpm.so.4 /usr/lib/ # ln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/ |
2. default 환경변수 설정
# echo " " >> /etc/profile # echo "####default PATH#####" >> /etc/profile # echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:" >> /etc/profile # echo "#####################" >> /etc/profile |
3. Apr 설치
# cd /usr/local/src/APM_Setup # wget https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz # tar zxvf apr-1.7.0.tar.gz # cd apr-1.7.0 # ./configure --prefix=/usr/local/apr # make -j # make install |
4. Apr-iconv 설치
# cd /usr/local/src/APM_Setup # wget https://archive.apache.org/dist/apr/apr-iconv-1.2.2.tar.gz # tar zxvf apr-util-1.2.2.tar.gz # cd apr-util-1.2.2 # ./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr/bin/apr-1-config # make -j # make install |
5. Apr-util 설치
# cd /usr/local/src/APM_Setup # wget http://mirror.apache-kr.org/apr/apr-util-1.6.1.tar.gz # tar zxvf apr-util-1.6.1.tar.gz # cd apr-util-1.6.1 # ./configure --prefix=/usr/local/apr --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-iconv=/usr/local/apr/bin/apriconv --with-crypto --with-openssl --with-nss --with-lber --with-ldap --with-ldap-include=/usr/include --with-ldap-lib=/usr/lib64/ # make -j # make install |
6. pcre 1 설치
# cd /usr/local/src/APM_Setup # wget https://ftp.exim.org/pub/pcre/pcre-8.45.tar.gz # tar zxvf pcre-8.45.tar.gz # cd pcre-8.45 # ./configure --prefix=/usr/local/pcre --enable-pcre8 --enable-pcre16 --enable-pcre32 --enable-jit --enable-utf8 --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --enable-valgrind # make -j # make install |
7. httpd 설치
# cd /usr/local/src/APM_Setup # wget https://archive.apache.org/dist/httpd/httpd-2.4.54.tar.gz # tar zxvf httpd-2.4.54.tar.gz # cd httpd-2.4.54
동시 접속자 수 변경 # vi server/mpm/prefork/prefork.c # define DEFAULT_SERVER_LIMIT 256 ← 기존값 256에서 2048로 변경해준다. 동시접속이 2048개 접속이 가능합니다.
아래는 vi로 수정할 필요 없이 sed로 내용을 치환해서 수정합니다. sed -i "s/#define DEFAULT_SERVER_LIMIT 128/#define DEFAULT_SERVER_LIMIT 2048/g" ./server/mpm/prefork/prefork.c ← 기존값 256에서 2048로 변경해줍니다.
* 여기서 sed 라는 명령어는 파일들을 출력, 치환 및 변경해줄 수 있는 명령어입니다.
# ./configure --prefix=/usr/local/apache --enable-load-all-modules --enable-maintainer-mode --enable-debugger-mode --enable-pie --enable-modules=all --enable-mods-shared=all --enable-imagemap --enable-authnz-ldap --enable-authnz-fcgi --enable-allowmethods --enable-isapi --enable-file-cache --enable-cache --enable-cache-disk --enable-cache-socache --enable-socache-shmcb --enable-socache-dbm --enable-socache-memcache --enable-socache-redis --enable-so --enable-rewrite --enable-ssl --enable-expires --enable-proxy-fcgi --enable-proxy-scgi --enable-proxy-html --enable-cgi --enable-cgid --enable-xml2enc --enable-cern-meta --enable-case-filter --enable-ident --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-pcre=/usr/local/pcre/bin/pcre-config --with-mpm=prefork --enable-http --disable-http2 --enable-modules=all # make -j # make install |
8. mod_url 설치 및 연동 ( 한글파일명 파일 인식 ex: 업로드.html )
# cd /usr/local/src/APM_Setup # wget https://kldp.net/modurl/release/2188-mod_url-apache2-1.25.tar.bz2 # tar xvf 2188-mod_url-apache2-1.25.tar.bz2 # cd /usr/local/src/APM_Setup/mod_url-apache2-1.25 # /usr/local/apache/bin/apxs -iac mod_url.c # echo "" >> /usr/local/apache/conf/httpd.conf # echo " # echo "" >> /usr/local/apache/conf/httpd.conf |
9. httpd.conf 설정파일 수정
sed -i "s/`grep '^User ' /usr/local/apache/conf/httpd.conf`/User nobody/g" /usr/local/apache/conf/httpd.conf sed -i "s/`grep '^Group ' /usr/local/apache/conf/httpd.conf`/Group nobody/g" /usr/local/apache/conf/httpd.conf sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /usr/local/apache/conf/httpd.conf sed -i 's/DirectoryIndex index.html/DirectoryIndex index.html index.php index.jsp/g' /usr/local/apache/conf/httpd.conf sed -i 's/ServerAdmin you@example.com/ServerAdmin root@localhost/g' /usr/local/apache/conf/httpd.conf sed -i 's/#AddHandler cgi-script .cgi/AddHandler cgi-script .cgi/g' /usr/local/apache/conf/httpd.conf sed -i '/AddType application\/x-gzip .tgz/a\ #PHP Enable' /usr/local/apache/conf/httpd.conf sed -i '/\ #PHP Enable/a \ AddType application/x-httpd-php-source .phps' /usr/local/apache/conf/httpd.conf sed -i '/\ #PHP Enable/a \ AddType application/x-httpd-php .php .jsp .html .inc ' /usr/local/apache/conf/httpd.conf
home Web source file 설정 일반적으로 /home/일반계정/웹소스파일 이렇게 있기 때문에 해당 설정을 넣습니다. echo "" >> /usr/local/apache/conf/httpd.conf echo " echo "" >> /usr/local/apache/conf/httpd.conf |
10. 자동 실행 설정
# cp -arp /usr/local/apache/bin/apachectl /etc/init.d/ # chmod 700 /etc/init.d/apachectl # sed -i '/#!\/bin\/sh/a # chkconfig: 2345 90 90' /etc/init.d/apachectl # sed -i '/#!\/bin\/sh/a # description: init file for Apache server daemon.\' /etc/init.d/apachectl # sed -i '/#!\/bin\/sh/a # processname: /usr/local/apache/bin/apachectl' /etc/init.d/apachectl # sed -i '/#!\/bin\/sh/a # config: /usr/local/apache/conf/httpd.conf' /etc/init.d/apachectl # sed -i '/#!\/bin\/sh/a # pidfile: /usr/local/apache/logs/httpd.pid' /etc/init.d/apachectl |
11. 부팅시 자동실행 설정
# chkconfig --add apachectl # chkconfig --level 3 apachectl on |
12. APM 환경변수 설정
# echo " " >> /etc/profile # echo "APACHE_HOME=/usr/local/apache" >> /etc/profile # echo "MySQL_HOME=/usr/local/mysql" >> /etc/profile # echo "PHP_HOME=/usr/local/php" >> /etc/profile # echo " " >> /etc/profile # echo "export PATH="\$"APACHE_HOME/bin:"\$"MySQL_HOME/bin:"\$"PHP_HOME/bin:"\$"PHP_HOME/sbin"\$"{PATH:+:"\$"{PATH}}" >> /etc/profile # echo " " >> /etc/profile # source /etc/profile |