CentOS上安装LAMP之Apache环境及安装过程报错解决方案(纯净系统环境)

来源:互联网 发布:天刀淘宝刷白发多少钱 编辑:程序博客网 时间:2024/05/22 16:00

Note:要从零开始搭建,就不要嫌中间遇到各种问题!

一.下载apache及相关安装包(包括httpd,apr,par-util,pcre等),并上传到服务器上,本人上传到/home/zhangatle/tar目录下

1.下载地址:http://httpd.apache.org/download.cgi 找稳定的最新的版本(Stable Release)
得到文件 httpd-2.4.27.tar.gz
2. 上传到你的服务器目录,如:/home/zhangatle/tar
这里写图片描述

解压:tar zxvf httpd-2.4.27.tar.gz (我们下载的是源代码,所以这一步只是把源代码解压) 

  1. 接下来我们需要编译刚才解压的源文件,这是重点
    配置编译时的一些参数: 
cd /home/zhangatle/httpd-2.4.27  (切换到apache源代码目录下)  ./configure --prefix=/usr/local/httpd   (设置apache安装目录,这里的 /usr/local/httpd 才是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.6.2.tar.gz
解压:tar zxvf apr-1.6.2.tar.gz
编译:

cd /home/zhangatle/apr-1.6.2   ./configure --prefix=/usr/local/apr  (一堆日志信息)    make (一堆日志信息)  make install (一堆日志信息) 

继续报错,是不是很惊喜?这里需要安装apr-devel

这里写图片描述
运行以下命令:

yum install apr-devel

再次make&&make install 以上apr,安装成功,在指定地址生成目录和文件
这里写图片描述

接着切换到上级目录,进入apache ,装apache,切换到源代码目录设置编译参数: ./configure –prefix=/usr/local/httpd –enable-modules=all –enable-mods-shared=all –enable-so
还是报上面的错,这是因为上面自定义了apr的安装目录,所以得把这个信息告诉apache。
正确的运行命令为:

./configure --prefix=/usr/local/httpd --enable-modules=all --enable-mods-shared=all --enable-so --with-apr=/usr/local/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.6.0.tar.gz
解压: tar -zxvf apr-util-1.6.0.tar.gz
编译:

cd /home/zhangatle/tar/apr-util-1.6.0   ./configure --prefix=/usr/local/apr-util/   

这次运行会报错:

checking for APR… no configure: error: APR could not be located.
Please use the –with-apr option.

看到提示你就懂了,不多说:

./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/   make   make install   

意料中的惊喜–>继续报错,居然还是一个致命错误,惊不惊喜?
这里写图片描述
解决方法:
安装一个依赖包:

yum install expat-devel

安装完成后,继续上面apr-util的make和make install 操作
apr-util安装成功后
在你指定的安装地址生成目录就说明安装成功了

四. 再转回去继续安装apache

有了上回的经验,这次就知道运行什么命令了。切到apache源代码目录下运行:

./configure --prefix=/usr/local/httpd --enable-modules=all --enable-mods-shared=all --enable-so  --with-apr=/usr/local/apr/  --with-apr-util=/usr/local/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.41.tar.gz
解压:tar -zxvf pcre-8.41.tar.gz
编译:

cd /home/zhangatle/tar/pcre-8.41./configure --prefix=/usr/local/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 PHP programmer? Eggache! Holy Shit!)

解决方案:

yum install gcc gcc-c++ gdb autoconf automake

这里会花费很长时间安装东西,中间会让你选择是否安装,输入 y 就行了。
下载过程完成后会自动安装,最终见到 Complete! 就结束了。
返回来还得继续安装PCRE啊,Go:

./configure --prefix=/usr/local/pcre/    make  make install 

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

补充: 可能其中还会报一个小错误,应该是pcre-devel的问题,安装一下,重新执行apache 安装就好

yum install pcre-devel

至此,令人头疼的apache准备环境就算搞定了。

五. 继续apache的安装,一定要在参数中带上以上3种环境配置:

./configure --prefix=/usr/local/httpd --enable-modules=all --enable-mods-shared=all --enable-so  --with-apr=/usr/local/apr/  --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre/  

补充,如果你是64位的系统,可能会报如下错误

collect2: error: ld returned 1 exit statusmake[2]: *** [htpasswd] Error 1make[2]: Leaving directory `/home/mufeng/tar/httpd-2.4.27/support'make[1]: *** [all-recursive] Error 1make[1]: Leaving directory `/home/mufeng/tar/httpd-2.4.27/support'make: *** [all-recursive] Error 1[root@localhost httpd-2.4.27]# 

解决办法:后面加上–libdir=/usr/lib64

./configure --prefix=/usr/local/httpd --enable-modules=all --enable-mods-shared=all --enable-so  --with-apr=/usr/local/apr/  --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre/  --libdir=/usr/lib64

大块的log,终于没报错(唯有泪千行啊。。。泪千行。。。)
make
make install
六. 最后测试apache:

cd /usr/local/httpd/bin./apachectl start

如果不能启动,查下端口冲突之类的问题(一般会与系统自带的httpd服务端口冲突)。
启动好后,访问你的apache,看到经典
It works!
关闭时用:./apachectl stop

补充:默认情况下不能通过127.0.0.1访问,需要更改httpd.conf里面的ServerName,更改为localhost就可以访问了

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

码完收功!!!

阅读全文
0 0
原创粉丝点击