httpd2.4源码编译

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpd2.4源码编译相关的知识,希望对你有一定的参考价值。

系统版本:RedHat6.5

内核版本:2.6.32-431.el6.x86_64


1、安装httpd2.4版本的软件,首先需要安装apr和apr-util这两个软件包;

    注意:apr和apr-util的版本,必须在1.5以上,否则会报错

[[email protected] ~]# ls
apr-1.5.2.tar.gz  apr-util-1.5.4.tar.gz  httpd-2.4.16.tar.gz


2、编译安装apr:

[[email protected] ~]# tar zxf apr-1.5.2.tar.gz     
[[email protected] ~]# cd apr-1.5.2
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr  
    注释:--prefix=/usr/local/apr:安装路径为/usr/local/apr
[[email protected] apr-1.5.2]# make && make install

 编译安装完之后,用ls命令去/usr/local/apr目录下进行查看,确保它确实已经被安装了

[[email protected] apr-1.5.2]# ls /usr/local/apr/      
bin  build-1  include  lib


3、编译安装apr-util:

[[email protected] ~]# tar zxf 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/    
    注释:#--with-apr:告诉系统,apr在/usr/local/apr/下
[[email protected] apr-util-1.5.4]# make && make install

    同样,用ls命令查看/usr/local/apr-util/目录,确保apr-util确实已经被安装了;

[[email protected] apr-util-1.5.4]# ls /usr/local/apr-util/
bin  include  lib


4、编译安装httpd2.4

   编译前的预安装:

[r[email protected] ~]# tar zxf httpd-2.4.16.tar.gz 
[[email protected] ~]# cd httpd-2.4.16
[[email protected] httpd-2.4.16]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24
 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre 
 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-modules=most 
 --enable-mpms-shared=all --with-mpm=prefork
 注释:--sysconfdir=/etc/httpd24:配置文件在/etc/httpd24/目录下;
       --enable-so:开启共享对象,so(Shared Object);
       --enable-ssl:支持ssl,可以进行加密;
       --enable-cgi:启用CGI功能
       --enable-rewrite:启用重写
       --with-zlib:支持压缩传输
       --with-pcre:支持正则表达式
       --enable-mpms-shared=all:编译所有的mpm模块
       --enable-modules=most:安装所有常用的模块
       --with-mpm=prefork:默认启用mpm模块中的prefork
[[email protected] httpd-2.4.16]# make && make install
[[email protected] httpd-2.4.16]# ls /usr/local/apache/
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules

httpd2.4编译安装成功了,接下来就是一些收尾工作:

    1、将/usr/local/apache/bin/加入到系统的环境变量中:

[[email protected] httpd-2.4.16]# vim /etc/profile.d/apache.sh
export PATH=/usr/local/apache/bin:$PATH
[[email protected] httpd-2.4.16]# . /etc/profile.d/apache.sh


    2、将/usr/local/apache/include文件,链接到系统的默认安装目录:

[[email protected] httpd-2.4.16]# ln -sv /usr/local/apache/include/ /usr/include/httpd24
`/usr/include/httpd24‘ -> `/usr/local/apache/include/‘


   3、将/usr/local/apache/man文档加入man的配置文件当中

[[email protected] apache]# vim /etc/man.config 
MANPATH /usr/local/apache/man


    4、提供服务脚本

[[email protected] apache]# cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
[[email protected] apache]# vim /etc/rc.d/init.d/httpd24
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}


   5、修改配置文件

[[email protected] ~]# vim /etc/httpd24/httpd.conf
PidFile     "/var/run/httpd/httpd24.pid"    
ServerAdmin [email protected]    #该服务器的管理人员的邮箱


    6、验证配置文件的语法是否正确

[[email protected] apache]# httpd -t
Syntax OK


     7、将该服务将入到系统服务当中:

[[email protected] apache]# chkconfig --list httpd24
[[email protected] apache]# chkconfig httpd24 on
[[email protected] apache]# chkconfig --list httpd24
httpd24            0:off    1:off    2:on    3:on    4:on    5:on    6:off


    8、启动服务

[[email protected] apache]# service httpd24 start
Starting httpd:                                            [  OK  ]


    9、查看80端口是否被监听apache的服务进程是否启动:

[[email protected] apache]# ss -tnl
State       Recv-Q Send-Q     Local Address:Port     Peer Address:Port 
LISTEN          0   128          :::80            :::* 
[[email protected] apache]# ps aux | grep httpd
root      36271  0.0  0.4  72552  2016 ?      Ss   05:24   0:00 /usr/local/apache/bin/httpd
daemon    36273  0.0  0.2  72552  1392 ?      S    05:24   0:00 /usr/local/apache/bin/httpd
daemon    36274  0.0  0.2  72552  1392 ?      S    05:24   0:00 /usr/local/apache/bin/httpd
daemon    36275  0.0  0.2  72552  1392 ?      S    05:24   0:00 /usr/local/apache/bin/httpd
daemon    36276  0.0  0.2  72552  1392 ?      S    05:24   0:00 /usr/local/apache/bin/httpd
daemon    36277  0.0  0.2  72552  1392 ?      S    05:24   0:00 /usr/local/apache/bin/httpd


    10、本地访问,确保服务万无一失

[[email protected] apache]# curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>


本文出自 “心如止水” 博客,请务必保留此出处http://1005969720.blog.51cto.com/9082248/1744263

以上是关于httpd2.4源码编译的主要内容,如果未能解决你的问题,请参考以下文章

centos6.9源码编译httpd2.4

Linux源码安装httpd:Centos7

CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39

Linux源码编译安装apache httpd2.4.48

CentOS6.5下源码编译安装httpd2.4.23

CentOS6上编译安装httpd2.4