Centos8 Apache-httpd编译安装

下载源

http://httpd.apache.org/
到该网址找到对应最新版本的httpd下载链接
在这里插入图片描述在这里插入图片描述
下载链接如下:
http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.bz2

找一个文件夹来存放和下载源文件。

[root@KAIVI ~]#cd /data/
#切换到/data目录下下载源文件
[root@KAIVI data]#wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.bz2
#下载源文件

编译安装

首次编译,可能回导致会缺少很多相关的包文件。需要根据提示,找到相关的包文件,然后依次进行安装即可。

[root@KAIVI data]#tar xvf httpd-2.4.41.tar.bz2 
#解压到当前文件夹
[root@KAIVI data]#cd httpd-2.4.41/
[root@KAIVI httpd-2.4.41]#
#切换到解压缩之后的目录中进行操作

不熟练的情况下可以查看里面的提示内容 “README”和“INSTALL”

[root@KAIVI httpd-2.4.41]#cat README
[root@KAIVI httpd-2.4.41]#cat INSTALL
#解释说明,如何安装以及安装步骤

cat INSTALL中的官方文档,可以查阅相关信息以及如何安装还有需要哪些相关的需求包

http://httpd.apache.org/docs/2.4/install.html

[root@KAIVI httpd-2.4.41]#./configure -help
#查看需要的实现需求 后面可以指定特定的需求功能
[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl
#需要实现上面定制的需求,需求可以通过./configure -help 查看

错误显示结果如下:

[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl
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.

报错configure: error: APR not found. 需要安装对应的需求相关包

[root@KAIVI httpd-2.4.41]#yum search apr
#查找apr相关的需求包
[root@KAIVI httpd-2.4.41]#dnf install apr-devel
#安装apr对应的开发需求包

apr-devel xxx*-devel xxx的开发相关包,集成在一个开发rpmgroup-devel中,需要是临时安装即可。

[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl
#重复命令。

错误显示结果如下:
在这里插入图片描述
报错configure: error: APR-util not found. 需要安装对应的需求相关包

[root@KAIVI httpd-2.4.41]#yum search apr-util
#查找apr-util相关的需求包
[root@KAIVI httpd-2.4.41]#dnf install apr-util-devel
#安装apr-util对应的开发需求包

安装好之后继续执行下面重复命令:

[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl

错误显示结果如下:在这里插入图片描述
报错configure: error: pcre-config for libpcre not found.需要安装对应的需求相关包

[root@KAIVI httpd-2.4.41]#yum search pcre
#查找pcre相关的需求包
[root@KAIVI httpd-2.4.41]#dnf install pcre-devel
#安装pcre对应的开发需求包

安装好之后继续执行下面重复命令:

[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl

还缺少ssl相关的需求包,查找对应的需求包并且安装

[root@KAIVI httpd-2.4.41]#yum search openssl
#查找openssl相关需求包
[root@KAIVI httpd-2.4.41]#dnf install openssl-devel
#进行包的安装
[root@KAIVI httpd-2.4.41]#./configure --prefix=/app/apache --sysconfdir=/etc/apache --enable-ssl
#执行重复的编译命令

验证上面的执行操作是否成功

[root@KAIVI httpd-2.4.41]#echo $?
0
#查看是否成功,0代表成功,非0则代表失败
[root@KAIVI httpd-2.4.41]#make -j 2
#进行第二部编译,-j 2 是表示2个cpu同时进程进行编译,加快编译速度

如果没有make命令则需要安装,没有gcc编译器插件也要安装

[root@KAIVI httpd-2.4.41]#yum install make -y 
[root@KAIVI httpd-2.4.41]#yum install gcc -y

假如出现了gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or director 的错误提示则需要安装redhat-rpm-config软件包

[root@KAIVI httpd-2.4.41]#dnf install redhat-rpm-config

最后进行编译的第三步骤:

 [root@KAIVI httpd-2.4.41]#make install

编译基本完成。修改访问路径和即时生效

[root@KAIVI httpd-2.4.41]# echo 'PATH=/app/apache/bin:$PATH' > /etc/profile.d/apache1.sh
#添加访问路径
[root@KAIVI httpd-2.4.41]#  . /etc/profile.d/apache1.sh 
#立即生效 . source 功能一样

最后,开启apache服务

[root@KAIVI httpd-2.4.41]#cd
[root@KAIVI ~]#apachectl 
#开启apache的httpd服务

验证测试

访问网页显示如图:
在这里插入图片描述
如上图所示,表示基本服务搭建成功

 [root@KAIVI ~]#cd /var/www/html/
 [root@KAIVI apache]#cd htdocs/
 [root@KAIVI htdocs]#ls     #查看
index.html
[root@KAIVI htdocs]#vim index.html 
#编辑vim

vim中编辑的内容
在这里插入图片描述

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值