CentOS 6编译httpd-2.4.10

前提:

安装环境:CentOS 6.7

apr相关包:apr-1.5.0.tar  apr-util-1.5.3.tar

httpd包:httpd-2.4.10.tar 

一、CentOS 6编译httpd-2.4前期配置

  1.apr: apache portableruntimeapache可移植环境

      CentOS 6:默认:apr-1.3.9,apr-util-1.3.9版本

      但是httpd2.4依赖于较新版本的aprapr-1.4+,apr-util-1.4+, [apr-iconv](可选),需编译安装

      aprapr-util版本无需一致

  2.所需开发环境包组和开发程序包 

  # yum  install -y  "DevelopmentTools" "Server Platform Development"

  # yum  install -y  pcre-devel 

二、编译安装1.4+版的apr和apr-util

  1.编译安装apr-1.5.0.tar

      [root@localhosttmp]# tar xf apr-1.5.0.tar.bz2

      [root@localhosttmp]# cd apr-1.5.0

      [[email protected]]# ./configure --prefix=/usr/local/apr

      [[email protected]]# make -j 4 && make install 

  2.编译安装apr-util-1.5.3.tar

      [root@localhosttmp]# tar xf apr-util-1.5.3.tar.bz2

      [root@localhosttmp]# cd apr-util-1.5.3

      [[email protected]]# ./configure --prefix=/usr/local/apr-util --with=/usr/local/apr

      [[email protected]]# make -j 4 && make install

  注意:编译安装时候要指明所编译需要的安装包,否则会找系统的开发包作为依赖安装包 

三、编译启动httpd-2.4服务

  1.编译httpd-2.4.10.tar

        [root@localhosttmp]# tar xf httpd-2.4.10.tar.bz2

        [root@localhosttmp]# cd httpd-2.4.10

        [root@localhosttmp]# ./configure --prefix=/usr/local/apache24 --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

        [root@localhosttmp]# make -j  4

        [root@localhosttmp]# make install

安装选项说明:

      /usr/local/apache24/build/config.nice:记录了安装时候所执行的命令

 --prefix=/usr/local/apache24

指定安装路径

--sysconfdir=/etc/httpd24

更改定义配置文件的安装路径,不指明就在安装路径下

--enable-so

支持DSO机制

 --enable-ssl

支持ssl功能

--enable-cgi

支持cgi机制

--enable-rewrite

支持URL重写

--with-zlib

依赖于Zlib提供压缩库实现页面压缩

 --with-pcre

支持pcre扩展的模式,更为强大的正则表达式功能

--with-apr=/usr/local/apr

依赖于指定路径的apr

--with-apr-util=/usr/local/apr-util

依赖于指定路径的apr-util

 --enable-modules=most

启用模块,可以给模块列表,可以most大多数常用模块,也可以All

 --enable-mpms-shared=all

将所有的MPM模块编译出来

--with-mpm=prefork

指定启动时默认的MPM模块

 

  2.自带启动脚本:apachectl

    (1)方法一:手动指明路径启动

          因为编译安装,所以启动服务需指定具体路径/usr/local/apache24/bin/apachectl start

    (2)方法二:更改环境变量直接手动绝对路径

            1) # vim /etc/profile.d/httpd.sh

                    exportPATH=/usr/local/apache24/bin:$PATH

            2) # apachectl start

    (3)方法三:开机启动脚本

  # cd  /etc/rc.d/init.d/

  # vim  httpd24

  # chkconfig --add httpd24

  #service httpd24 start

=================================CentOS 6 服务脚本============================================

#!/bin/bash

#

# httpd        Startup script for the Apache HTTPServer

#

# chkconfig: - 85 15

# description: TheApache HTTP Server is an efficient and extensible  \

#              server implementing the current HTTPstandards.

# processname: httpd

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

# config:/etc/sysconfig/httpd

# pidfile:/var/run/httpd/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: TheApache HTTP Server is an extensible server

#  implementing the current HTTP standards.

### END INIT INFO

 

# Source functionlibrary.

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

 

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

        . /etc/sysconfig/httpd

fi

 

# Start httpd in theC locale by default.

HTTPD_LANG=${HTTPD_LANG-"C"}

 

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

# mod_ssl needs apass-phrase from the user.

INITLOG_ARGS=""

 

# SetHTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server

# with thethread-based "worker" MPM; BE WARNED that some modules may not

# work correctlywith a thread-based MPM; notably PHP will refuse to start.

 

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

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

httpd=/usr/local/apache/bin/httpd

prog=httpd

pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}

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

RETVAL=0

STOP_TIMEOUT=${STOP_TIMEOUT-10}

 

# The semantics ofthese two functions differ from the way apachectl does

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

# when not runningis also a failure.  So we just do it theway init scripts

# are expected tobehave here.

start() {

        echo -n $"Starting $prog: "

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

        RETVAL=$?

        echo

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

        return $RETVAL

}

 

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

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

# httpd parent toSIGKILL any errant children.

stop() {

echo-n $"Stopping $prog: "

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

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 toconfiguration syntax error"

        failure $"not reloading $httpd dueto 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 werecalled.

case "$1"in

  start)

start

;;

  stop)

stop

;;

  status)

        status -p ${pidfile} $httpd

RETVAL=$?

;;

  restart)

stop

start

;;

  condrestart|try-restart)

ifstatus -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

相关推荐