centos安装apache

参考https://www.cnblogs.com/nb-blog/p/5278502.html
http://blog.csdn.net/clevercode/article/details/45438495
https://www.cnblogs.com/Anker/p/3355573.html
http://www.linuxidc.com/Linux/2015-08/121073.htm

下载Apache 2.4路径可参考:
http://httpd.apache.org/download.cgi
http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.10.tar.gz

解决依赖关系的包 apr、apr-util、pcre
apr、apr-util下载路径可参考:
http://www.eu.apache.org/dist/apr/ 或https://mirrors.cnnic.cn/apache/apr/ 或http://apache.fayea.com/apache-mirror//apr/
pcre下载路径可参考:
http://softlayer-sng.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz

1、安装apr

[root@localhost Desktop]# cd /usr/local/src
[root@localhost src]# wget  http://www.eu.apache.org/dist/apr/apr-1.6.3.tar.gz 
[root@localhost src]# tar -zxvf apr-1.6.3.tar.gz 
[root@localhost src]# cd apr-1.6.3
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr 
[root@localhost apr-1.6.3]# make 
[root@localhost apr-1.6.3]# make install 
[root@localhost apr-1.6.3]# cd ..

2、安装apr-util

[root@localhost src]# wget  http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz 
[root@localhost src]# tar -zxvf apr-util-1.6.1.tar.gz
[root@localhost src]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config  
[root@localhost apr-util-1.6.1]# make 
[root@localhost apr-util-1.6.1]# make install
[root@localhost apr-util-1.6.1]# cd ..

有时在make后会报错

make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.0'
make: *** [all-recursive] Error 1

大致是说缺少了 xml 的解析器。查阅网络资料后找到了解决方案,yum 安装一个 expat-devel 包即可:

yum -y install expat-devel

3、正则表达式库安装

[root@localhost src]# wget  http://ftp.exim.llorien.org/pcre/pcre-8.10.tar.gz
[root@localhost src]# tar -zxvf pcre-8.10.tar.gz 
[root@localhost src]# cd pcre-8.10
[root@localhost pcre-8.10]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.10]# make
[root@localhost pcre-8.10]# make install

有时make后会报错

./libtool: line 990: g++: command not found
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/usr/local/src/pcre-8.10'
make: *** [all] Error 2

这个错误是缺少gcc安转包,运行如下命令:

yum -y install gcc-c++

成功后在执行make,又报错:

libtool: link: Fatal configuration error.
make[1]: *** [libpcrecpp.la] Error 1
make[1]: Leaving directory `/usr/local/src/pcre-8.10'
make: *** [all] Error 2

于是重新执行了一边./configure –prefix=/usr/local/pcre 后有执行make,第三次报错:

.libs/pcrecpp.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libpcrecpp.la] Error 1
make[1]: Leaving directory `/usr/local/src/pcre-8.10'
make: *** [all] Error 2

在./configure后加上–disable-shared –with-pic ,执行后在执行make

./configure --prefix=/usr/local/pcre --disable-shared --with-pic 
make 

好了。。。。

pcre问题解决参考:http://blog.csdn.net/jiajiano6/article/details/10929773

安装apache2.2

[root@localhost src]# wget https://mirrors.cnnic.cn/apache//httpd/httpd-2.2.34.tar.gz  --no-check-certificate
[root@localhost src]# tar -zxvf httpd-2.2.34.tar.gz
[root@localhost src]# cd httpd-2.2.34
[root@localhost httpd-2.2.34]# ./configure --prefix=/usr/local/apache2 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[root@localhost httpd-2.2.34]# make
[root@localhost httpd-2.2.34]# make install

① ./configure时报错:

configure: error: Did not find pcre-config script at 

到local下看了一下,没有prce,于是重新安装了一次prce,local下有了,然后安装apache,第二次报错:

checking for zlib location... not found
checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

网上搜索应该是没有zlib-devel,于是安装

yum install zlib-devel -y

在执行./configure 成功了

② make install时又报错:

collect2: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/src/httpd-2.2.34/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/httpd-2.2.34/support'
make: *** [all-recursive] Error 1

make clean一下
apache的编译选项上增加 –libdir=/usr/lib64 即:

./configure --prefix=/usr/local/apache2 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --libdir=/usr/lib64

依旧是那个错,各种搜索之后发现一片文章总结的错误很好,
http://www.jianshu.com/p/ba5d5622e9d8,参照他第九个错误,重复了我这里2、安装apr-util的操作,然后就好了

5、启动apache:

/usr/local/apache2/bin/apachectl start

安装apache2.4

环境与前面相同

[root@localhost src]# wget http://apache.cs.utah.edu//httpd/httpd-2.4.29.tar.gz   --no-check-certificate
[root@localhost src]# tar -zxvf httpd-2.4.29.tar.gz
[root@localhost src]# cd httpd-2.4.29
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --libdir=/usr/lib64
[root@localhost httpd-2.4.29]# make
[root@localhost httpd-2.4.29]# make install

启动报错:

[root@localhost Desktop]# /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

进入apache的安装目录,编辑httpd.conf文件,搜索”#ServerName”,添加ServerName localhost:80

cd /usr/local/apache2/conf
vi httpd.conf

centos安装apache_第1张图片

centos安装apache_第2张图片

第二次启动又报错

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

说明80端口被用
终端: ps -ef|grep httpd察看占用的进程或者用netstat -lnp|grep 80
找到后kill掉

[root@localhost conf]# ps -ef|grep httpd
root      36274      1  0 07:18 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36291  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36292  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36293  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36294  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36295  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
daemon    36296  36274  0 07:23 ?        00:00:00 /usr/local/apache2/bin/httpd -k start
root      55426  55402  0 07:48 pts/1    00:00:00 grep httpd
[root@localhost conf]# kill all httpd

重启好了

yum安装apache:

[root@localhost Desktop]# rpm -qa httpd            //先在系统上面查询一下是否已经安装了apache
[root@localhost Desktop]# yum install httpd -y     //没有的话安装

[root@localhost Desktop]# rpm -qa httpd                          
httpd-2.2.15-29.el6.centos.x86_64
[root@localhost Desktop]# service httpd start      //启动apache
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

yum下载安装apache参考自:https://www.cnblogs.com/lauren1003/p/5993654.html

你可能感兴趣的:(linux)