Building Apache2 From Source on Linux (Redhat 8)
2013-10-21 11:26
801 查看
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
Downlaod the latest tar.gz file for apache2
You can download it from
httpd.apache.org.
Login as root
You can type
Extract the source code
In this example we extract the source code to a directory under
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 set
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:
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:
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:
Compile Apache
Now to compile apache we run
Installing Apache
The next step copies the binaries into the install directory, and sets up the modules.
Starting/Stopping/Restarting Apache
Now to start/stop apache use apachectl in the bin directory of your install dir.
提示 如果改命令不起作用 请使用一下命令:
A script for init.d (optional)
Here's a script you can save to
Next run chkconfig to setup runlevels for which httpd will run:
Uninstall old rpm packages (Optional)
If you have old rpm apache packages installed, you can check by running:
In my case it lists the following:
To uninstall one of the rpm's type
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
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
Downlaod the latest tar.gz file for apache2
You can download it from
httpd.apache.org.
Login as root
You can type
suto switch to root. Then run
source /etc/profileto 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 set
CFLAGS=-O2or
CFLAGS=-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
makethis 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/httpdit 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
相关文章推荐
- Building a Linux Kernel from source
- How to Compile Qt from Source Code on Linux
- Compiling PHP and Apache 2 from source on Linux OS
- Install Apache 2 from Source on Linux(转)
- building-gcc-4-8-from-source-on-ubunu-12-04/
- Installing_Code::Blocks_from_source_on_Linux
- 【Bazel】Install on RedHat7.4 from source 菜鸟记录
- A very cool thing: Install MYSQL from source without root access on LINUX
- Installing Code::Blocks from source on Linux
- 9 Steps to Install and Configure PostgreSQL from Source on Linux
- Domino Server installation on Linux (Centos or Redhat) – something somewhere
- enum should not be used as an identifier since it is a reserved keyword from source level 1.5 on
- 安装 NIST net 的步骤及使用(nistnet-2.0.12b针对linux-2.4.20-8)on RedHat9.0
- About Xorg building from the source codes
- Setting Up Logrotate on RedHat Linux
- How to Get Source Code of a Linux Command on CentOS
- Installing ImageMagick from Source on Ubuntu 8.04
- Building from source--想自己编译cyanogenmod ROM吗?
- Guide to porting from Solaris to Linux on x86
- [Linux] Enable ssh key authentication from one user on client to multiple users on server