apache2.4.17 编译安装

准备安装包:

httpd-2.4.17.tar

apr-util-1.5.4.tar

apr-1.5.2.tar

httpd-2.4依赖于较高版本的apr(1.5以上)和apr-util

apr: apache portable runtime(移植运行)是一个让api,让apache能够跨平台的工具,是一个底层库

apache支持正则表达式依赖于pcre(正则表达式函数库),安装其开发包pcre-devel即可

下载地址:

http://apr.apache.org/

http://httpd.apache.org/download.cgi

安装步骤:

1. 先安装编译开发环境和一些必须的包

    yum install cmake #编译时要用到
    yuminstall pcre-devel #使用pcre正则表达式要用到
    yuminstall gcc gcc-c++ #编译工具

2. 安装apache服务器

(a)  解压httpd安装包

    tar xvzf httpd-2.4.17.tar.gz

(b) httpd需要apr和apr-util,解压后放在已解压的httpd-2.4.17/srclib目录下,并把目录名字分别改为apr和apr-util。后

面编绎要用到--with-included-apr选项,安装apr和apr-util库

    tar xvzf apr-1.5.2.tar.gz -C httpd-2.4.17/srclib
    tar xvzf apr-util-1.5.4.tar.gz -C httpd-2.4.17/srclib

(c)  开始安装apache,根据需要调整所需选项

./configure --prefix=/usr/local/apache2--with-included-apr --sysconfdir=/etc/httpd2.4/conf/ --enable-so--enable-rewrite --with-pcre --enable-modules=most --with-zlib --enable-cgi
            make && make install

各项参数含义:

--prefix=/usr/local/apache  #指定安装目标路径

--sysconfdir=/etc/httpd2.4     #指定配置文件安装位置

--enable-so                 #支持动态共享模块

--enable-cgi                #启用支持cgi

--enable-rewirte            #支持URL重写

--with-zlib                #网络上发送数据报文时通用压缩库的API

--enable-ssl                #启用支持ssl

--with-apr=/usr/local/apr   #指定依赖包apr路径

--with-apr-util=/usr/local/apr-util  #指定依赖包apr-util路径

--enable-modules=all|most            #安装全部模块或大多数模块

--enable-mpms-shared=all             #支持全部多道处理方式

--with-event:                        #指定默认使用event

--enable-cgid :启用支持带线状图形的CGI脚本 MPMs

(d)  编辑/usr/local/apache2/conf/httpd.conf 修改用户名和组名为apache,没有的话就创建一个。默认用户和组为

daemon

    vim /usr/local/apache2/conf/httpd.conf
    Userdaemon        -> User apache
    Groupdaemon       -> Group apache

(e) 启动测试

    /usr/local/apache2/bin/apachectl start
    curl http://localhost

显示<html><body><h1>Itworks!</h1></body></html> 即为成功启动

3. 后续的配置

(a) 导出头文件

    ln -sv /usr/local/apache2/include/ /usr/include/httpd
    "/usr/include/httpd" -> "/usr/local/apache2/include/"

(b) 导出库文件(没有生成库文件)

(c) 导出man手册

vim/etc/man.conf

添加 MANPATH /usr/local/apache2/man

或者直接使用命令:man -M /usr/local/apache2/man apache

(d) 添加PATH路径

vim/etc/profile.d/httpd2.4.sh

添加  exportPATH=/usr/local/apache2/bin:$PATH

(e) 创建启动服务和开机启动

修改/etc/httpd2.4/conf/httpd.conf添加一行PidFile “/var/run/httpd2.4.pid”

然后修改/etc/init.d/httpd,以下3行改为相对应的地址

apachectl=/usr/local/apache2/bin/apachectl

httpd=${HTTPD-/usr/local/apache2/bin/httpd}

pidfile=${PIDFILE-/var/run/httpd2.4.pid}

service httpd start 即可启动

注意:

编译安装2.4版本的主配置文件/etc/apache2.4没有像yum安装的2.2版本的主配置文件/etc/httpd/conf/httpd.conf

一样分为三段,分段配置文件为/etc/apache2.4/extra/*.conf

httpd-vhost.conf:配置虚拟主机

httpd-ssl.conf:配置ssl

httpd-mpm.conf:配置MPM

(f) 日志轮循设置

复制安装包中 /httpd-2.4.17/build/rpm/httpd.logrotate到 /etc/logrotate.d/ 目录 

httpd.logrotate中 /var/log/httpd/*log 可以更改为自己需要的路径,例:/usr/local/apache2/logs/*log

执行logrotate -d来dbug下有没错误

logrotate -d /etc/logrotate.conf

执行logrotate 使日志轮循生效

logrotate /etc/logrotate.conf

至此apache安装完成。

4. httpd-2.4新特性

(a) MPM支持在运行时装载:

--enable-mpms-shared=all(编译所有支持的MPM) --with-mpm=event(设定默认启用的MPM)

(b)支持event

(c)  异步读写

(d)  在每模块及每目录上指定日志级别

(e)  每请求配置:<If>,<Elseif>

(f) 增强版的表达分析器

(g)  毫秒级的keepalivetimout

(h)  基于FQDN的虚拟主机不再需要NameVirtualHost指令

(i)   配置文件支持使用自定义变量

新增了一些模块:mod_proxy_fcgi,mod_ratelimit,mod_request,mod_remoteip

对于基于IP的访问控制做了修改:不再支持用order,allow,deny这些机制而是统一使用require进行

注意:

1. 访问控制参数的写法:

原本使用 Order Deny / Allow 的方式,改用 Require

require all granted 允许所有访问

require all denied  拒绝所有访问

仅允许IP为192.168.1.1的主机访问

<RequireAll>

require all granted

require ip 192.168.1.1 (也可以写成网段)

</RequireAll>

禁止192.168.1.2的主机访问,其他的都允许

<RequireAll>

require all granted

require not ip 192.168.1.2

</RequireAll>

2. Namevirtualhost参数被移除

3. RewriteLogLevel 参数改为 logLevel

4. 压缩使用mod_deflate 外, Apache 2.4 中还需要mod_filter

SSL开启mod_ssl 外,Apache 2.4 中还需要mod_socache_shmcb

附上原有yum安装后,经修改的/etc/init.d/httpd 脚本,没装过httpd的可以直接使用:

1#!/bin/bash

2 #

3 #httpd        Startup script for theApache HTTP Server

4 #

5 #chkconfig: - 85 15

6 #description: The Apache HTTP Server is an efficient and extensible  \

7#              server implementing thecurrent HTTP standards.

8 #processname: httpd

9 #config: /etc/httpd/conf/httpd.conf

10 #config: /etc/sysconfig/httpd

11 #pidfile: /var/run/httpd/httpd.pid

12 #

13### BEGIN INIT INFO

14 #Provides: httpd

15 #Required-Start: $local_fs $remote_fs $network $named

16 #Required-Stop: $local_fs $remote_fs $network

17 #Should-Start: distcache

18 #Short-Description: start and stop Apache HTTP Server

19 #Description: The Apache HTTP Server is an extensible server

20#  implementing the current HTTPstandards.

21 ###END INIT INFO

22

23 #Source function library.

24 ./etc/rc.d/init.d/functions

25

26if [ -f /etc/sysconfig/httpd ]; then

27         . /etc/sysconfig/httpd

28fi

29

30 #Start httpd in the C locale by default.

31HTTPD_LANG=${HTTPD_LANG-"C"}

32

33 #This will prevent initlog from swallowing up a pass-phrase prompt if

34 #mod_ssl needs a pass-phrase from the user.

35INITLOG_ARGS=""

36

37 #Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

38 #with the thread-based "worker" MPM; BE WARNED that some modules maynot

39 #work correctly with a thread-based MPM; notably PHP will refuse to start.

40

41 #Path to the apachectl script, server binary, and short-form for messages.

42#apachectl=/usr/sbin/apachectl

43 apachectl=/usr/local/apache/bin/apachectl

44 httpd=${HTTPD-/usr/local/apache/bin/httpd}

45prog=httpd

46pidfile=${PIDFILE-/var/run/httpd/httpd2.4.pid}

47 lockfile=${LOCKFILE-/var/lock/subsys/httpd}

48RETVAL=0

49 STOP_TIMEOUT=${STOP_TIMEOUT-10}

50

51 #The semantics of these two functions differ from the way apachectl does

52 #things -- attempting to start while running is a failure, and shutdown

53 #when not running is also a failure.  Sowe just do it the way init scripts

54 #are expected to behave here.

55start() {

56        echo -n $"Starting $prog: "

57        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

58        RETVAL=$?

59        echo

60        [ $RETVAL = 0 ] && touch ${lockfile}

61        return $RETVAL

62 }

63

64 #When stopping httpd, a delay (of default 10 second) is required

65 #before SIGKILLing the httpd parent; this gives enough time for the

66 #httpd parent to SIGKILL any errant children.

67stop() {

68        echo -n $"Stopping $prog: "

69        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd

70        RETVAL=$?

71        echo

72        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

73 }

74reload() {

75    echo -n $"Reloading $prog: "

76    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then

77         RETVAL=6

78        echo $"not reloading due to configuration syntax error"

79        failure $"not reloading $httpd due to configuration syntaxerror"

80    else

81         # Force LSB behaviour from killproc

82        LSB=1 killproc -p ${pidfile} $httpd -HUP

83        RETVAL=$?

84        if [ $RETVAL -eq 7 ]; then

85            failure $"httpd shutdown"

86        fi

87    fi

88    echo

89 }

90

91 #See how we were called.

92case "$1" in

93  start)

94        start

95        ;;

96  stop)

97        stop

98        ;;

99  status)

100        status -p ${pidfile} $httpd

101        RETVAL=$?

102        ;;

103  restart)

104        stop

105        start

106        ;;

107  condrestart|try-restart)

108        if status -p ${pidfile} $httpd >&/dev/null; then

109                 stop

110                 start

111        fi

112        ;;

113  force-reload|reload)

114        reload

115        ;;

116  graceful|help|configtest|fullstatus)

117        $apachectl [email protected]

118        RETVAL=$?

119        ;;

120  *)

121        echo $"Usage: $prog{start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"

122        RETVAL=2

123 esac

124

125 exit $RETVAL

时间: 2024-08-02 18:08:28

apache2.4.17 编译安装的相关文章

apache2.4.27编译安装

#apache 2.4编译安装# 第1步:安装gcc编译器. yum  install  -y   gcc   gcc-c++   openssl-devel   pcre  pcre-devel 说明:openssl-devel是让apache支持ssl安全套接字功能. 因为rewirte重写功能需要pcre-devel支持.所以要安装pcre和pcre-devel软件. PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的

mysql-5.6.17编译安装和常见问题

mysql-5.6.17编译安装和常见问题 以前用的是MySQL的5.1版本,且使用的是免编译的包,安装简单.最近换了5.6版本的MySQL,安装过程出现了不少问题. 1. 卸载原来版本的MySQL 检查已经安装的MySQL: # rpm -qa |grep mysql 检查到mysql以后卸载: # rpm -e mysql //卸载mysql,加--nodeps可以强制卸载 2. 下载MySQL # cd /usr/local/mysql # wget http://dev.mysql.co

Mysql 5.7.17 编译安装

环境准备: mysql 安装包:mysql-5.7.17.tar.gz yum源: [[email protected]_1 ~]# cat /etc/yum.repos.d/server.repo [local] name=local baseurl=file:///mnt/cdrom gpgcheck=0 enabled=1 [[email protected]_1 ~]# 系统版本: [[email protected]_1 ~]# cat /etc/redhat-release Cent

apache-2.4.x 编译安装方法

apache-2.4.x 编译安装方法 作者:朱 茂海 /分类:Apache 字号:L M S apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr. 1.下载软件 cd /tmp wget http://mirrors.axint.net/apache//httpd/httpd-2.4.2.tar.gz wget http://mirrors.axint.net/apache//apr/apr-1.

Apache2.4.25编译安装之虚拟主机For Centos7

安装之前准备: 配置好防火墙,selinux,时区. 检查系统是否安装了httpd服务 yum install gcc gcc-c++ zlib-devel 下载软件,pcre,apr,apr-util,apache wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz wget http://mirror.bit.edu.cn/

mysql-5.6.17编译安装脚本

#!/bin/bash#Date:2017-04-21#Author:Allen_Jol#mysql-5.6.17_v2.0 #卸载自带的mysql-libsrpm -e --nodeps mysql-libs #安装所需软件依赖yum -y install make gcc gcc-c++ ncurses ncurses-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel MDIR=/usr/local/srccd $MDIR

Linux系统下Apache2.4.17的安装过程

Linux系统下安装Apache Server2.4.17.还是先声明一下,Linux命令我不进行讲解,因为我不是讲Linux命令的.有需要注意的地方,我会上图,没什么值得的注意的地方,我就不上图了.还有就是怎样将压缩包上传到Linux系统中去,我不进行讲解,还是那句话:网上教程太多了!最后,确保你的Linux是连网的! 工具/原料 Linux系列系统 Apache Server2.4.17源码包 APR源码包 APR-Util源码包 PCRE源码包 方法/步骤 1 首先,秉承我一贯的风格,来看

linux企业常用服务---编译安装lamp及优化

安装注意: 本地光盘得挂载好需要安装一些依赖包及充当yum源: 源码包存放的位置与脚本中要一致: 使用脚本形式安装,安装前先看脚本内容,稍作调整后再进行安装: 安装mcrypt支持,安装的顺序必须libmcrypt-->mhash-->mcrypt,每安装都必须ln链接到系统库中: 防火墙和selinux先关闭最后在打开. 需提前准备好以下源码包及yum的配置 源码包: httpd-2.2.17.tar.gz    ##apache的httpd                        

Apache2.2.17源码编译安装以及配置虚拟主机

WEB服务(一) 理论部分: Apache服务主要是多个服务的组合,名称来自于A Patchy Server 意思是基于原有的WEB程序的代码修改(补丁)后形成的服务器程序 1995年发布第一个版本1.0一直有Apache Group负责该项目的维护和管理1999年成立了Apache的软件基金会官方网站是http://www.apache.org/ ASF是非盈利性组织,Apache HTTP Server 就是旗下最著名的软件项目之一 跨平台应用(支持多数操作系统) 支持多字符集 Apache