博客
关于我
Linux系统安装Apache 2.4.6
阅读量:793 次
发布时间:2023-02-05

本文共 10262 字,大约阅读时间需要 34 分钟。

Apache简介

Apache HTTP Server 是一个开放源码的网页服务器,可以在大多数计算机操作系统中运行。由于其多平台支持和高安全性,Apache 成为最流行的Web服务器端软件之一。它支持快速响应和扩展功能,可通过简单的API将 Perl/Python 等解释器编译到服务器中。

Apache软件下载

Apache 的相关软件包下载地址

1. Apache HTTP Server

截止目前为止,Apache HTTP Server 的最新版本是 Apache httpd 2.4.6 Released,下载地址:

2. APR 和 APR-Util 包

截止目前为止,APR 和 APR-Util 的最新版本如下,下载地址:

  • 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 地址:

Requirements

The following requirements exist for building Apache httpd:

APR 和 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 [官网], 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 [官网], 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 [推荐编译器] 是推荐的。如果你没有 GCC,那么至少确保你的编译器是 ANSI 兼容的。同时,PATH 必须包含基本的构建工具,如 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, ntpdatexntpd 程序用于此 purpose,基于 Network Time Protocol (NTP)。有关 NTP 软件和公共时钟服务器的详细信息,请参阅 [官网]。

[OPTIONAL]

For some of the support scripts like ,(例如,写在 Perl 中的脚本),需要 Perl 5 解释器(版本 5.003 或更高)。如果你有多个 Perl 解释器(例如,系统范围内安装的 Perl 4 和你自己的 Perl 5),你应该使用 --with-perl 选项(见下文)来确保正确的解释器被 Apache 使用。否则,你将无法使用受影响的支持脚本。但你仍然可以构建和使用 Apache httpd。

Apache安装过程

Step 1:安装包 gcc 或 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++

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

Step 2:安装包 APR 和 APR-Util

[root@getlnx05 kerry]# ls apr*

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

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

[root@getlnx05 kerry]# cd apr-1.4.8

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

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

[root@getlnx05 apr-1.4.8]# make

[root@getlnx05 apr-1.4.8]# make install

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

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

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

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

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

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

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

[root@getlnx05 pcre-8.33]# make

[root@getlnx05 pcre-8.33]# make install

Step 4:安装 Apache Http Server

[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

用浏览器访问时提示 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

一般出现这个错误是因为没有安装包 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-c++

问题2:checking 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 install 命令有可能导致这个错误。

[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 [官网]。

[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:启动服务时报错

[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 配置文件,添加 ServerName 的具体 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 给服务器标识自己使用的名称和端口。

# 这个通常可以自动确定,但建议你显式指定,以避免启动时出现问题。

# 如果你的主机没有注册过域名,进入它的 IP 地址。

#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> 块下。

#

"httpd.conf" 502L, 18179C written

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

httpd not running, trying to start

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

httpd (pid 7797) already running

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

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# chkconfig iptables off

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

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

转载地址:http://aakfk.baihongyu.com/

你可能感兴趣的文章
Linux系统本地部署MongoDB数据库并实现远程访问方法指南
查看>>
Linux系统查看JDK的安装路径
查看>>
linux系统查看电脑设备型号,Linux系统查看硬件信息
查看>>
Linux系统查看系统信息命令(比较全)
查看>>
Linux系统状态分析与监控工具详解
查看>>
Linux系统环境变量和别名设置(永久生效和临时生效)
查看>>
Linux系统用户和权限管理
查看>>
linux系统监控与硬盘分区/格式化/文件系统管理
查看>>
Linux系统程序安装(三)源码包安装程序
查看>>
Linux系统突然所有命令都失效了,显示bash: xxxxx: command not found...
查看>>
Linux系统管理期末考试小结
查看>>
Linux系统终端与正确关机
查看>>
Linux系统编程:深入理解计算机软硬件体系和架构
查看>>
Linux系统调优实战
查看>>
Linux系统调用分析
查看>>
Linux系统轻量应用服务器CPU使用率高的排查与解决方案
查看>>
Linux系统通过netstat查看网络状态、端口状态
查看>>
Linux系统配置静态IP地址步骤
查看>>
linux系统重命名文件名,但文件名有空格如何处理
查看>>
linux线程
查看>>