版本说明

  • CentOS版本:
    CentOS release 6.8 (Final)
  • 安装包版本:
    httpd-2.4.29.tar.gz
    apr-1.6.3.tar.gz
    apr-util-1.6.1
    pcre-8.41.tar.gz

安装过程

路径说明

安装包一般放在:/usr/local/src
安装路径一般为:/usr/local

安装(用root用户)

  • 安装必要应用
    # yum install -y gcc gcc-c++
    # yum install -y expat-devel //错误1
    # yum install -y pcre-devel //错误2
    # yum install -y openssl-devel //错误3
    # yum install -y libxml2-devel //错误4
  • apr安装
    # tar zvxf apr-1.6.3.tar.gz
    # cd apr-1.6.3
    # ./configure --prefix=/usr/local/apr/
    # make
    # make install
  • apr-util安装
    # tar zvxf apr-util-1.6.1.tar.gz
    # cd apr-util-1.6.1
    # ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
    # make
    # make install

  • pcre安装
    # tar zvxf pcre-8.41.tar.gz
    # cd pcre-8.41
    # ./configure --prefix=/usr/local/pcre/
    # make
    # make install
  • apache安装

    # ./configure \
    --prefix=/usr/local/apache2.4 \
    --sbindir=/usr/local/apache2.4/sbin \
    --with-apr=/usr/local/apr/ \
    --with-apr-util=/usr/local/apr-util \
    --with-pcre=/usr/local/pcre/ \
    --enable-ssl \
    --with-ssl=shared \
    --enable-proxy=shared \
    --enable-so \
    --enable-mods-shared=all
    # make
    # make install

启动及查看

  • 复制命令到service级别
    # cp /usr/local/apache2.4/sbin/httpd /etc/rc.d/init.d
  • 启动
    # service httpd -k start
  • 停止
    # service httpd -k stop
  • 重启
    # service httpd -k restart
  • 查看状态
    # service httpd -T

    • 通过80端口状态查看
      # sudo netstat -antp|grep 80
    • 通过进程查看
      # ps -ef|grep httpd
    • 访问查看是否启动成功
      访问:http://ip:80
      出现It works! 恭喜你就成功啦。

开通https访问

  • 生成证书

    # cd /usr/local/apache2.4/conf
    # openssl req -new -x509 -nodes -out server.crt -keyout server.key
  • 编辑httpd.conf,打开以下注释

    Include conf/extra/httpd-ssl.conf 
    LoadModule ssl_module modules/mod_ssl.so
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
  • 重启apache
  • 查看&访问

    • 查看443端口:# sudo netstat -antp|grep 443
    • 访问:https://ip:443 , 如果出现It works! 恭喜你就成功啦。

实现与tomcat整合

  • 编辑httpd.conf,打开以下注释

     LoadModule proxy_module modules/mod_proxy.so
     LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
  • 通过443端口跳转

    • 编辑/conf/extra/httpd-ssl.conf(在443虚拟机中加入跳转的tomcat)

      <VirtualHost *:443>
      <Location /apache_tomcat_test>
      ProxyPass ajp://127.0.0.1:#tomcat的ajp端口#/apache_tomcat_test
      </Location>
      </VirtualHost>
      
    • 重启apache
    • 访问https://ip:443/apache_tomcat_test
  • 通过80端口跳转(用https,关闭http访问)

    • 编辑/conf/extra/httpd-ssl.conf(在80虚拟机中加入跳转的tomcat)

      <VirtualHost *:80>
      SSLEngine on
      SSLCertificateFile "/usr/local/apache2/conf/server.crt" 
      SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" 
      
      <Location /apache_tomcat_test>
        ProxyPass ajp://127.0.0.1:#tomcat的ajp端口#/apache_tomcat_test
      </Location>
      </VirtualHost>
      
    • 重启apache
    • 访问https://ip:80/apache_tomcat_test

安装中的错误及解决

错误1

  • apr-util-1.6.1编译时的错误

    make[1]: Entering directory `/usr/local/apr-util-1.6.1'
    /bin/sh /usr/local/apr//build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr//include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
    xml/apr_xml.c:35:19: error: expat.h: No such file or directory
    xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
    xml/apr_xml.c: In function ‘cleanup_parser’:
    xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c: トップレベル:
    xml/apr_xml.c:384: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
    xml/apr_xml.c: In function ‘apr_xml_parser_create’:
    xml/apr_xml.c:401: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:402: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:410: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:411: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:412: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:424: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:424: error: ‘default_handler’ undeclared (first use in this function)
    xml/apr_xml.c:424: error: (Each undeclared identifier is reported only once
    xml/apr_xml.c:424: error: for each function it appears in.)
    xml/apr_xml.c: In function ‘do_parse’:
    xml/apr_xml.c:434: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:438: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp_err’
    xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp’
    xml/apr_xml.c: In function ‘apr_xml_parser_geterror’:
    xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
    xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
    make[1]: * [xml/apr_xml.lo] Error 1
    make[1]: Leaving directory `/usr/local/apr-util-1.6.1'
    make: * [all-recursive] Error 1

  • 原因:缺少expat库,估计是apr-util-1.6不提供了,apr-util-1.5就没这个错误
  • 解决:# yum install -y expat-devel

错误2

  • apache ./configure时的错误
    checking for pcre-config... false
  • 原因:缺少pcre库
  • 解决:# yum -y install pcre-devel

错误3

  • apache ./configure时的错误
    checking for OpenSSL version >= 0.9.8a... FAILED
    configure: WARNING: OpenSSL version is too old
  • 原因:OpenSSL版本旧
  • 解决:# yum install -y openssl-devel

错误4

  • apache make时出错
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_StopParser'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_Parse'
    /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
    collect2: ld returned 1 exit status
    make[2]: * [htpasswd] Error 1
    make[2]: Leaving directory `/usr/local/httpd-2.4.29/support'
    make[1]: * [all-recursive] Error 1
    make[1]: Leaving directory `/usr/local/httpd-2.4.29/support'
    make: * [all-recursive] Error 1
  • 原因:缺少了xml相关的库,导致reference无效
  • 解决:# yum install -y libxml2-devel
  • 注意:安装libxml2-devel后,需要删掉apr-util,重新安装

其他说明

apache依赖包可以降低到1.5。就不会出上述错误了。

apr-1.5.2
apr-util-1.5.2
pcre-8.41






April
159 声望7 粉丝

润新苗于细雨 成万物于美田