Building Apache2 From Source on Linux (Redhat 8)

Building Apache2 From Source on Linux (Redhat 8)

This page shows the steps used to compile and build apache2 on linux. The example uses Apache 2.0.46 on Redhat 8 using a bash shell, you will need gcc installed. You can find Apache's install instructionshere

Zrinity provides email marketing appliances and software to large businesses and advertising agencies. Zrinity's email delivery systems are very reliable and high-speed.

Downlaod the latest tar.gz file for apache2

You can download it from httpd.apache.org.

Login as root

You can type su to switch to root. Then run source /etc/profile to ensure that your path environment variable is setup properly.

Extract the source code

In this example we extract the source code to a directory under /usr/local/src/

 
 cp httpd-2.0.46.tar.gz /usr/local/src

 cd /usr/local/src

 gunzip httpd-2.0.46.tar.gz

 tar -xvf httpd-2.0.46.tar

 rm -f httpd-2.0.46.tar

 cd httpd-2.0.46

Now you should be in the directory that contains the source code.

Set compiler options (optional)

If you want you can set some compiler options, this is typically done to create optimized code. One very common thing to do is to setCFLAGS=-O2 orCFLAGS=-O3 (that's an Oh, not a Zero) that tells the compiler how much code optimization to do, setting it to a higher value does more optimization, but also takes longer to compile and may potentially cause unexpected things (not common). O2 is a fairly safe level to use. To do this type the following:

 
 export CFLAGS=-O2

You can also tell the compiler what kind of CPU you have to perform more optimizations, I'm not going to get into that here, but if your interested check out the GCC manual.

Run autoconf (configure)

Now you need to set the configuration options, and check that all libraries needed to compile are present. This is done with a script called configure, to find out what options you can set type the following:

 
 ./configure --help

You will see quite a few options there, we will set the prefix (the directory to install apache, we picked /usr/local/apache2) and also tell it which modules to compile and install. We will tell configure to compile and install all modules as shared DSO libraries, that way we caneasily enable and disable them in the httpd.conf file. Here's how we ran configure:
 
 configure --prefix=/usr/local/apache2 --enable-mods-shared=all

Compile Apache

Now to compile apache we run make this compiles the source code into executable binaries.

 
 make

Installing Apache

The next step copies the binaries into the install directory, and sets up the modules.

 
 make install

Starting/Stopping/Restarting Apache

Now to start/stop apache use apachectl in the bin directory of your install dir.

 cd /usr/local/apache2/bin
 
 ./apachectl start
 
 ./apachectl stop
 
 ./apachectl restart


提示 如果改命令不起作用 请使用一下命令:

 ./apachectl -k start
 
 ./apachectl -k stop
 
 ./apachectl -k restart


A script for init.d (optional)

Here's a script you can save to /etc/init.d/httpd it is a modified version of the one that came in the rpm for Apache 2.0.40

#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

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

# 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/apache2/bin/apachectl
httpd=/usr/local/apache2/bin/httpd
pid=$httpd/logs/httpd.pid
prog=httpd
RETVAL=0


# 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: "
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid
}
reload() {
        echo -n $"Reloading $prog: "
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f $pid ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"
		echo $"|fullstatus|graceful|help|configtest}"
        exit 1
esac

exit $RETVAL

Next run chkconfig to setup runlevels for which httpd will run:
	
	chkconfig --add httpd
	
	chkconfig --level 2345 httpd on
	
	chkconfig --list
	

Uninstall old rpm packages (Optional)

If you have old rpm apache packages installed, you can check by running:

 rpm -q httpd
 
In my case it lists the following:
redhat-config-httpd-1.0.1-13
httpd-2.0.40-11.3
httpd-manual-2.0.40-11.3
To uninstall one of the rpm's type rpm -e packagename
 
 rpm -e httpd-2.0.40-11.3
 

It may tell you that you have other packages that depend on httpd, you will have to uninstall them first before you can remove the old httpd server.


原始链接地址:http://www.zrinity.com/developers/apache/apache2src.cfm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值