方法一:通过yum安装,避免依赖问题
安装httpd一般都是yum安装,yum安装规避了依赖,直接去阿里镜像站下载这个系统,挂载到电脑,搭建一个本地仓库,或者搭建一个internet仓库,就能正常yum安装https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Everything-2009.iso
1、创建目录,挂载
创建目录:#mkdir /mnt/iso
挂载:#mount /dev/sr0 /mnt/iso
搭建本地仓库:
#cd /etc/yum.repos.d
创建 .repo 结尾的文件
#touch iso.repo
编辑iso.repo文件
vim /etc/yum.repos.d/iso.repo
[AppStream]
name=AppStream
enable=1
gpgcheck=0
baseurl=file:///mnt/iso/AppStream
[BaseOS]
name=BaseOS
enable=1
gpgcheck=0
baseurl=file:///mnt/iso/BaseOS
2、yum安装即可
#yum -y install httpd
#systemctl restart httpd 重启httpd服务
3、在浏览器输入ip地址即可
方法二:源码包编译安装
1、下载apache源码包(本章所需要的源码包全部在下面百度网盘,下载源码包都放在/root/下)
1)官网下载:Download - The Apache HTTP Server Project
2)链接:https://pan.baidu.com/s/1Afdx2Ml7OACh0pAaGhrJmw
提取码:6666
下载到windows的可通过WinScp复制到Centos 7(安装包在上述的百度网盘下载即可)
2、解压apache源码包
#tar -zxvf httpd-2.4.53.tar.gz
#cd httpd-2.4.53
#./configure --prefix=/usr/local/apache2/
如果报错:checking for APR... no
configure: error: APR not found. Please read the documentation.
说明系统没有安装apr,安装即可
3、安装apr
#cd 回到/root/目录下
下载:wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
如提示:-bash: wget: command not found
解决方法: #yum -y install wget
重新下载: #wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
解压:#tar -zxvf apr-1.4.5.tar.gz
#cd apr-1.4.5
#./configure --prefix=/usr/local/apr/
提示:checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/apr-1.4.5':
configure: error: no acceptable C compiler found in $PATH
解决方法:yum -y install gcc
#./configure --prefix=/usr/local/apr/
#make
#make install
4、重新安装apache
#cd httpd-2.4.53
#./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/
报错:checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
说明没有安装apr-util,安装即可
5、安装apr-util
#cd 回到/root/目录下
#wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
#tar -zxvf apr-util-1.3.12.tar.gz
#cd apr-util-1.3.12
#./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
#make
#make install
6、重新安装apache
#cd 回到/root/目录下
#cd httpd-2.4.53
#./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/
报错:checking for -pcre2-config... no
checking for -pcre-config... no
checking for pcre2-config... no
checking for pcre-config... no
configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/
找不到pcre(2)-config配置文件
解决方法:安装pcre即可
6.1新装centos 7系统已经默认安装了pcre
#rpm -qa | grep pcre (有结果显示,说明已安装)
#yum -y install pcre-devel (解决上面红色标识的问题)
(pcre-config的文件在 /usr/bin/下,没有安装pcre-devel,/usr/bin/下是没有pcre-config文件)
重复apache安装
# ./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/bin/
#make
#make install(已安装成功)
7、关闭防火墙
#systemctl stop firewalld.service(临时关闭防火墙,重启会无效)
#systemctl disable firewalld.service(永久关闭防火墙)
#systemctl status firewalld.service(查询防火墙状态)
8、打开httpd服务
#/usr/local/apache2/bin/apachectl start
9、在浏览器输入自己的IP地址