Linux安装apache详解

来源:互联网 发布:apache服务器搭建 编辑:程序博客网 时间:2024/06/11 17:01

一、概述

今天终于在在Linux把apache安装好了,花了将近两天的时间,废材啊。。。 
看图。

这里写图片描述

二、步骤

1、下载apache源代码

可以通过WinScp将源代码将从window上移到Linux上。例如,我移到了tmp目录下,然后执行解压缩命令将其解压

    tar -zxvf httpd-2.4.3.tar.gz 
  • 1
  • 1

接着进行安装步骤了,进入到解压的目录下执行如下命令

    ./configure --prefix=/usr/local/apache2/   (设置apache安装目录,这里的 /usr/local/apache2/ 才是apache真正的安装目录)
  • 1
  • 2
  • 1
  • 2

到这里,你会报错,如下:

    checking for APR... no    configure: error: APR not found.  Please read the documentation.
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

2、下载APR

到网上卸载apr-1.4.6.tar.gz,继续上面步骤,解压缩->进入到压缩包,然后执行.confingure命令,然后make ,make install。然后我们再来安装apache,命令如下:

    ./configure --prefix=/usr/local/apache2/  --with-apr=/usr/local/apr/  (注意,和第一次安装时不同)
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

回车,继续保错

3、下载APR-Util

到网上卸载apr-util-1.5.1.tar.gz。再次解压缩。。。和上面的一样,不过它的安装需要依赖于apr,所以在安装的时候指定下apr的路径。否则会报如下错误。

checking for APR... noconfigure: error: APR could not be located. Please use the --with-apr option.
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

正确的安装是:

 ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/    make    make install  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

再回去安装apache,就是在apache 安装的时候注意下不仅要指定apr的路径,还要指定apr-util的路径。不过依旧报错

checking for pcre-config... falseconfigure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

有了上面的经验,我们应该已经知道如何做了,下载pcre-8.32.tar.gz

    ./configure --prefix=/usr/local/pcre/      make    make install
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

接着错误:

checking for windows.h... noconfigure: error: You need a C++ compiler for C++ support.
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

Ok,通过yum安装下C++的环境即可。到了,这一步,基本apache安装成功了。 
安装命令如下:

    yum install -y gcc gcc-c++
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

三、启动apache

在启动apache的命令之前,我们最好需要查看下配置文件,我的是在/usr/local/apache2/conf/httpd.conf,,如下: 
这里写图片描述

我们需要在这里servername做些修改,修改成你linux的ip,端口号就用默认的。

好了,真正启动Linux吧

     /usr/local/apache2/bin/apachectl start
  • 1
  • 2
  • 1
  • 2

现在你就只需要在浏览器中输入ip地址即可访问。

注意:如果访问不了,可能需要关闭你的防火墙,命令如下:

    service iptables stop或者  systemctl stop firewalld
  • 1
  • 2
  • 1
  • 2

Ok,基本到这里就没问题了。

当然,最后apache的安装其实是这样的

./configure --prefix=/home/local/apache --enable-ssl=static --with-ssl=/usr/local/openssl --enable-so --enable-mods-shared=most --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

0 0
原创粉丝点击