编译安装Apache

1.将所需软件安装包下载到/opt目录下
关闭防火墙

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2.解压文件
tar xf apr -1.6.2.tar.gz
tar xf apr -util -1.6.0.tar.gz
tar xf httpd -2.4.29.tar.bz2

3.移动俩个文件并改名
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr -util-1.6.0 httpd -2.4.29/srclib/apr-util

4.安装需求环境
建立yum
yum install -y gcc gcc-c++ make pcre-devel expat-devel perl

5.编译安装
cd /opt/httpd-2.4.29/

./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \ #启用网页地址重写功能,用于网站优化、防盗链及目录迁移维护
--enable-charset-lite \ #启动字符集支持,以便支持使用各种字符集编码的页面
--enable-cgi #启用CGI(通用网关接口)脚本程序支持,便于网站的外部扩展应用访问能力
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

make -j4 && make install

6.优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别

ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

7.添加httpd系统服务

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #用于service服务管理
chmod +x /etc/init.d/httpd
vi /etc/init.d/httpd
#!/bin/bash #在第一行前插入新行,添加此三行内容
#chkconfig: 35 85 21 #35级别自动运行 第85个启动 第21个关闭
# description: Apache is a World Wide Web server
chkconfig --add httpd #将httpd服务加入到service管理器

systemctl start httpd.service

8.修改httpd 服务配置文件
vim /etc/httpd.conf
--52行--修改 Listen 192.198.146.20:80 --197行--取消注释,修改 ServerName www.benet.com:80

--221行--默认首页存放路径 DocumentRoot "/usr/local/httpd/htdocs" --255行--默认首页文件名设置 DirectoryIndex index.html

httpd -t 或 apachectl -t #检查配置文件的配置项是否有误
cat /usr/local/httpd/htdocs/index.html systemctl restart httpd.service

9.浏览器访问验证
netstat -anpt | grep 80 echo "192.168.146.20 www.benet.com" >> /etc/hosts

http://192.168.146.20 http://www.benet.com
·

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值