一、 httpd 2.4的新特

1) MPM支持运行时装载
  --enable-mpms-shared=all --with-mpm=prefork|worker|event
2) 支持event MPM
3) 异步读写支持
4) 支持每模块及每目录分别使用不同的日志级别
5) 支持per-request(即支持<If>, <ElseIf>, and <Else>条件判断)
6) 增强版的表达式分析器;
7) 支持毫秒级keepalive timeout;
8) 基于FQDN(域名)的虚拟主机不再需要NameVirtualHost;
9) 支持用户使用自定义变量;
    新增一些模块:mod_proxy_fcgi, mod_ratelimit, mod_request, mod_remoteip
    修改了一些配置机制:不再支持使用order, allow, deny来实现基于IP的访问控制;

二、 系统环境

CentOS6.4 x86_64位 采用最小化安装,系统经过了基本优化  1G内存,1核cpu

selinux为关闭状态,iptables关闭状态

三、编译准备

    1. 安装相关依赖工具

  # yum  install -y gcc gcc-c++ wget expat-devel zlib-devel zlib openssl openssl-devel libxml2-devel

2. 下载相关软件包

# wget http://www-us.apache.org/dist//httpd/httpd-2.4.37.tar.gz

# wget -c http://www-us.apache.org/dist//apr/apr-1.6.5.tar.gz

# wget -c http://www-us.apache.org/dist//apr/apr-util-1.6.1.tar.gz

# wget https://ftp.pcre.org/pub/pcre/pcre-8.32.tar.gz

     3. 编译安装依赖包

# cd /usr/local/src

安装apr:

  # tar xf apr-1.6.5.tar.gz

   # cd  apr-1.6.5

   # ./configure --prefix=/usr/local/apr

   # make && make install

   安装apr-util:

  # tar xf apr-util-1.6.1.tar.gz

   # cd  apr-util-1.6.1

   # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

   # make && make install

安装pcre:

  # tar -xf pcre-8.32.tar.gz

   # cd pcre-8.32

   # ./configure --prefix=/usr/local/pcre

   # make && make install

        注意:如果你下载pcre2的话,apache2.4会出现编译不通过,建议不要使用pcre2.

四、编译安装httpd

# tar -xf httpd-2.4.37.tar.gz

# cd httpd-2.4.37

开始配置:

./configure \
--prefix=/usr/local/httpd24 \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--enable-deflate \
--enable-expires \
--with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most \
--enable-mpms-shared=all \
--with-mpm=prefork/event/worker

注意:如果是复制粘贴配置,要注意每行结尾\之前只能有一个空格,之后不能有空格

参数含义:

./configure \
--prefix=/usr/local/httpd24 \                 # 指定安装路径
--sysconfdir=/etc/httpd24 \                  # 指定配置文件路径
--enable-so \                # 启用动态模块加载
--enable-ssl \             # 启用ssl加密传输
--enable-cgi \                                       # 允许使用cgi脚本
--enable-rewrite \                                 # 启用url重写功能
--with-zlib \                                           # 支持数据包压缩
--enable-deflate \                                 # 支持网页压缩
--enable-expires \                                # 支持网页缓存
--with-pcre=/usr/local/pcre \                 # pcre安装路径
--with-apr=/usr/local/apr \                     # apr安装路径
--with-apr-util=/usr/local/apr-util \          #  apr-util 安装路径
--enable-mods-shared=most \              # 动态的编译进来大多数的模块
--enable-mpms-shared=all \                  # 动态编译MPM所有支持的模式 
--with-mpm=prefork/event/worker         # 默认加载使用的mpm

编译并安装:

# make && make install

五、安装后配置

1. 将apache二进制程序目录加入环境变量PATH

    # echo 'export PATH=/usr/local/http24/bin:$PATH' >>/etc/profile

    # source  /etc/profile

   2. 链接方式输出头文件

    # ln -sv /usr/local/httpd24/include /usr/include/apache

   3. 添加man帮助手册

    编辑man.config文件,找到 MANPATH /usr/X11R6/man 这一行,在下面添加如下一行

    MANPATH /usr/local/httpd24/man

    4.添加启动脚本

    a. 系统自带脚本

     # cp /usr/local/httpd24/bin/apachectl /etc/init.d/httpd

    vi打开,添加两行   

    # chkconfig: 35 85 15
    # description: The Apache HTTP Server

      b. 相关启动脚本

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: - 85 15

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

#              server implementing the current HTTP standards.

# processname: httpd

# config: /etc/httpd/httpd.conf

# pidfile: /usr/local/httpd24/logs/httpd.pid

#

### BEGIN INIT INFO

# Provides: httpd

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

# Required-Stop: $local_fs $remote_fs $network

# Should-Start: distcache

# Short-Description: start and stop Apache HTTP Server

# Description: The Apache HTTP Server is an extensible server

#  implementing the current HTTP standards.

### END INIT INFO

# Source function library.

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

if [ -f /etc/httpd ]; then

. /etc/httpd

fi

# Start httpd in the C locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}

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

# mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS=""

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

apachectl=/usr/local/httpd24/bin/apachectl

httpd=/usr/local/httpd24/bin/httpd

prog=httpd

pidfile=${PIDFILE-/usr/local/httpd24/logs/httpd.pid}

lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

RETVAL=0

STOP_TIMEOUT=${STOP_TIMEOUT-10}

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

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

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

# are expected to behave here.

start() {

echo -n $"Starting $prog: "

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

RETVAL=$?

echo

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

return $RETVAL

}

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

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

# httpd parent to SIGKILL any errant children.

stop() {

status -p ${pidfile} $httpd > /dev/null

if [[ $? = 0 ]]; then

echo -n $"Stopping $prog: "

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

else

echo -n $"Stopping $prog: "

success

fi

RETVAL=$?

echo

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

}

reload() {

echo -n $"Reloading $prog: "

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

RETVAL=6

echo $"not reloading due to configuration syntax error"

failure $"not reloading $httpd due to configuration syntax error"

else

# Force LSB behaviour from killproc

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

RETVAL=$?

if [ $RETVAL -eq 7 ]; then

failure $"httpd shutdown"

fi

fi

echo

}

# See how we were called.

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status -p ${pidfile} $httpd

RETVAL=$?

;;

restart)

stop

start

;;

condrestart|try-restart)

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

stop

start

fi

;;

force-reload|reload)

reload

;;

graceful|help|configtest|fullstatus)

$apachectl $@

RETVAL=$?

;;

*)

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

RETVAL=2

esac

exit $RETVAL

c. 开机启动httpd服务

# chkconfig --add httpd

# chkconfig httpd on

# chkconfig --list httpd

    5. 测试安装

   打开浏览器,在浏览器输入centos主机的ip地址,或者本机curl,检测安装是否成功。

# curl localhost

<html><body><h1>It works!</h1></body></html>

六、可能遇到的问题

    1. 启动报错

启动时会出现“AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message”这样的报错,只需要编辑http.conf文件,找到#ServerName www.example.com:80这一行,在下面添加 如下一行,然后重启apache

    # vim /etc/httpd/httpd.conf

ServerName localhost:80

取消以下注释行,开启httpd状态监控

Include /etc/httpd24/extra/httpd-info.conf

2.

  参数方面没问题,然后我开始一个个去掉参数:发现问题出现在--enable-cgi \这个上面,故这个有问题。
  最后对调参数,参数放在倒数第二个再次环境测试!结果发现通过了!,其实问题出现在\后面有空格,去掉空格再编译

3. 

这个提示是openssh版本太低,yum install -y openssl openssl-devel 解决

  4.

  

    

缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持。

安装libxml2-devel包

[root@localhost ~]# yum install -y libxml2-devel

删除apr-util安装目录,并重新编译安装

[root@localhost ~]# rm -rf /usr/local/apr-util
[root@localhost ~]# cd /usr/local/src/apr-util-1.6.1 # 这一步很重要,必须清除之前配置时的缓存
[root@localhost apr-util-1.6.1]# make clean # 源码安装三步走
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install

重新编译安装httpd

# 同样要清理之前的缓存十分重要
[root@localhost src]# cd /usr/local/src/httpd-2.4.28
[root@localhost httpd-2.4.28]# make clean
[root@localhost httpd-2.4.28]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.28]# make
# 这时make没报错了 [root@localhost httpd-2.4.28]# make install
注:此处参考http://blog.51cto.com/castiel/2051440

CentOS 6.5 编译安装Apache2.4的更多相关文章

  1. CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25

    所需源码包: /usr/local/src/Apache-2.2.25/httpd-2.2.25.tar.gz 编译安装 Apache2.2.25 #切换到源码目录 cd /usr/local/src ...

  2. CentOS6.3 编译安装LAMP(2):编译安装 Apache2.4.6

    Apache官方说: 与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量.更好地支持云计算.利用更少的内存处理更多的并发等.除此之外,还包括性能提升.内 ...

  3. centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8

    以虚拟机VirtualBox 版本是4.1.20(内存设置为512M,centos安装是文本模式下安装),全新以最小化包安装了32位的 CentOS6.3系统,作为本地web环境,上次讲了在windo ...

  4. CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27

    CentOS 6.8编译安装httpd2.2.31+MySQL5.6.31+PHP5.3.27   说明:   操作系统:CentOS 6.8 32位 准备篇: 一.系统约定    软件源代码包存放位 ...

  5. Ubuntu 16.04下编译安装Apache2.4和PHP7结合

    Ubuntu 16.04下编译安装Apache2.4和PHP7结合,并安装PDOmysql扩展. 1.编译安装apache2.4.20 1 第一步: ./configure --prefix=/usr ...

  6. CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14

    准备篇: CentOS 7.0系统安装配置图解教程 http://www.osyunwei.com/archives/7829.html 一.配置防火墙,开启80端口.3306端口 CentOS 7. ...

  7. centos 7.0 编译安装php 7.0.3

    php下载页面 http://cn2.php.net/downloads.php 7.0.3多地区下载页面 http://cn2.php.net/get/php-7.0.3.tar.gz/from/a ...

  8. CentOS 6.6编译安装Nginx1.6.2+MySQL5.6.21+PHP5.6.3

    http://www.osyunwei.com/archives/8867.html 一.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables #编辑防火墙配置 ...

  9. CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13

    CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.132013-10-24 15:31:12标签:服务器 防火墙 file 配置文件 written 一.配置好I ...

随机推荐

  1. 使用MEMCACHED实现缓存

    什么是memcached Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga Interactive公司的Brad Fit ...

  2. 机器学习python常用模块

    .Pickle模块 打包,解压训练模型 .pysnooper 调试打印日志

  3. Java并发编程实战 第8章 线程池的使用

    合理的控制线程池的大小: 下面内容来自网络.不过跟作者说的一致.不想自己敲了.留个记录. 要想合理的配置线程池的大小,首先得分析任务的特性,可以从以下几个角度分析: 任务的性质:CPU密集型任务.IO ...

  4. 通过telnet自动下载cfg配置文件

    源代码如下: import telnetlib import logging import datetime import csv import time def telnetfunc(enbid, ...

  5. WPF界面控件Telerik UI for WPF发布R2 2019 SP1|实现新的属性

    Telerik UI for WPF拥有超过100个控件来创建美观.高性能的桌面应用程序,同时还能快速构建企业级办公WPF应用程序.UI for WPF支持MVVM.触摸等,创建的应用程序可靠且结构良 ...

  6. 微信小程序-饮食日志_开发记录01

    今天主要了解微信小程序的框架结构以及环境部署等. 小程序的框架主要分为: js.json.wxss.wxml等 和java web的内容相似,主要了解内部代码的使用情况和语言方式. 主要写了页面的框架 ...

  7. 动态树(Link-Cut-Tree)简单总结(指针版本)

    Link-Cut-Tree(动态树 LCT) 1.定义 1. 偏爱子节点: 一颗子树内最后访问的点若在该子树根节点 X 的某个儿子节点 P 的子树中,则称 P 为 X 的偏爱子节点. 偏爱边:连向偏爱 ...

  8. mysql参数sql_log_bin配置

    mysql参数sql_log_bin配置 如果想在主库上执行一些操作,但不复制到slave库上,可以通过修改参数sql_log_bin来实现.比如说,这里模拟主从同步复制异常. 还有一种场景,就是导入 ...

  9. linux-awk-3

    awk 基础语法 Awk –Fs '/pattern/ {action}' input-file (或者) Awk –Fs '{action}' input-file -F 为字段分界符.如果不指定, ...

  10. mysql LAST()函数 语法

    mysql LAST()函数 语法 作用:返回指定的字段中最后一个记录的值. 语法:SELECT LAST(column_name) FROM table_name 注释:可使用 ORDER BY 语 ...