1 最好先安装组件
[root@localhost ~]# yum groupinstall additional development [root@localhost ~]# yum groupinstall development tool
2 安装ap1.5.2r(Apache Portable Runtime),安装apr-util 1.5.4工具
[root@localhost ~]wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz [root@localhost ~]# tar xzvf apr-1.5.2.tar.gz [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr/
如果报错:rm: cannot remove `libtoolT': No such file or directory,请编辑configure这个文件,将 $RM "$cfgfile" 那行注释掉
[root@localhost apr-1.5.2]#make&&make install
安装apr-util工具
[root@ns2 ~]wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
编译选项注意有 --apr选项
[root@localhost ~]# tar xf apr-util-1.5.4.tar.gz [root@localhost ~]# cd apr-util-1.5.4 [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ [root@localhost apr-util-1.5.4]#make&&make install
3 centos默认安装了pcre,所以不需要安装pcre,否则请安装pcre-devel哦
4 安装httpd 2.4.12(2015-6-6新)
[root@localhost ~]# tar xf httpd-2.4.12.tar.bz2 [root@localhost ~]# 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
[root@localhost 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 [root@localhost httpd-2.4.12]#make&&make install
如果报错
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
安装openssl-devel即可
编译安装完
进入安装后的目录
[root@localhost bin]# cd /usr/local/apache [root@localhost apache]# ls bin build cgi-bin error htdocs icons include logs man manual modules [root@localhost apache]# cd bin/ [root@localhost bin]# ./apachectl
然后打开网页试试,输入你的虚拟机ip即可
如果不能打开,考虑如下
[root@localhost bin]# service iptables stop [root@localhost bin]# getenforce Enforcing [root@localhost bin]# setenforce 0 [root@localhost bin]# vim /etc/selinux/config
改为permissive
修改文件夹属性
[root@localhost bin]#chmod 755 /usr/local/apache/
再刷新试试
上述的好了,网页出现it works!后
我们可以把命令复制到/etc/init.d/httpd实现service调用,总之,一切为了实现之前使用httpd rpm包的那个习惯,嘿嘿
[root@localhost bin]# cp /root/httpd-2.4.12/build/rpm/httpd.init /etc/init.d/httpd [root@localhost 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
别急着启用服务
创建相应的目录
[root@localhost bin]# mkdir /var/run/httpd/
为了使用httpd -t等命令,修改~/.bash_profile
修改为PATH=$PATH:$HOME/bin:/usr/local/apache/bin
[root@localhost bin]# vim ~/.bash_profile [root@localhost bin]# source ~/.bash_profile [root@localhost bin]# httpd -t Syntax OK
在/etc/httpd/httpd.conf加上这行
PidFile "/var/run/httpd/httpd.pid"
为log文件创建符合链接
[root@localhost bin]# ln -s /usr/local/apache/logs/* /var/log/httpd/
然后重启服务看是否ok
如果不行请查看日志文件等
[root@localhost bin]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
如果不能重启,比如这个错误
Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
[FAILED]
[root@testA bin]# service httpd stop
Stopping httpd: [FAILED]
这时候去找httpd.pid文件即可
把/usr/local/apache/logs/httpd.pid 移到/var/run/httpd/下即可
然后再次查看网页是否正常,最终搭建最新httpd2.4.12的任务已经完成!