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
·