1 最好先安装组件
[[email protected] ~]# yum groupinstall additional development [[email protected] ~]# yum groupinstall development tool
2 安装ap1.5.2r(Apache Portable Runtime),安装apr-util 1.5.4工具
[[email protected] ~]wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz [[email protected] ~]# tar xzvf apr-1.5.2.tar.gz [[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr/
如果报错:rm: cannot remove `libtoolT‘: No such file or directory,请编辑configure这个文件,将 $RM "$cfgfile" 那行注释掉
[[email protected] apr-1.5.2]#make&&make install
安装apr-util工具
[[email protected] ~]wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
编译选项注意有 --apr选项
[[email protected] ~]# tar xf apr-util-1.5.4.tar.gz [[email protected] ~]# cd apr-util-1.5.4 [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ [[email protected] apr-util-1.5.4]#make&&make install
3 centos默认安装了pcre,所以不需要安装pcre,否则请安装
4 安装httpd 2.4.12(2015-6-6新)
[[email protected] ~]# tar xf httpd-2.4.12.tar.bz2 [[email protected] ~]# cd httpd-2.4.12
打算编译选项加上(注意不明确的请查看./configure -h不要瞎写,写完和自己的对照一下,是否有问题)
基本选项,包括安装路径,配置文件路径
--prefix=/usr/local/apache指定安装的大路径
--sysconfdir=/etc/httpd指定配置文件的路径
模块允许选项,允许模块使用,大部分动态允许mpm等
--enable-so允许模块化使用
--enable-modules=most添加大多数的模块
--enable-mods-shared=most
--enable-mpms-shared=all支持所有的mpm模型
--enable-cgi --enable-cgid支持cgi程序
--enable-ssl支持ssl从而支持https
--enable-rewrite支持url重定向
指定和apr,apr-util的联系与绑定
--with-include-apr
--with-apr=/usr/local/apr指定apr
--with-apr-util=/usr/local/apr-util指定apr-util
[[email protected] httpd-2.4.12]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --enable-cgi --enable-cgid --enable-ssl --enable-rewrite --with-include-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util [[email protected] httpd-2.4.12]#make&&make install
编译安装完
进入安装后的目录
[[email protected] bin]# cd /usr/local/apache [[email protected] apache]# ls bin build cgi-bin error htdocs icons include logs man manual modules [[email protected] apache]# cd bin/ [[email protected] bin]# ./apachectl
然后打开网页试试,输入你的虚拟机ip即可
如果不能打开,考虑如下
[[email protected] bin]# service iptables stop [[email protected] bin]# getenforce Enforcing [[email protected] bin]# setenforce 0 [[email protected] bin]# vim /etc/selinux/config
改为permissive
修改文件夹属性
[[email protected] bin]#chmod 755 /usr/local/apache/
再刷新试试
上述的好了,网页出现it works!后
我们可以把命令复制到/etc/init.d/httpd实现service调用,总之,一切为了实现之前使用httpd rpm包的那个习惯,嘿嘿
[[email protected] bin]# cp /root/httpd-2.4.12/build/rpm/httpd.init /etc/init.d/httpd [[email protected] bin]# chmod +x /etc/init.d/httpd
修改文件
建议三处
- httpd=${HTTPD-/usr/local/apache/bin/httpd}
- pidfile=${PIDFILE-/var/run/httpd/${prog}.pid}
- CONFFILE=/etc/httpd/httpd.conf
别急着启用服务
创建相应的目录
[[email protected] bin]# mkdir /var/run/httpd/
为了使用httpd -t等命令,修改~/.bash_profile
修改为PATH=$PATH:$HOME/bin:/usr/local/apache/bin
[[email protected] bin]# vim ~/.bash_profile [[email protected] bin]# source ~/.bash_profile [[email protected] bin]# httpd -t Syntax OK
在/etc/httpd/httpd.conf加上这行
PidFile "/var/run/httpd/httpd.pid"
为log文件创建符合链接
[[email protected] bin]# ln -s /usr/local/apache/logs/* /var/log/httpd/
然后重启服务看是否ok
如果不行请查看日志文件等
[[email protected] bin]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
然后再次查看网页是否正常,最终搭建最新httpd2.4.12的任务已经完成!