linux安装配置Apache2.4

首先下载官网的apache(httpd-2.4.16.tar.gz):http://httpd.apache.org/download.cgi#apache24


选择以上两种任意一种版本下载

第一种.tar.bz2版本使用:sudo tar jxvf ./httpd-2.4.16.tar.bz2 -C /usr/lib

第二种.tar.gz版本使用:sudo tar zxvf ./httpd-2.4.16.tar.gz -C /usr/lib(我使用的是这个)

命令解释:

sudo:是允许可以让普通用户执行root命令的(如果进入了root下则不用加这个命令;进入root的命令:su)

tar:可以用来备份文件

jxvf和zxvf:这个是tar命令中主要参数合并起来一起用的,拆分开的可以看成:tar -j,tar-x.......等(具体解释可以看看linux下的命令解释)

-C /usr/lib:这个命令是指定解压文件到/usr/lib文件夹下

这时可以在/usr/lib下看到httpd-2.4.16这个文件夹


从命令行进入这个文件夹输入:ll  可以看到这个目录下的所有文件

安装的话configure这个文件最重要:  ----事实上linux中install Software基本都是用configure这个文件的


我们在root权限下输入:./configure


注意:这里就要教给大家怎么来在没有人帮助的情况下自己来解决错误和异常

在安装软件的时候出现异常或者错误的时候,大家很多人第一时间就是直接复制错误然后google,百度。。。。但是我并不推荐大家这样做,我建议大家首先看看报的是什么错误,然后去官网上直接看官方的安装解决方法。现在大家可以试试使用这种方法来解决。

首先我们看到了:checking for APR... no,这是大家就知道了最主要的错误了:这是在检查APR的时候出错了

我们接着看看下一句:configure:error:APR not found. Please read the documentation.    从这句话中我们得到了更加详细的信息了,“APR没有找到”,后面一句就是提示我们:"请阅读文档"。

从上面这几句的报错信息中我们是不是就找到了关键点了呢?----APR

我们这是到官网上找到相关的帮助文档(http://httpd.apache.org/docs/2.4/install.html)打开是一大堆的英语,对于懂英语的还好点,对于不懂英语,一看就头疼!!!这算是好的了,有很多人打开看到这么多英文直接就Ctrl+W就关闭了。。。告诉大家我也是属于不懂英语的行列的人,刚开始也是这么干的,后来见得这种文档多了也没办法了,只能硬着头皮看了。。。。这样就印证了这么一句话:人都是被逼的。

我们看这个的时候也没有必要一句一句的翻译,挑重点的来看:

下载地址:http://apr.apache.org/download.cgi

Download $ lynx http://httpd.apache.org/download.cgi
Extract $ gzip -d httpd-NN.tar.gz
$ tar xvf httpd-NN.tar
$ cd httpd-NN
Configure $ ./configure --prefix=PREFIX
Compile $ make
Install $ make install
Customize $ vi PREFIX/conf/httpd.conf
Test PREFIX/bin/apachectl -k start

首先我们看到的是下面一些内容,前两行作用不是很大(下载和解压)

第3,4,5行是怎么安装的过程

第6行是配置apache2.4.16的,我们还没有安装完成,谈何配置

第7行是配置好后进行测试的

接着我们会看到:

Requirements ----要求,我们看到了关键的地方,这个下面罗列了一些安装apache服务器的必要条件


我们看第一个不就是我们报错的信息吗?然后我们就可以仔细看看这个APR和APR-Util下面的信息了。

<span style="font-size:18px;">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 /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/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.</span>

大致意思就是:确保你的系统上有APR和APR-Util。如果没有那就从apache下载最新版的APR和APR-Util,解压到/httpd_source_tree_root/srclib/apr和/httpd_source_tree_root/srclib/apr-util(确保解压目录下没有版本号,例如:APR必须分布在/httpd_source_tree_root/srclib/apr)并且使用.configure's --wirh-included-apt 选项。在一些平台上,你可能需要安装必要的安装包允许httpd建立在你安装的APR和APR-Util副本。

我们不得不说官网上给的安装方法是非常详细的!

注意:你可以安装上面说的来安装,也可以按照我一下这种方法来安装,不过上面这种方法直接就安装到了apche下面了,我并不推荐这样做,因为可能APR以后也要用到。所以我建议大家可以安装到/usr/local/apr中

安装APR

首先解压apr-1.5.2.tar.gz到指定目录
apr-1.5.2.tar.gz使用:sudo tar zxvf ./apr-1.5.2.tar.gz -C /usr/lib
进入解压的目录执行:./configure --prefix=/usr/local/apr
这时可能报错:
<span style="font-size:18px;">rm: cannot remove `libtoolT': No such file or directory</span>
这时我们修改configure文件中的$RM "$cfgfile"为$RM -f "$cfgfile"
再次运行./configure --prefix=/usr/local/apr即可
不报错之后执行:make
然后再执行:make install
到此APR即可安装成功

安装APR-Util

首先解压apr-util-1.5.4.tar.bz2到指定目录
apr-util-1.5.4.tar.bz2使用:sudo tar jxvf ./apr-util-1.5.4.tar.bz2 -C /usr/lib
进入目录下执行:
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
即可安装
到这里我们之前报错的APR找不到应该解决了,我们再试试./configure 是否报错
这次输入的时候就要有所改变了:./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
接着我们看到了什么?不出意外的话还是报错。我们继续使用之前排查问题的方法来找解决的方法

我们可以看到关键字是:pcre,我们继续到刚才的那篇文章中找。
<span style="font-size:18px;">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.</span>
大致意思是:这个库是必须的,下载可以从http://www.pcre.org或者安装端口或者包。。。。。
到指定位置下载:pcre-8.37.tar.gz文件
解压文件
执行./configure -prefix=/usr/local/pcre
然而又报错:

我们现在一看这个错误应该就知道是缺少什么了吧。。。
configure: error: You need a C++ compiler for C++ support.-------你需要一个C++编译器来支持C++
我们可以直接安装linux库下面的gcc和gcc-c++

安装gcc和gcc-c++

执行命令:yum install -y gcc gcc-c++
等待安装完成即可
安装完gcc和gcc-c++之后再次执行:./configure --prefix=/usr/local/pcre就不会报错了,然后运行make和make install即可安装成功。
让我们再试试看这次apache是否会报错了
执行:
./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util -enable-dav -enable-so -enable-maintainer-mode -enable-rewrite
这次终于不报错了,继续执行make和make install
总结:从刚开始的报错到现在解决,大家是不是收获很多呢?这个过程是在研究新技术的时候遇到不明白的问题,怎么找问题的方法,在工作之后这样的方法不能说是最好最快捷的,但是却是一个不错的入手方向!!!

配置启动Apache

进入Apache目录下的bin目录,我的是在/usr/local/apache/bin/,使用apachectl start命令启动Apache
注意这时可能出现一个警告:
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
这个警告的内容与/etc/hosts这个文件有关,打开我们可以看到这个文件的内容,我的是这样的:
127.0.0.1   localhost localhost.localdomain localhost4 host.lxc-centos.com
::1         localhost localhost.localdomain localhost6 host.lxc-centos.com
所以我提醒的是localhost.localdomain,有的人可能是:127.0.0.1
并且这个警告说的很明白,他说你的ServerName要使用: localhost.localdomain
注意:在linux下Apache的主配文件是在/etc/httpd/conf/这个目录下!!!!!修改Apache的conf目录下的httpd.conf是没用的
在CentOS中Apache的默认文档路径的位置是在/var/www/html,配置文件的路径是/etc/httpd/conf/httpd.conf。其他的配置存储在/etc/httpd/conf.d/ 文件夹里。
进入/etc/httpd/conf/目录下,使用:vi + httpd.conf    找到ServerName这一行,他应该是用#注释掉的。将#去掉,然后修改为:
localhost.localdomain:80
这样修改后就再次启动的时候就不会出现这个警告了
为什么说他是个警告呢?因为这是你在网页上输入localhost:80是可以访问的

翻译过来的意思就是:
本页面是用来在已安装的Apache HTTP服务器的正常运行测试。如果你能阅读这一页,这意味着在这个站点上安装Apache HTTP服务器工作正常。
出现这个提示的原因是:在/var/www/html/这个目录下面没有找到指定的文件(index.html)
我们可以在/etc/httpd/conf.d/ 目录下找到welcome.conf这个文件打开我们看到以下内容:
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>
我们可以看到上面有一句:ErrorDocument 403 /error/noindex.html      这句的意思就是在没有找到文件的时候就自动跳转到noindex.html(var/www/error/)这个页面上。
有些人在网上看到说是要显示:It works!        才是安装成功!
首先大家要明白为什么他会显示It works!这句话呢?
这个文件是在apache的安装目录下的htdocs文件夹下的index.html,打开这个html文件你就会发现正是大家想要的It works!
那我们上面那个截图提示的“This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page it means that the Apache HTTP server installed at this site is working properly.”又是什么?在这篇文章中(http://wiki.dreamhost.com/Configure_Apache_on_Fedora_or_Centos)你会看到以下一段话:

他说的很明白:
The default page displays the following when Apache successfully installs:
-----默认页面显示以下内容时,Apache安装成功
接着我们看到了:
Apache 2 Test Page powered by CentOS
or
Fedora Test Page

This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you
can read this page it means that the Apache HTTP server installed at this site is working properly.
Apache2在Centos或者Fedora中的测试页面会显示:
This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page it means that the Apache HTTP server installed at this site is working properly.
我们可以复制apache/htdocs文件夹下的index.html文件到/var/www/html/下面(cp index.html /var/www/html/)
这时我们重启服务就可以看到It works!这个提示语句了。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值