您的位置:首页 > 运维架构 > Apache

Linux系统下Apache2.4.17的安装过程

2016-05-06 18:59 591 查看
Linux系统下安装Apache Server2.4.17。还是先声明一下,Linux命令我不进行讲解,因为我不是讲Linux命令的。有需要注意的地方,我会上图,没什么值得的注意的地方,我就不上图了。还有就是怎样将压缩包上传到Linux系统中去,我不进行讲解,还是那句话:网上教程太多了!最后,确保你的Linux是连网的!

工具/原料

Linux系列系统

Apache Server2.4.17源码包

APR源码包

APR-Util源码包

PCRE源码包

方法/步骤

1

首先,秉承我一贯的风格,来看一小段官方文档:

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.

Perl-Compatible Regular Expressions Library (PCRE)

This library is required but not longer bundled with httpd.

Disk Space

Make sure you have at least 50 MB of temporary free disk space available.

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.

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 the ntpdate or xntpd programs are used for this purpose which are based on the Network Time Protocol (NTP).

我来翻译一下:

要编译Apache httpd,存在以下要求:

APR and APR-Util

确保你的系统中已经安装了APR和APR-Util。

Perl-Compatible Regular Expressions Library (PCRE)

这个库是必需的,但它不再与httpd捆绑在一起。

Disk Space

确保你有至少50MB的临时空闲磁盘空间可以使用。

ANSI-C Compiler and Build System

确保你已经安装了一个ANSI-C编译器。推荐使用由自由软件基金会(FSF)编写的GNU C编译器(GCC)。

Accurate time keeping

HTTP协议的元素会以一天的时间进行表示。所以,它的时间会参照你系统中的一些时钟同步设备的设置。通常基于网络时间协议(NTP)的程序ntpdate或xntpd就是用来做这样的事情。

通过官方文档我们了解到,在安装Apache2.4之前我们要做的是:安装APR、APR-Util和PCRE。

2

无论你是要安装APR、APR-Util、PCRE还是Apache Server或者是其他的一些软件,总之,只要是源码安装,那么就需要一个ANSI-C编译器。如果你没有,那就用yum装一个吧,既然推荐使用GCC,那就装个GCC吧。执行命令:yum install -y gcc。如果,你闲得发慌,你可以不依赖yum,自己进行安装GCC试试,相信你会爽歪歪的!

3

接下来,就是要安装APR、APR-Util和PCRE。安装之前,来看下怎么下载它们。先来看下APR与APR-Util的下载,大家可以去http://apr.apache.org进行下载,看下面两张图:








再来看下怎么下载PCRE。大家可以去http://www.pcre.org进行下载,看下面四张图:














将下载的3个压缩包上传到你的Linux系统中去。我上传到了我Linux系统下/mysoft目录中。进入这个目录:cd /mysoft。我们先解包APR,并查看/mysoft目录下的文件,依次执行命令:

gzip -d apr-1.5.2.tar.gz

tar -xf apr-1.5.2.tar

ls -l

可以看到/mysoft目录下多了一个目录apr-1.5.2。





进入apr-1.5.2目录:cd ./apr-1.5.2/。然后,进行APR的源码安装,依次执行命令:

./configure

make

make install

安装完成后,我们可以在make install过程中看到如下图所示信息,我们可以看到APR的安装路径/usr/local/apr。当然,你也可以使用 --prefix=目录 选项来指定一个安装目录。





接着,我们来解包APR-Util,并查看/mysoft目录下的文件,依次执行命令:

gzip -d apr-util-1.5.4.tar.gz

tar -xf apr-util-1.5.4.tar

ls -l

可以看到/mysoft目录下多了一个目录apr-util-1.5.4。





进入apr-util-1.5.4目录:cd ./apr-util-1.5.4/。然后,进行APR-Util的源码安装,依次执行命令:

./configure --with-apr=/usr/local/apr

make

make install

在安装APR-Util时,需要指定APR的安装路径,所以需要带上选项--with-apr=/usr/local/apr,如果你不带上这个选项,在configure的时候会看到下图的错误提示。





下面,我们来安装PCRE。首先,解包PCRE,并查看/mysoft目录下的文件,依次执行命令:

gzip -d pcre-8.36.tar.gz

tar -xf pcre-8.36.tar

ls -l

可以看到/mysoft目录下多了一个目录pcre-8.36。





进入pcre-8.36目录:cd ./pcre-8.36/。然后,进行pcre-8.36源码安装,但是,当你在执行./configure时,会看到下图所示提示:

configure: error: You need a C++ compiler for C++ support

不用担心,yum又派上用场了,执行命令:yum install -y gcc gcc-c++ 。

gcc-c++安装完成后,我们继续我们的pcre-8.36源码安装,依次执行命令:

./configure

make

make install





至此,准备工作就绪,开始准备安装Apache Server2.4,首先,来看下怎么下载Apache2.4,我们可以去http://httpd.apache.org进行下载,看下图。





安装Apache之前,我们再来看一小段官方文档:

--enable-mods-shared=MODULE-LIST

Defines a list of modules to be enabled and build as dynamic shared modules. This mean, these module have to be loaded dynamically by using the LoadModule directive.MODULE-LIST is a space separated list of modulenames enclosed by quotation marks. The module names are given without the preceding mod_. For example:

--enable-mods-shared='headers rewrite dav'

Additionally you can use the special keywords reallyall, all, most, few and none. For example,

--enable-mods-shared=most will compile most modules and build them as DSO modules

--enable-mods-shared=few will only compile a very basic set of modules

The default set is most.

The LoadModule directives for the chosen modules will be automatically generated in the main configuration file. By default, all those directives will be commented out except for the modules that are either required or explicitly selected by a configure --enable-foo argument. You can change the set of loaded modules by activating or deactivating the LoadModule directives in httpd.conf. In addition the LoadModule directives for all built modules can be activated via the configure option --enable-load-all-modules.

--enable-mods-static=MODULE-LIST

This option behaves similar to --enable-mods-shared, but will link the given modules statically. This mean, these modules will always be present while running httpd. They need not be loaded with LoadModule.

--enable-modules=MODULE-LIST

This option behaves like to --enable-mods-shared, and will also link the given modules dynamically. The special keyword none disables the build of all modules.

我来翻译一下:

--enable-mods-shared=MODULE-LIST

定义一个要启用的模块列表,并且这些模块会以动态共享模块进行编译。这就意味着,这些模块需要通过使用LoadModule指令进行动态加载。MODULE-LIST是一个由引号引起来且由空格进行分隔的模块名列表。这些模块名要以去掉前面的mod_的形式给出。例如:

--enable-mods-shared='headers rewrite dav'

你还可以使用特殊关键字reallyall,all,most,few和none。例如:

--enable-mods-shared=most 编译大部分模块并将它们作为动态共享模块进行编译

--enable-mods-shared=few 只编译一组比较基本的模块

默认关键字是most。

对于已选择的模块来说,LoadModule指令会自动在主要配置文件中生成。默认情况下,所有这些指令会被注释掉,除了一些必需的或是通过一个--enable-foo参数明确指定的模块。你可以在httpd.conf文件中通过激活或注销LoadModule指令来改变已加载模块的设置。另外,可以通过配置选项--enable-load-all-modules来将所有已编译模块的LoadModule指令激活。

--enable-mods-static=MODULE-LIST

这个配置选项的行为与--enable-mods-shared类似,但会静态链接给出的模块。这就意味着,在运行httpd的时候,这些模块总是存在。它们不需要用LoadModule指令进行加载。

--enable-modules=MODULE-LIST

这个配置选项的行为与--enable-mods-shared类似,也会动态链接给出的模块。可以使用特殊关键字none来禁用所有要编译的模块。

更多的内容大家可以自己去官网看,这里我就不再多讲了。进入正题,解包httpd,并查看/mysoft目录下的文件,依次执行命令:

gzip -d httpd-2.4.17.tar.gz

tar -xf httpd-2.4.17.tar

ls -l

可以看到/mysoft目录下多了一个目录httpd-2.4.17。





14

进入httpd-2.4.17目录:cd ./httpd-2.4.17/。然后,进行Apache源码安装,依次执行命令:

./configure --enable-mods-shared=all

make

make install

Apache默认安装在/usr/local/apache2目录下。同样,这里你也可以使用

--prefix=目录名

来指定一个安装目录,例如:

./configure --prefix=/usr/mydir --enable-mods-shared=all





15

Apache已经安装成功,现在启动httpd服务。执行命令:

/usr/local/apache2/bin/apachectl -k start。

大家会发现,httpd服务并没有启动,而是出现了一条如下图所示的错误信息:

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





16

出现上述错误信息,是因为配置文件httpd.conf中的ServerName没有修改。

我们用Vim打开httpd.conf配置文件,执行命令:

vi /usr/local/apache2/conf/httpd.conf

设置Vim在执行搜索时不区分大小写,执行命令:

:set ic

搜索"servername"字符串,执行命令:

/servername

找到servername后,按A键进行编辑。将ServerName前的#号去掉,将ServerName后面的字符串改为:localhost:80,如下图所示。

修改完成后,按Esc键由编辑模式切换到命令模式,然后执行保存退出命令:

:wq





17

在启动httpd之前,我们先为其创建一个软链接(相当于windows下的快捷方式),否则每次重启Apache都要输那么一长串,很费劲。

为httpd创建软链接,并查看一下软链接是否创建成功,依次执行命令:

ln -s /usr/local/apache2/bin/apachectl /mylinks/httpd。

ls -l /mylinks

来吧,启动httpd服务,执行命令:/mylinks/httpd -k start





18

在测试Apache是否已经正常工作之前,我们先看下防火墙的状态:

systemctl status firewalld

如果处于running运行状态,就把它关掉:

systemctl stop firewalld

然后,查看一下防火墙是否已经关掉:

systemctl status firewalld

如果处于dead状态,就说明已经关掉了。

如果你希望每次系统启动的时候都不要启动防火墙,可以执行命令:

systemctl disable firewalld

同样,如果你希望每次系统启动的时候都启动防火墙,可以执行命令:

systemctl enable firewalld











19

防火墙关闭后,接着来看下你系统的IP地址:ifconfig -a。可以看到我的IP是192.168.0.104。





20

打开浏览器,在地址栏中输入:192.168.0.104,回车。可以看到It works!



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: