CentOS7编译安装Apache2.4(基于VMWare虚拟机)

1、安装相关的依赖包
yum -y install gcc make prce-devel openssl-devel expat-devel
2、安装apache之前需要安装好apr和apr-util
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz #下载apr的压缩包
tar xvf apr-1.7.0.tar.gz #解压
cd apr-1.7.0
./configure --prefix=/usr/local/apr #编译并指定目录
make && make install #安装apr

  安装apr的时候会报以下的错误,解决方法很简单,打开configure这个文件,将RM='$RM'改成    RM='$RM -f '

在这里插入图片描述

安装apr-util,后面记得接上我们安装的apr的路径
wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar xvf apr-util-1.6.1
cd apr-util-1.6.1
./configure --prefix=/usr/loca/apr-util --with-apr=/usr/local/apr
make && make install
下载apache的安装包,然后解压安装
wget https://mirror.bit.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
tar xvf httpd-2.4.46.tar.gz
cd http-2.4.46
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make install
3、因为我们是编译安装的apache所以无法使用systemctl start httpd启动,这个时候我们可以通过./usr/local/apache/bin/apachectl start 启动,但是启动后会报如下图所示的错误,解决方法简单就是打开apache的配置文件httpd.conf,修改这一行ServerName localhost:80 ,即可。
在这里插入图片描述

4、这就表示访问成功了,如果访问不了的话,需要关闭一下防火墙systemctl stop firewalld
在这里插入图片描述

5、制作apache启动脚本,很简单的一个脚本httpd,基本看了就懂
function start_http()
{
/usr/local/apache/bin/apachectl start
}
function stop_http()
{

    /usr/local/apache/bin/apachectl stop

}
function restart_http()
{

    /usr/local/apache/bin/apchectl restart

}
case “$1” in
start)
start_http
;;
stop)
stop_http
;;
restart)
restart_http
;;
*)
echo “Usage:start | stop | restart”
;;
esac
6、启动自己所编写的脚本,脚本存放位置/etc/init.d/目录下,需要分配脚本执行权限,配置好之后我们就可以通过systemctl 启动我们的apache了
chmod + x httpd
systemctl daemon-reload
systemctl start httpd
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值