资讯专栏INFORMATION COLUMN

源码安装apache(附遇到的问题及解决)

int64 / 3419人阅读

摘要:开通访问生成证书编辑,打开以下注释重启查看访问查看端口访问如果出现恭喜你就成功啦。就不会出上述错误了。

版本说明

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)



ProxyPass ajp://127.0.0.1:#tomcat的ajp端口#/apache_tomcat_test


重启apache

访问: https://ip:443/apache_tomcat_test

通过80端口跳转(用https,关闭http访问)

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


SSLEngine on
SSLCertificateFile "/usr/local/apache2/conf/server.crt" 
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" 


  ProxyPass ajp://127.0.0.1:#tomcat的ajp端口#/apache_tomcat_test


重启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





文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/35940.html

相关文章

  • 关于 webpack 你可能忽略细节(源码分析)

    摘要:本篇的主要目标是通过实际问题来介绍中容易被人忽略的细节以及源码分析以最新发布的版本的源码为例并且提供几种解决方案。探究原因及源码分析这里以最新发布的版本的源码作为分析。解决方案加参数基于上面简要的分析,我们来尝试下参数的作用。 注:本篇不是入门教程,入门请直接查看官方文档。本篇的主要目标是通过实际问题来介绍 webpack 中容易被人忽略的细节, 以及源码分析(以最新发布的 relea...

    mtunique 评论0 收藏0
  • 【推荐】最新200篇:技术文章整理

    摘要:作为面试官,我是如何甄别应聘者的包装程度语言和等其他语言的对比分析和主从复制的原理详解和持久化的原理是什么面试中经常被问到的持久化与恢复实现故障恢复自动化详解哨兵技术查漏补缺最易错过的技术要点大扫盲意外宕机不难解决,但你真的懂数据恢复吗每秒 作为面试官,我是如何甄别应聘者的包装程度Go语言和Java、python等其他语言的对比分析 Redis和MySQL Redis:主从复制的原理详...

    BicycleWarrior 评论0 收藏0
  • 【推荐】最新200篇:技术文章整理

    摘要:作为面试官,我是如何甄别应聘者的包装程度语言和等其他语言的对比分析和主从复制的原理详解和持久化的原理是什么面试中经常被问到的持久化与恢复实现故障恢复自动化详解哨兵技术查漏补缺最易错过的技术要点大扫盲意外宕机不难解决,但你真的懂数据恢复吗每秒 作为面试官,我是如何甄别应聘者的包装程度Go语言和Java、python等其他语言的对比分析 Redis和MySQL Redis:主从复制的原理详...

    tommego 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<