Apache Linux下Apache安装步骤
原文地址:https://www.cnblogs.com/wcwnina/p/8029156.html
Apache简介
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。关于更多Apache的介绍,可以参考百科“http://baike.baidu.com/view/28283.htm或官网http://www.apache.org/ 或 http://httpd.apache.org/的介绍。
Apache相关软件下载
Apache的相关软件包下载地址http://apr.apache.org/projects.html。
1. Apache HTTP Server
截止目前为止,Apache HTTP Server 目前最新的版本是 Apache httpd 2.4.6 Released, 下载地址:http://httpd.apache.org/download.cgi#apache24。
2. APR and APR-Util包
截止目前为止,APR and APR-Util的最新版本如下,下载地址:http://apr.apache.org/download.cgi
- APR 1.4.8, released June 21, 2013
- APR-util 1.5.2, released April 4, 2013
- APR-iconv 1.2.1, released November 26, 2007
3. PCRE包
截止目前为止,PCRE最新的包为8.33,下载地址如下
可以下载了相关安装包,上传到/root/kerry这个临时目录。也可以直接通过wget下载。
Apache安装要求
下面是官方文档的要求,必须安装APR、APR-Util、PCRE,gcc-c++等包,文档URL地址http://httpd.apache.org/docs/2.4/install.html。
Requirements
The following requirements exist for building Apache httpd:
APR and APR-Util
Make sure you have APR and APR-Util already installed on your system. If you don't, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/) and use ./configure's --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.
Perl-Compatible Regular Expressions Library (PCRE)
This library is required but not longer bundled with httpd. Download the source code from http://www.pcre.org, or install a Port or Package. If your build system can't find the pcre-config script installed by the PCRE build, point to it using the --with-pcre parameter. On some platforms, you may have to install the corresponding -dev package to allow httpd to build against your installed copy of PCRE.
Disk Space
Make sure you have at least 50 MB of temporary free disk space available. After installation the server occupies approximately 10 MB of disk space. The actual disk space requirements will vary considerably based on your chosen configuration options, any third-party modules, and, of course, the size of the web site or sites that you have on the server.
ANSI-C Compiler and Build System
Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC) from the Free Software Foundation (FSF) is recommended. If you don't have GCC then at least make sure your vendor's compiler is ANSI compliant. In addition, your PATH must contain basic build tools such as make.
Accurate time keeping
Elements of the HTTP protocol are expressed as the time of day. So, it's time to investigate setting some time synchronization facility on your system. Usually thentpdate or xntpd programs are used for this purpose which are based on the Network Time Protocol (NTP). See the NTP homepage for more details about NTP software and public time servers.
Perl 5 [OPTIONAL]
For some of the support scripts like apxs or dbmmanage (which are written in Perl) the Perl 5 interpreter is required (versions 5.003 or newer are sufficient). If you have multiple Perl interpreters (for example, a systemwide install of Perl 4, and your own install of Perl 5), you are advised to use the --with-perl option (see below) to make sure the correct one is used by configure. If no Perl 5 interpreter is found by the configure script, you will not be able to use the affected support scripts. Of course, you will still be able to build and use Apache httpd.
安装提示
Linux下,源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。
过程中用到“configure --prefix=安装目录 --with-name=依赖库源码解压目录”;其中--prefix指的是安装目录,--with指的是安装本文件所依赖的库文件。
安装httpd时,进行指定安装,用到./configure --prefix
具体解释:“.”表示当前目录;“/”是目录分隔符;合起来就是当前目录下。
1)如不指定prefix,则可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share。如果你要卸载这个程序,要么在原来的make目录下用一次make uninstall(前提是make文件指定过uninstall),要么去上述目录里面把相关的文件一个个手工删掉。
2)如指定prefix,直接删掉一个文件夹就够了。
注:
./configure的作用是检测系统配置,生成makefile文件,以便你可以用make和make install来编译和安装程序。
./configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系,但并不是所有的tar包都是源代码的包。
你可以先命令ls,看有没有configure或者makefile文件。
1)如果有configure,就./configure,有很多参数。如果系统环境合适,就会生成makefile,否则会报错。
2)如果有makefile,就直接make,然后make install。
你还可以用rpm或者deb包来安装。而且现在的发行版都有自己的包管理器,比如apt或yum,一个命令就可以从源下载软件,还可以自动解决依赖问题。
Apache安装过程
Step 1:安装包gcc或gcc-c++
[[email protected] pcre-8.33]# yum list gcc-c++
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
Available Packages
gcc-c++.x86_64 4.1.2-51.el5 rhel-debuginfo
[[email protected] pcre-8.33]# yum list gcc
Loaded plugins: product-id, security, subscription-manager
Updating Red Hat repositories.
Installed Packages
gcc.x86_64 4.1.2-51.el5 installed
[[email protected] pcre-8.33]# rpm -q gcc
gcc-4.1.2-51.el5
从上面可见gcc包已经安装,缺少gcc-c++包,那么接下来安装包gcc-c++,如果此处不安装该包,后面安装过程中会报错。(编译C)
[[email protected] pcre-8.33]#yum install gcc-c++
Step 2:安装包APR和APR-Util
[[email protected] kerry]# ls apr* ("kerry"是一个路径而已)
apr-1.4.8.tar.gz apr-util-1.5.2.tar.gz
[[email protected] kerry]#
[[email protected] kerry]# tar -zxvf apr-1.4.8.tar.gz
[[email protected] kerry]# cd apr-1.4.8
[[email protected] apr-1.4.8]# ls
新建目录/usr/local/apr,用作安装目录:
[[email protected] apr-1.4.8]# mkdir /usr/local/apr
[[email protected] apr-1.4.8]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.4.8]# make
[[email protected] apr-1.4.8]# make install
安装完成后,可以验证一下。
[ [email protected] apr]# ls -lrt
total 32
drwxr-xr-x 3 root root 4096 Aug 15 06:57 include
drwxr-xr-x 3 root root 4096 Aug 15 06:57 lib
drwxr-xr-x 2 root root 4096 Aug 15 06:57 build-1
drwxr-xr-x 2 root root 4096 Aug 15 06:57 bin
[[email protected] kerry]# tar -zxvf apr-util-1.5.2.tar.gz
[[email protected] kerry]# cd apr-util-1.5.2
[[email protected] apr-util-1.5.2]# mkdir /usr/local/apr-util
[[email protected] apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[[email protected] apr-util-1.5.2]# make
[[email protected] apr-util-1.5.2]# make install
Step 3:安装包PCRE
[[email protected] kerry]# unzip pcre-8.33.zip
[[email protected] kerry]# cd pcre-8.33
[[email protected] pcre-8.33]# mkdir /usr/local/pcre
[[email protected] pcre-8.33]# ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
[[email protected] pcre-8.33]# make
[[email protected] pcre-8.33]# make install
Step 4:安装Apache
[[email protected] kerry]# tar -zxvf httpd-2.4.6.tar.gz
[[email protected] kerry]# cd httpd-2.4.6
[[email protected] httpd-2.4.6]# ./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
[[email protected] httpd-2.4.6]# make
[[email protected] httpd-2.4.6]# make install
Step 5:启动Apache服务
[[email protected] httpd-2.4.6]# /usr/local/apache/bin/apachectl start
用浏览器访问http://localhost时提示It works!