二维码

Apache Linux下Apache安装步骤

1514 人阅读 | 时间:2020年05月24日 17:09

阿帕奇简介

         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服务器  

    最终目前为止,Apache HTTP Server 最新版本是Apache httpd 2.4.6发布下载地址:http : //httpd.apache.org/download.cgi#apache24

2. APR和APR-Util   

    截止到目前为止,APR和APR-Util 的最新版本如下,下载地址:http : //apr.apache.org/download.cgi

  • 2013年6月21日发布的APR 1.4.8 

  • 2013年4月4日发行的APR-util 1.5.2 

  • 2007年11月26日发布的APR-iconv 1.2.1

3. PCRE   

   截至目前为止,PCRE 最新的包为8.33 ,下载地址如下

  • https://sourceforge.net/projects/pcre/files/pcre/

   可以下载了相关安装包,上传到/ root / kerry 这个临时目录。也可以直接通过wget 下载。

 

Apache 安装要求

下面是官方文档的要求,必须安装APR APR-Util PCRE gcc-c ++ 等包,文档URL 地址http://httpd.apache.org/docs/2.4/install.html

 要求

构建Apache httpd存在以下要求:

APR和APR-Util

确保已在系统上安装APR和APR-Util。如果您不使用或不想使用系统提供的版本,请从Apache APR下载最新版本的APR和APR-Util ,将它们解压缩到./srclib/apr和./srclib/apr-util(be确保目录名称没有版本号;例如,APR发行版必须位于./srclib/apr/下,并使用./configure的--with-included-apr选项。在某些平台上,您可能必须安装相应的-dev软件包,以允许httpd针对已安装的APR和APR-Util副本进行构建。 

Perl兼容的正则表达式库(PCRE)

该库是必需的,但不再与httpd捆绑在一起。http://www.pcre.org下载源代码,或安装端口或软件包。如果您的构建系统找不到PCRE构建安装的pcre-config脚本,请使用--with-pcre参数指向它。在某些平台上,您可能必须安装相应的-dev软件包,以允许httpd针对已安装的PCRE副本进行构建。 

磁盘空间

确保您至少有50 MB的可用临时磁盘空间。安装后,服务器大约占用10 MB的磁盘空间。实际的磁盘空间要求将根据您选择的配置选项,任何第三方模块以及服务器上的一个或多个网站的大小而有很大不同。

ANSI-C编译器和构建系统

确保已安装ANSI-C编译器。GNU C编译器(GCC)自由软件基金会(FSF)的建议。如果您没有GCC,则至少要确保供应商的编译器符合ANSI。另外,您的PATH必须包含基本的构建工具,例如make。    

精确计时

HTTP协议的元素表示为一天中的时间。因此,是时候研究在系统上设置一些时间同步功能了。通常,ntpdate或xntpd程序用于此目的,它们基于网络时间协议(NTP)。有关NTP软件和公共时间服务器的更多详细信息,请参见NTP主页  

Perl 5 [可选] 

对于某些支持脚本(如apxsdbmmanage(用Perl编写)),需要Perl 5解释器(版本5.003或更高版本已足够)。如果您有多个Perl解释器(例如,在系统范围内安装Perl 4,并且自己安装了Perl 5),建议您使用--with-perl选项(请参见下文)以确保使用正确的解释器。通过配置如果配置脚本未找到Perl 5解释器,则将无法使用受影响的支持脚本。当然,您仍然可以构建和使用Apache httpd。       

 

安装提示

Linux 下,原始码的安装一般由个步骤组成:配置(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文件,以便你可以用makemake install来编译和安装程序。

./configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系,但并不是所有的tar包都是源代码的包。

你可以先命令ls,看有没有configure或者makefile文件。

1)如果有configure,就./configure,有很多参数。如果系统环境合适,就会生成makefile,否则会报错。

2)如果有makefile,就直接make,然后make install

你还可以用rpm或者deb包来安装。而且现在的发行版都有自己的包管理器,比如aptyum,一个命令就可以从源下载软件,还可以自动解决依赖问题。

 

Apache安装过程

 Step 1:安装包gccgcc-c++

[root@getlnx05 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

[root@getlnx05 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

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

从上面可见gcc包已经安装,缺少gcc-c++包,那么接下来安装包gcc-c++,如果此处不安装该包,后面安装过程中会报错。(编译C

[root@getlnx05 pcre-8.33]#yum install  gcc-c++

 

Step 2:安装包APRAPR-Util

[root@getlnx05 kerry]# ls apr*  "kerry"是一个路径而已)

apr-1.4.8.tar.gz  apr-util-1.5.2.tar.gz

[root@getlnx05 kerry]#

[root@getlnx05 kerry]# tar -zxvf apr-1.4.8.tar.gz

[root@getlnx05 kerry]# cd apr-1.4.8

[root@getlnx05 apr-1.4.8]# ls

Apache Linux下Apache安装步骤

新建目录/usr/local/apr,用作安装目录:

[root@getlnx05 apr-1.4.8]# mkdir /usr/local/apr

[root@getlnx05 apr-1.4.8]# ./configure --prefix=/usr/local/apr

Apache Linux下Apache安装步骤

[root@getlnx05 apr-1.4.8]# make

[root@getlnx05 apr-1.4.8]# make install

Apache Linux下Apache安装步骤

安装完成后,可以验证一下。

[ root@getlnx05 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

[root@getlnx05 kerry]# tar -zxvf apr-util-1.5.2.tar.gz

[root@getlnx05 kerry]# cd apr-util-1.5.2

Apache Linux下Apache安装步骤

[root@getlnx05 apr-util-1.5.2]# mkdir /usr/local/apr-util

[root@getlnx05 apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

Apache Linux下Apache安装步骤

[root@getlnx05 apr-util-1.5.2]# make

[root@getlnx05 apr-util-1.5.2]# make install

Apache Linux下Apache安装步骤

 

Step 3:安装包PCRE

[root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# mkdir /usr/local/pcre

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config

Apache Linux下Apache安装步骤

[root@getlnx05 pcre-8.33]# make

[root@getlnx05 pcre-8.33]# make install

Apache Linux下Apache安装步骤

 

Step 4:安装Apache

[root@getlnx05 kerry]# tar -zxvf httpd-2.4.6.tar.gz

[root@getlnx05  kerry]# cd httpd-2.4.6

[root@getlnx05 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

[root@getlnx05 httpd-2.4.6]# make

[root@getlnx05 httpd-2.4.6]# make install

Step 5:启动Apache服务

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectl start

用浏览器访问http://localhost时提示It works!

 

Apache安装问题集锦

 问题1:缺少包gcc-c++导致安装包apr-util不通过

 [root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

Apache Linux下Apache安装步骤

一般出现这个错误是因为没有安装包gcc-c++,可以通过如下命令检查,

[root@getlnx05 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

[root@getlnx05 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

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

[root@getlnx05 pcre-8.33]# rpm -q gcc-c++

 

问题2checking for APR-util... configure: error: the --with-apr-util parameter is incorrect

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2 -pthread"

  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... configure: error: the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.

[root@getlnx05 httpd-2.4.6]#

一般是由于APR-util没有安装成功,可以通过验证该目录是否为空来判断,因为你有时候执行了make,忘了执行make isntall命令有可能导致这个错误。

[root@getlnx05 apr]# cd /usr/local/apr-util

[root@getlnx05 apr-util]# ls

 

问题3:没有指定PCRE参数

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/apache  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2 -pthread"

  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... yes

checking for gcc... gcc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C compiler... yes

checking whether gcc accepts -g... yes

checking for gcc option to accept ISO C89... none needed

checking how to run the C preprocessor... gcc -E

checking for gcc option to accept ISO C99... -std=gnu99

checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

[root@getlnx05 httpd-2.4.6]#

 

问题4:安装前忘了先安装APR相关包

[root@getlnx05 httpd-2.4.6]#  ./configure --prefix=/usr/local/appache/

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... no

configure: error: APR not found.  Please read the documentation.

[root@getlnx05 httpd-2.4.6]#

 

问题5:安装apr-util报错 

错误内容:

make[1]: Entering directory `/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: 错误:expat.h:没有那个文件或目录
xml/apr_xml.c:66: 错误:expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: 在函数‘cleanup_parser’:
xml/apr_xml.c:364: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:365: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c: 在文件层:
xml/apr_xml.c:384: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: 在函数‘apr_xml_parser_create’:
xml/apr_xml.c:401: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:402: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:410: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:411: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:412: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:424: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:424: 错误:‘default_handler’未声明(在此函数内第一次使用)
xml/apr_xml.c:424: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
xml/apr_xml.c:424: 错误:所在的函数内也只报告一次。)
xml/apr_xml.c: 在函数‘do_parse’:
xml/apr_xml.c:434: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:438: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:442: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
xml/apr_xml.c:442: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c: 在函数‘apr_xml_parser_geterror’:
xml/apr_xml.c:500: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
xml/apr_xml.c:500: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
make[1]: *** [xml/apr_xml.lo] 错误 1
make[1]: Leaving directory `/usr/local/apr-util-1.6.1'
make: *** [all-recursive] 错误 1
[root@cdr02 apr-util-1.6.1]# yum inatsll expat-devel -y
已加载插件:product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
No such command: inatsll. Please use /usr/bin/yum --help
[root@cdr02 apr-util-1.6.1]# yum inatsll -y expat-devel
已加载插件:product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
No such command: inatsll. Please use /usr/bin/yum --help
[root@cdr02 apr-util-1.6.1]# make
make[1]: Entering directory `/usr/local/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: 错误:expat.h:没有那个文件或目录
xml/apr_xml.c:66: 错误:expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: 在函数‘cleanup_parser’:
xml/apr_xml.c:364: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:365: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c: 在文件层:
xml/apr_xml.c:384: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: 在函数‘apr_xml_parser_create’:
xml/apr_xml.c:401: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:402: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:410: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:411: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:412: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:424: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:424: 错误:‘default_handler’未声明(在此函数内第一次使用)
xml/apr_xml.c:424: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
xml/apr_xml.c:424: 错误:所在的函数内也只报告一次。)
xml/apr_xml.c: 在函数‘do_parse’:
xml/apr_xml.c:434: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:438: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c:442: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
xml/apr_xml.c:442: 错误:‘apr_xml_parser’没有名为‘xp’的成员
xml/apr_xml.c: 在函数‘apr_xml_parser_geterror’:
xml/apr_xml.c:500: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
xml/apr_xml.c:500: 错误:‘apr_xml_parser’没有名为‘xp_err’的成员
make[1]: *** [xml/apr_xml.lo] 错误 1

解决办法:

安装expat库试试。yum install expat-devel

 

问题6:安装pcre报错

错误内容:invalid value of canonical build

解决办法:
检查./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config是否有多余的空格。

 

问题7make命令安装Apache时报错

错误内容:make[2]: *** [htpasswd] 错误 1
make[2]: Leaving directory `/usr/local/httpd-2.4.29/support'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/usr/local/httpd-2.4.29/support'
make: *** [all-recursive] 错误 1

解决办法:
由于安装的“apr”“apr-util”的版本是V1.6,造成版本不兼容,需要安装它们的V1.5

 

问题8:启动服务时报错

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectl start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using getlnx05.gfg1.esquel.com. Set the 'ServerName' directive globally to suppress this message

这个时候需要编辑httpd.conf配置文件,添加SeraverName的具体IP地址。如下所示。

[root@getlnx05 conf]# cd /usr/local/apache/conf/

[root@getlnx05 conf]# ls

extra  httpd.conf  magic  mime.types  original

[root@getlnx05 conf]# vi httpd.conf

ServerAdmin you@example.com

#

# ServerName gives the name and port that the server uses to identify itself.

# This can often be determined automatically, but we recommend you specify

# it explicitly to prevent problems during startup.

#

# If your host doesn't have a registered DNS name, enter its IP address here.

#

#ServerName www.example.com:80

ServerName 192.168.9.122:80

#

# Deny access to the entirety of your server's filesystem. You must

# explicitly permit access to web content directories in other

# <Directory> blocks below.

#

"httpd.conf" 502L, 18179C written

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

  如果从其它电脑连接访问Apache时,输入url地址:http://192.168.9.122页面没有显示正常,而上面配置也OK,那么你必须关闭防火墙,有时候甚至需要重启电脑才能OK,重启Apache服务都无效。

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# /usr/local/apache/bin/apachectl restart

 

设置Apache的环境变量

1、在"/etc/profile"文件最后添加export PATH=$PATH:/usr/local/apache/bin "="左右不要有空格)

2[root@admin ~]# source /etc/profile (立即生效)

3、测试重启:[root@admin ~]# service httpd restart
 

 

设置Apache 开机启动

[root @ admin〜] #cp / usr / local / apache / bin / apachectl /etc/rc.d/init.d/httpd (如果有其他版本的Apache存在,也可以直接覆盖掉)       

,打开编辑(vim ,键盘输入字母“ i” “ /etc/rc.d/init.d/httpd” 文件,在#!/ bin / sh 下增加两行文字如下:

  #chkconfig:35 70 30 #说明:Apache
  

,注册该服务

[root @ admin〜] #chkconfig –添加httpd 
 

查看结果:[root @ admin〜#chkonfig --list 
 

   

  至此。转载请注明出处,记得扫码打赏支持哦,谢谢!

组 限制解除 

档铺网-在线文档免费处理


©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
◎已有 0 人评论
搜索
作者介绍
30天热门
×
×
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×