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

Linux上安装Apache环境及安装过程报错解决方案(零初始环境)

2016-08-17 00:15 465 查看
Note:要从零开始搭建,就不要嫌中间遇到各种eggache的问题!
一.下载apache源代码
1.下载地址:http://httpd.apache.org/download.cgi 找稳定的最新的版本(Stable Release) 得到文件 httpd-2.4.3.tar.gz2. 上传到你的服务器目录,如:/home/tnuser/installers 解压:tar -zxvf httpd-2.4.3.tar.gz (我们下载的是源代码,所以这一步只是把源代码解压)  移动解压后的目录到目标地址:mv /home/tnuser/installers/httpd-2.4.3  /home/tnuser/ (这一步只是把解压后的目录放在合适的位置方便管理,可以不做)
3. 接下来我们需要编译刚才解压的源文件,这是重点
配置编译时的一些参数: 
[plain] view plain copy print?
cd /home/tnuser/installers/httpd-2.4.3 (切换到apache源代码目录下)

./configure --prefix=/home/tnuser/apache/ (设置apache安装目录,这里的 /home/tnuser/apache/ 才是apache真正的安装目录)

二. 到这里时,回车运行命令,报错:如果你能正常执行,说明你以前安装过apache环境,请直接make & make install 并请跳过下面一段)checking for APR... no
configure: error: APR not found. Please read the documentation.
解决方案:Apache在安装时需要一些准备环境,这里需要安装另外一个东西 APR(Apache Portable Runtime)。下载地址: http://archive.apache.org/dist/apr/ 同样找最新版本
得到文件:apr-1.4.6.tar.gz
解压:tar -zxvf apr-1.4.6.tar.gz
编译:
[plain] view plain copy print?
cd /home/tnuser/installers/apr-1.4.6

./configure --prefix=/home/tnuser/apr/ (一堆日志信息)

make (一堆日志信息)

make install (一堆日志信息)

完成后在指定地址生成目录和文件
接着装apache,切换到源代码目录设置编译参数: ./configure --prefix=/home/tnuser/apache/ 还是报上面的错,这是因为上面自定义了apr的安装目录,所以得把这个信息告诉apache。正确的运行命令为:
[plain] view plain copy print?
./configure --prefix=/home/tnuser/apache/ --with-apr=/home/tnuser/apr/

三. 执行后继续报错
不过这次错误信息变成了:(不要紧,这说明你的apr安装好了,只是又发现少了另外一个环境,慢慢来)checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
解决方案: 下载 APR-util
下载地址:http://archive.apache.org/dist/apr/ 找最新版本得到文件:apr-util-1.5.1.tar.gz解压: tar -zxvf apr-util-1.5.1.tar.gz编译:
[plain] view plain copy print?
cd /home/tnuser/installers/apr-util-1.5.1

./configure --prefix=/home/tnuser/apr-util/

这次运行会报错:
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option.
看到提示你就懂了,不多说:
[plain] view plain copy print?
./configure --prefix=/home/tnuser/apr-util/ --with-apr=/home/tnuser/apr/

make

make install

在你指定的安装地址生成目录就说明安装成功了

四. 再转回去继续安装apache
有了上回的经验,这次就知道运行什么命令了。切到apache源代码目录下运行:
[plain] view plain copy print?
./configure --prefix=/home/tnuser/apache/ --with-apr=/home/tnuser/apr/ --with-apr-util=/home/tnuser/apr-util/

照旧报错:

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 解决方案:发现还是少环境,不多说,下载 PCRE
下载地址: http://jaist.dl.sourceforge.net/project/pcre/pcre/ 找最新版下得到文件: pcre-8.32.tar.gz解压:tar -zxvf pcre-8.32.tar.gz编译:
[plain] view plain copy print?
cd /home/tnuser/hunter/installers/pcre-8.32

./configure --prefix=/home/tnuser/pcre/

这次错误信息如下:
checking for windows.h... no
configure: error: You need a C++ compiler for C++ support.
原来pcre需要用C++编译(我只想说:Why I need C++ while I'm a java programmer? Eggache! Holy Shit!)解决方案:首先,区分你的系统是Debian还是Fedora。我的系统是Fedora,所以配置步骤如下:(Debian系统使用命令apt-get,对应工具包为build-essential,命令使用方法:apt-get install build-essential)sudo yum groupinstall "Development Tools"这里会花费很长时间安装东西,中间会让你选择是否安装,输入 y 就行了。下载过程完成后会自动安装,最终见到 Complete! 就结束了。返回来还得继续安装PCRE啊,Go:
[plain] view plain copy print?
./configure --prefix=/home/tnuser/pcre/

make

make install

安装成功,以最终在目标位置生成相应目录为准。

至此,令人eggache的apache准备环境就算搞定了。五. 继续apache的安装,一定要在参数中带上以上3种环境配置:
[plain] view plain copy print?
./configure --prefix=/home/tnuser/apache/ --with-apr=/home/tnuser/apr/ --with-apr-util=/home/tnuser/apr-util/ --with-pcre=/home/tnuser/pcre/

大块的log,终于没报错(唯有泪千行啊。。。泪千行。。。)

makemake install六. 最后测试apache:cd /home/tnuser/apache/bin
apachectl -k start
如果不能启动,查下端口冲突之类的问题(一般会与系统自带的httpd服务端口冲突)。启动好后,访问你的apache,看到经典

It works!

关闭时用:apachectl -k stop

七.附录:http://apache.jz123.cn/install.html 中文版官方编译与安装教程

码完收功!!!原文地址:http://blog.csdn.net/bob007abc/article/details/8281630
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息