centos6.9编译安装Apache httpd 2.4.27

Apache httpd 2.4.27是Apache httpd 的最新一个版本,在centos6上通过yum安装的默认是httpd 2.2.15,相对来说相差了好几个大版本。为了使用一些新特性,下面我们在centos6.9上试着安装最新版 Apache httpd 2.4.27版本。

一、检查安装环境

1、centos6.9 、Apache httpd 2.4.27的源码包,apr相关软件包等,
2、检查是否安装过httpd包。

[root@centos6 ~]#rpm -qa httpd* 
httpd-2.2.15-59.el6.centos.x86_64
httpd-tools-2.2.15-59.el6.centos.x86_64
 注:这里显示已经装过httpd2.2.15的包了

为了不影响编译安装 Apache httpd 2.4.27我们最好卸载掉已安装过的httpd的httpd-2.2.15相关包。

[root@centos6 ~]#yum -y remove httpd*
....
===============================================================================================================================================================================================
 Package                                  Arch                           Version                                        Repository                                                        Size
===============================================================================================================================================================================================
Removing:
 httpd                                    x86_64                         2.2.15-59.el6.centos                           @anaconda-CentOS-201703281317.x86_64/6.9                         3.0 M
 httpd-tools                              x86_64                         2.2.15-59.el6.centos                           @anaconda-CentOS-201703281317.x86_64/6.9                         138 k
Removing for dependencies:
 gnome-user-share                         x86_64                         2.28.2-3.el6                                   @anaconda-CentOS-201703281317.x86_64/6.9                         1.1 M

Transaction Summary
===============================================================================================================================================================================================
...
Removed:
 httpd.x86_64 0:2.2.15-59.el6.centos                                                         
 httpd-tools.x86_64 0:2.2.15-59.el6.centos                                                        
...
Complete!
[root@centos6 ~]#rpm -qa httpd*
[root@centos6 ~]#
已成功卸载。

二、安装开发包组、apr等相关包

1、获取Apache httpd 2.4.27源码包。
可到Apache官网下载最新版本http://www.apache.org/,如果一下没有找到安装包,可直接输入http://httpd.apache.org/可跳转到下载页面。

centos6.9编译安装Apache httpd 2.4.27_第1张图片
centos6.9编译安装Apache httpd 2.4.27_第2张图片

上面两个可随便下载一个,这边下载的是httpd-2.4.27.tar.bz2版本。下载完导入到centos6.9中,或

[root@centos6 ~]#wget http://apache.fayea.com//httpd/httpd-2.4.27.tar.bz2
--2017-08-06 16:55:42--  http://apache.fayea.com//httpd/httpd-2.4.27.tar.bz2
Resolving apache.fayea.com (apache.fayea.com)... 119.6.242.165, 119.6.242.164
Connecting to apache.fayea.com (apache.fayea.com)|119.6.242.165|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6527394 (6.2M) [application/x-bzip2]
Saving to: ‘httpd-2.4.27.tar.bz2’

100%[=====================================================================================================================================================>] 6,527,394    109KB/s   in 77s    

2017-08-06 16:56:59 (83.0 KB/s) - ‘httpd-2.4.27.tar.bz2’ saved [6527394/6527394]

2、安装开发包组

[root@centos6 ~]#yum grouplist
 检查系统相关包组的安装,这里我们要安装的是 Development tools这个开发包组,如已安装则可略过。
[root@centos6 ~]#yum -y groupinstall  "Development tools"
...
Installed:
  autoconf.noarch 0:2.63-5.1.el6        automake.noarch 0:1.11.1-4.el6       bison.x86_64 0:2.4.1-5.el6     byacc.x86_64 0:1.9.20070509-7.el6                cscope.x86_64 0:15.6-7.el6        
  ctags.x86_64 0:5.8-2.el6              diffstat.x86_64 0:1.51-2.el6         doxygen.x86_64 1:1.6.1-6.el6   flex.x86_64 0:2.5.35-9.el6                       gcc.x86_64 0:4.4.7-18.el6         
  gcc-c++.x86_64 0:4.4.7-18.el6         gcc-gfortran.x86_64 0:4.4.7-18.el6   git.x86_64 0:1.7.1-8.el6       indent.x86_64 0:2.2.10-7.el6                     intltool.noarch 0:0.41.0-1.1.el6  
  libtool.x86_64 0:2.2.6-15.5.el6       patchutils.x86_64 0:0.3.1-3.1.el6    rcs.x86_64 0:5.7-37.el6        redhat-rpm-config.noarch 0:9.0.3-51.el6.centos   rpm-build.x86_64 0:4.8.0-55.el6   
  subversion.x86_64 0:1.6.11-15.el6_7   swig.x86_64 0:1.3.40-6.el6           systemtap.x86_64 0:2.9-7.el6  

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6               cpp.x86_64 0:4.4.7-18.el6                        gettext-devel.x86_64 0:0.17-18.el6           gettext-libs.x86_64 0:0.17-18.el6              
  kernel-devel.x86_64 0:2.6.32-696.el6            libgcj.x86_64 0:4.4.7-18.el6                     libgfortran.x86_64 0:4.4.7-18.el6            libstdc++-devel.x86_64 0:4.4.7-18.el6          
  mpfr.x86_64 0:2.4.1-6.el6                       perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6    perl-Compress-Zlib.x86_64 0:2.021-144.el6    perl-Error.noarch 1:0.17015-4.el6              
  perl-Git.noarch 0:1.7.1-8.el6                   perl-HTML-Parser.x86_64 0:3.64-2.el6             perl-HTML-Tagset.noarch 0:3.20-4.el6         perl-IO-Compress-Base.x86_64 0:2.021-144.el6   
  perl-IO-Compress-Zlib.x86_64 0:2.021-144.el6    perl-URI.noarch 0:1.40-2.el6                     perl-XML-Parser.x86_64 0:2.36-7.el6          perl-libwww-perl.noarch 0:5.833-5.el6          
  ppl.x86_64 0:0.10.2-11.el6                      systemtap-client.x86_64 0:2.9-7.el6              systemtap-devel.x86_64 0:2.9-7.el6          

Complete!
这里安装的包较多请稍等片刻。

3、还有Apache httpd 2.4.27,依赖于apr-1.4+, apr-util-1.4+,以上的包,不然安装时出错。(CentOS 6:默认:apr-1.3.9, apr-util-1.3.9)这里获取的是apr-1.5.2.tar.bz2与apr-util-1.5.4.tar.bz2
4.解压安装相应包依赖包。

[root@centos6 ~]#tar xvf httpd-2.4.27.tar.bz2
[root@centos6 ~]#tar xvf apr-1.5.2.tar.bz2
[root@centos6 ~]#tar xvf apr-util-1.5.4.tar.bz2
[root@centos6 ~]#mv apr-1.5.2 httpd-2.4.27/srclib/apr
[root@centos6 ~]#mv apr-util-1.5.4 httpd-2.4.27/srclib/apr-util
注:把apr-1.5.2.tar.bz2与apr-util-1.5.4.tar.bz2解压出来的包移动到httpd-2.4.27/srclib/
下是方便编译安装httpd-2.4.27时连apr与apr-util一块编译安装,这样就可以步骤繁琐,需同时编译安装apr与apr-util这两个包。
如没有搞清当然也可以自己手动分别编译安装。
[root@centos6 ~]#yum -y install pcre-devel openssl-devel
注:提前安装http所依赖的开发程序包。如现在没有安装可在编译安装时根据提醒一步一步安装。

4.补充(手动编译apr-1.5.2与apr-util-1.5.4)

[root@centos6 ~]#tar xvf apr-1.5.2.tar.bz2
[root@centos6 ~]#cd apr-1.5.2
[root@centos6 apr-1.5.2]#./configure --prefix=/app/apr
[root@centos6 apr-1.5.2]#make && make install
[root@centos6 apr-1.5.2]#cd 
[root@centos6 ~]#tar xvf apr-util-1.5.4.tar.bz2
[root@centos6 ~]#cd apr-util-1.5.4
[root@centos6 apr-util-1.5.4]#./configure --prefix=/app/apr-util
[root@centos6 apr-util-1.5.4]#make && make install

三、编译安装httpd-2.4.27

1.进入解压的目录中

[root@centos6 ~]# cd httpd-2.4.27

2.编译安装,时间稍长请耐心等待。

[root@centos6 httpd-2.4.27]#  ./configure --prefix=/app/httpd24 --enable-so --enable-ssl 
--enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr
 --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
注:--prefix=/app/httpd24 安装路径
--enable-so 允许运行时加载DSO模块
--enable-ssl 如果不加载将无法使用使用https
--enable-cgi 允许使用cgi脚本
--enable-rewrite 支持URL重写机制
--with-zlib 支持网络通用压缩库
--with-pcre 支持pcre
--with-included-apr  Use bundled copies of APR/APR-Util
--enable-modules=most 启用大多数常用的模块
--enable-mpms-shared=all 启用MPM所有支持的模式
--with-mpm=prefork 默认使用prefork模式
同时可以根据查询相关帮助自己自由添加选项
[root@centos6 httpd-2.4.27]#./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
......
[root@centos6 httpd-2.4.27]#make && make install

如果是自己手动编译的apr-1.5.2与apr-util-1.5.4 ,则要添加相应路径

[root@centos6 httpd-2.4.27]#  ./configure --prefix=/app/httpd24 
--with-apr=/app/apr --with-apr-util=/app/apr-util  --enable-so --enable-ssl 
--enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr 
--enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@centos6 httpd-2.4.27]#make && make install

这是差不多已经编译完成,后续进行相关设置。

四、后续相关设置

1.启动查看是否成功

[root@centos6 ~]#cd /app/httpd24/bin/
[root@centos6 bin]#./apachectl start 启动httpd
[root@centos6 ~]#ss -ntl 产看端口:80是否打开 这里已经打开了。
State       Recv-Q Send-Q                                                               Local Address:Port                                                                 Peer Address:Port 
LISTEN      0      128                                                                              *:41219                                                                           *:*     
LISTEN      0      128                                                                             :::35111                                                                          :::*     
LISTEN      0      128                                                                             :::111                                                                            :::*     
LISTEN      0      128                                                                              *:111                                                                             *:*     
LISTEN      0      128                                                                             :::80                                                                             :::*     
LISTEN      0      128                                                                             :::22                                                                             :::*     
LISTEN      0      128                                                                              *:22                                                                              *:*     
LISTEN      0      128                                                                      127.0.0.1:631                                                                             *:*     
LISTEN      0      128                                                                            ::1:631                                                                            :::*     
LISTEN      0      100                                                                            ::1:25                                                                             :::*     
LISTEN      0      100                                                                      127.0.0.1:25                                                                              *:*  

2.打开网页进行测试。

[root@centos6 ~]#iptables -F  关闭防火墙
[root@centos6 ~]#chkconfig iptables off  开机禁用防火墙
centos6.9编译安装Apache httpd 2.4.27_第3张图片

修改主页试下

[root@centos6 ~]#cd /app/httpd24/htdocs/ 安装时没有指定页面位置,默认安装在随主目录下的htdocs
[root@centos6 htdocs]#ls
index.html
[root@centos6 htdocs]#vim index.html 
[root@centos6 htdocs]#cat index.html 

hello world!

centos6.9编译安装Apache httpd 2.4.27_第4张图片

3.为httpd的相关控制脚本添加路径。

[root@centos6 ~]#vim /etc/profile.d/app.sh  
[root@centos6 ~]#cat !$
cat /etc/profile.d/app.sh
export PATH=/app/httpd24/bin:$PATH
[root@centos6 ~]#. /etc/profile.d/app.sh  这样就可不用进入/app/httpd24/bin目录下启用某个程序,下次开机也可以使用。

4.注册apache为系统服务

[root@centos6 ~]#cp /app/httpd24/bin/apachectl  /etc/init.d/httpd24
上面只是手动可启动,关闭,如需进行开机启动。
我们还需要个开机启动的模板来进行设置。
如下所示
[root@centos6 ~]scp /etc/init.d/httpd 192.168.18.130:/etc/init.d/ 
从别机考一份模板如下设置改动
[root@centos6 init.d]#vim httpd
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
[root@centos6 init.d]#chkconfig --add httpd 添加
[root@centos6 init.d]#chkconfig  httpd on   设置httpd开机启动
[root@centos6 init.d]#chkconfig --list          查看
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

5.向原有配置里添加httpd的man帮助

MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /app/httpd24/man  添加路径

到这里已经安装完毕!后续的设置根据需求进行设置。

如有不足请多多指教!

你可能感兴趣的:(centos6.9编译安装Apache httpd 2.4.27)