zoukankan      html  css  js  c++  java
  • Linux中如何安装Apache服务器

                                                                         Linux中如何安装Apache服务器

          由于学习的需要,所有手动安装了一下Apache源码包,安装过程中的问题千奇百怪,但是如果弄清楚了问题出在哪里,那么也不是太难。如果有学习者出现安装中的问题,可仔细阅读该教程。

    首先下载httpd软件包(下载地址http://httpd.apache.org/download.cgi#apache24)。

    由于本人是在虚拟机中安装的CentOs7.0,所以我们还需要下载一个软件用来将下载在Windows中的包文件放置在Linux中。(下载地址:http://winscp.net/eng/docs/lang:chs)

    点击安装WinSCP,安装成功后可出现该界面:

    如图所示:输入虚拟机的IP地址,用户名和密码,点击登录即可。找到下载的包文件,可将包文件拖拽进Linux文件夹中,注意:需要将下载的httpd包文件放置在/usr/local/src文件目录下,该目录常用来放置各种源码包。

     

          下面我们登录到Linux中,到达src目录下(cd /usr/local/src),对放置的httpd包文件进行解压 #tar -zxvf  httpd包文件(注意这里可能会有一个小插曲,当你解压时可能会出现:

    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error exit delayed from previous errors

    这样的错误,原因很简单由于压缩包没有用gzip格式压缩的,所有解压时可以去掉'z',这样即可成功解压):

     #cd httpd文件夹

     #cd ./configure --prefix=/usr/local/apache

    这时出现了下面的问题:

    [root@localhost httpd-2.4.17]# ./configure --prefix=/usr/local/apache2

    checking for chosen layout... Apache

    checking for working mkdir -p... yes

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

    checking for egrep... /usr/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.

    从最后一行的配置信息中可以得知:APR没有找到,那么APR是什么呢?

    注意:大家不要将APR与ARP两者混淆,前者是(Apache portable Run-time libraries,Apache可移植运行库,其主要作用是为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库),而后者是(Address Resolution Protocol,地址解析协议)。

    好了,下面我们就可以去下载APR包了,但要告诉大家,APR还依赖于软件包APR-util,所有我们还需要下载APR-util

    下载地址:(http://apr.apache.org/

    我们依然利用文章开头所讲的方法,将其放到/usr/local/src目录下面。下面进行解压安装:

    #cd /usr/local/src

    #tar -xvf apr包文件  

     #cd apr文件夹

     #cd ./configure --prefix=/usr/local/apr-util

    但出现了下面的配置问题:

    从配置信息中可以发现:我们需要安装Gcc编译器

    我们可以使用在线安装gcc

    #yum install gcc

    #yum install gcc-c++(这个一定要安装,如果未安装,下面的安装中还会要求安装该软件包)

    安装完成后即可重新安装APR-util,APR,依旧按照先前的方法进行安装,即可安装通过。

    当我们安装httpd包文件时,发现在安装中出现了:

    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/

    从配置信息中可知:我们还需要安装PCRE包文件,其实安装到这里我想大家都是很崩溃的,心想怎么这么多东西要安装,这里我们就要说一下Linux中关于软件包的依赖性,如果以安装Apache服务器为例的话,就是:httpd包文件-->PCRE-->ARP-->APR-util-->GCC

    所有如果我们选择源码安装的话,就必须要一步一步认真安装。

    我们可以到网上找到配置信息中的PCRE(主要用于字符串的模式分割、匹配、查找及替换操作)

    下载地址:http://download.chinaunix.net/download/0008000/7913.shtml

    #unzip pcre包文件

    #cd pcre文件夹

    #configure --prefix=/usr/local/pcre--with-apr=/usr/local/apr/bin/apr-1-config

    #make

    #make install

    等我们安装成功之后就可以再次安装httpd安装包了,接下来大家可以放心,后面不会再有其他依赖的安装包软件了,我们还是按照先前的方法:

    #cd httpd包文件

    #cd./configure--prefix=/usr/local/apache--with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

    #make

    #make install

    好了,终于安装成功了,那么我们开启Apache服务,但在开启之前我们要修改一个小地方:

    #cd /usr/local/apache/conf

    #vi httpd.conf

    找到#ServerName www.example.com:80

    在下面添加ServerName 192.168.9.122:80

    保存退出即可

    最后我们来启动一下:

    接下来我们可在浏览器中查看:

    出现It Works !即可说明你的Apache服务器安装成功。

  • 相关阅读:
    HDU-4035 Maze
    poj 3744 Scout YYF I
    HDU 4911 Inversion
    HDU-3001 Travelling
    HDU 4539 郑厂长系列故事——排兵布阵
    poj 3311 Hie with the Pie
    poj-1185 炮兵阵地
    位运算
    HDU-1438 钥匙计数之一
    poj 3254 Corn Fields
  • 原文地址:https://www.cnblogs.com/qal2767799810/p/4924458.html
Copyright © 2011-2022 走看看