一.安装开发软件包组
[root@localhost yum.repos.d]#yum groupinstall "development tools"
[root@localhost yum.repos.d]# yum install openssl-devel
[root@localhost yum.repos.d]# yum install pcre-devel
[root@localhost yum.repos.d]# yum install expat-devel
二.检查httpd是否已经安装
[root@localhost yum.repos.d]# rpm -qa httpd
如果没有返回信息,则代表没有安装
三.安装Apache
1.通过 以下命令从网络中下载httpd-2.4.38.tar.gz包,放置在家目录下
[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.38.tar.gz
2.解压当前文件,使用命令:
[root@localhost ~]# tar zxvf httpd-2.4.34.tar.gz
3.配置configure脚本
[root@localhost httpd-2.4.38]# ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
最后一行提示报错,缺少ARP需要安装,apr是Apache Portable Runtime的缩写,中文译为Apache可移植运行环境,是httpd所必须的,apr-util同理。
apr及apr-util下载地址:http://apr.apache.org/download.cgi
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
再进行解包和解压:
[root@localhost ~]# tar -zxvf apr-1.7.0.tar.gz
[root@localhost ~]# tar -zxvf apr-util-1.6.1.tar.gz
再安装apr和apr-util
[root@localhost ~]#cd apr-1.7.0
[root@localhost apr-1.7.0]#./configure
[root@localhost apr-1.7.0]#make && make install
[root@localhos local]# cd apr-util-1.6.1
[root@localhos apr-util-1.6.1]# ./configure --with-apr=/usr/local/apr/
[root@localhos apr-util-1.6.1]# make && make install
重新安装httpd服务
[root@localhost httpd-2.4.38]# ./configure
[root@localhost httpd-2.4.38]# make && make install
四.检查
[root@localhost ~]# cd /usr/local/apache2
[root@localhost apache2]# apachectl -t
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
Syntax OK
提示了一个错误,需要编辑httpd.conf文件,如下:
[root@localhost apache2]# cd conf
[root@localhost conf]# vim httpd.conf
编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80
再次检查是否还有错误:
[root@localhost apache2]# apachectl -t
Syntax OK
最后启动服务:
[root@localhost apache2]# apachectl start
在浏览器输入本机网址,出现如下图,则代表安装成功了: