Apache [阿帕奇] 是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。
1、apache推荐的2种安装方式
1)yum安装
yum install httpd
2)源码编译安装
[root@shell ~]#
[root@shell ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@shell ~]#
[root@shell ~]# yum repolist
[root@shell ~]#
[root@shell ~]# ip addr show
[root@shell ~]#
[root@shell ~]# yum grouplist "Development Tools"
[root@shell ~]# yum groupinstall "Development Tools" #安装开发工具包
[root@shell ~]# rpm -qa httpd
[root@shell ~]#
[root@shell ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.46.tar.gz #下载apache包
[root@shell ~]# tar zxf httpd-2.4.46.tar.gz -C /usr/local/src/ #解压
[root@shell ~]# cd /usr/local/src/
[root@shell src]# cd httpd-2.4.46
[root@shell httpd-2.4.46]# ./configure --prefix=/usr/local/httpd #编译
此时发现如下报错:
checking for APR... no
configure: error: APR not found . Please read the documentation
……
去网上查找解决方案得知,是apache在编译过程中缺少若干依赖导致的报错
解决方案如下:
需要安装三个依赖包,即可进行apache的安装
[root@shell httpd-2.4.46]# wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
[root@shell httpd-2.4.46]# wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
[root@shell httpd-2.4.46]# wget ftp://ftp.pcre.org/pub/pcre/pcre-8.10.zip
[root@shell ~]# tar -zxf apr-1.4.5.tar.gz
[root@shell ~]# cd apr-1.4.5
[root@shell ~]# ./configure --prefix=/usr/local/apr
[root@shell ~]# make && make install
[root@shell ~]# cd ..
[root@shell ~]# tar -zxf apr-util-1.3.12.tar.gz
[root@shell ~]# cd apr-util-1.3.12
[root@shell ~]# ./configure --prefix=/usr/local/apr-until -with-apr=/usr/local/apr/bin/apr-1-config
[root@shell ~]# make && make install
[root@shell ~]# cd ..
[root@shell ~]# cd apr-util-1.3.12
[root@shell ~]# unzip -o pcre-8.10.zip
[root@shell ~]# cd pcre-8.10
[root@shell ~]# ./configure --prefix=/usr/local/pcre
[root@shell ~]# make && make install
[root@shell ~]# cd ..
接下来再次进行编译apache:
[root@shell httpd-2.4.46]# ./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-until --with-pcre=/usr/local/pcre
[root@shell httpd-2.4.46]# make
[root@shell httpd-2.4.46]# make install #安装
[root@shell httpd-2.4.46]# ln -s /usr/local/httpd/bin/apachectl /etc/init.d/httpd #将启动命令链接到/etc/init.d中,方便启动服务
[root@shell httpd-2.4.46]# vi /usr/local/httpd/conf/httpd.conf #按照红框处指导进行修改
ServerName 192.168.64.133:80
[root@shell httpd-2.4.46]#
[root@shell httpd-2.4.46]# /etc/init.d/httpd restart #重启apache
[root@shell httpd-2.4.46]# yum install links #安装浏览器
[root@shell httpd-2.4.46]# links 192.168.64.133 #访问web
[root@shell ~]#
[root@shell ~]# curl 192.168.64.133
<html><body><h1>It works!</h1></body></html>
[root@shell ~]#
使用谷歌浏览器进行访问: