设为首页 收藏本站
查看: 1287|回复: 0

[经验分享] 编译安装Apache

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-20 08:51:10 | 显示全部楼层 |阅读模式
一、准备工作
二、编译安装
三、相关文件路径配置
四、主配置文件常用配置信息详解

一、准备工作

安装编译环境
?
1
yum groupinstall "Development tools"




下载所需文件
?
1
2
3
4
5
6
7
[iyunv@localhost ~]# mkdir downloads
[iyunv@localhost ~]# cd downloads/
[iyunv@localhost downloads]#wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.12.tar.gz
[iyunv@localhost downloads]#wget http://mirror.bit.edu.cn/apache/apr/apr-1.5.2.tar.gz
[iyunv@localhost downloads]#wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
[iyunv@localhost downloads]# ls
apr-1.5.2.tar.gz  apr-util-1.5.4.tar.gz  httpd-2.4.12.tar.gz




解压文件
?
1
2
3
[iyunv@localhost downloads]# tar -xf httpd-2.4.12.tar.gz
[iyunv@localhost downloads]# tar -xf apr-1.5.2.tar.gz
[iyunv@localhost downloads]# tar -xf apr-util-1.5.4.tar.gz




二、编译安装
cd到源码文件夹中,可以使用 # ./configure --help,获取编译帮助  

(1)、编译安装apr,apr-util,编译安装httpd2.4需要较新版本apr和apr-util
?
1
2
3
4
5
6
[iyunv@localhost apr-1.5.2]# cd apr-1.5.2
[iyunv@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[iyunv@localhost apr-1.5.2]# make && make install
[iyunv@localhost apr-1.5.2]# cd /root/downloads/apr-util-1.5.4
[iyunv@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[iyunv@localhost apr-util-1.5.4]# make && make install




下列命令执行完成后
?
1
./configure --prefix=/usr/local/apr



结果中提示cannot remove `libtoolT': No such file or directory

解决编辑configure,注释掉 $RM "$cfgfile" 即可。

(2)、编译安装httpd
?
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost apr-util-1.5.4]# cd /root/downloads/httpd-2.4.12
[iyunv@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=worker
[iyunv@localhost httpd-2.4.12]# make
提示
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决,下次编译时提前安装
[iyunv@localhost httpd-2.4.12]# yum install pcre-devel -y
再次make,提示
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决,需要mod_ssl模块支持,依赖其开发组件
[iyunv@localhost httpd-2.4.12]# yum install -y openssl-devel
再次make,成功,然后安装
[iyunv@localhost httpd-2.4.12]# make install




./configure相关选项,--enable-mpms-shared=all,这样event、worker、prefork就会以模块化的方式安装,这里的--with-mpm=worker设定启用worker模块,其他的根据需要在httpd.conf里配置。
?
1
2
3
4
5
6
7
8
9
10
--sysconfdir=/etc/httpd  :指定配置文件安装位置
--enable-so              :支持动态共享模块如果没有这个模块PHP将无法与apache结合工作
--enable-ssl             :启用支持ssl
--enable-cgi             :支持cgi
--enable-rewrite         :支持URL重写
--with-zlib             :压缩库,在互联网上传播时可节约带宽
--with-apr=/usr/local/apr :指定apr路径
--with-apr-util=/usr/local/apr-util :指定apr-util路径
--enable-mpms-shared=all  :支持多道处理模块
--with-mpm=event         :设定默认的模块





三、相关文件路径配置

(1)、将服务程序路径添加到PATH环境变量中
新建/etc/profile.d/apache.sh,添加内容保存退出,source一下
?
1
export PATH=$PATH:/usr/local/apache/bin



(2)、添加库文件搜索路径
新建/etc/ld.so.conf.d/apache.conf,添加内容
?
1
/etc/ld.so.conf.d/apache.conf



(3)、添加头文件路径
?
1
[iyunv@localhost profile.d]# ln -sv /usr/local/apache/include /usr/include/httpd



(4)、添加man手册路径
编辑/etc/man.config文件中的“MANPATH=”
?
1
MANPATH /usr/local/apache/share/man



(5)、将服务脚本复制到/etc/init.d目录下
?
1
[iyunv@localhost apache]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd



(6)、有需要可以修改下/etc/init.d/httpd
1
2
3
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}



(7)、添加httpd到服务列表,设置开机启动,并启动服务
?
1
2
3
[iyunv@localhost apache]# chkconfig --add httpd
[iyunv@localhost apache]# chkconfig httpd on
[iyunv@localhost apache]# service httpd start




如果有如下提示
?
1
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message



编辑/etc/httpd/httpd.conf,搜索/ServerName,定位到#ServerName www.example.com:80,修改并启用即可,如
?
1
ServerName localhost:80




完成以上配置,就可以用浏览器测试了,下图中“It works!”显示apache正常工作
wKiom1VbODyzasWcAAB4QWh2Jac283.jpg



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-68703-1-1.html 上篇帖子: Apache Httpd服务器之虚拟机详解 下篇帖子: apache编译问题汇总
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表