WEB网站服务(一)Apache 01

实验目的:

1.编译安装httpd

2.优化路径

3.创建一个以自己姓名命名的目录,并在在其中创建一个index.html网页,并将此目录做为网页目录

4.在客户机永www.自己姓名.com访问

 

实验步骤:

关闭防火墙和selinux

[[email protected] /]# systemctl stop firewalld.service

[[email protected] /]# setenforce 0

[[email protected] /]# systemctl disable firewalld.service

检测是否安装httpd

[[email protected] /]# rpm -e httpd --nodeps

错误:未安装软件包 httpd

挂着系统光盘进行安装httpd依赖包

[[email protected] ~]# mount /dev/cdrom  /mnt

rpm -ivh /mnt/Packages/apr-1.4.8-3.el7.x86_64.rpm

rpm -ivh /mnt/Packages/apr-devel-1.4.8-3.el7.x86_64.rpm

rpm -ivh /mnt/Packages/cyrus-sasl-devel-2.1.26-20.el7_2.x86_64.rpm

rpm -ivh /mnt/Packages/expat-devel-2.1.0-8.el7.x86_64.rpm

rpm -ivh /mnt/Packages/libdb-devel-5.3.21-19.el7.x86_64.rpm

rpm -ivh /mnt/Packages/openldap-devel-2.4.40-13.el7.x86_64.rpm

rpm -ivh /mnt/Packages/apr-util-devel-1.5.2-6.el7.x86_64.rpm

rpm -ivh /mnt/Packages/apr-util-1.5.2-6.el7.x86_64.rpm

rpm -ivh /mnt/Packages/pcre-devel-8.32-15.el7_2.1.x86_64.rpm

rpm -ivh /mnt/Packages/pcre-8.32-15.el7_2.1.x86_64.rpm

 

上传httpd的压缩包,开始源码编译安装!!!

WEB网站服务(一)Apache 01

[[email protected] /]# tar zxf  httpd-2.4.25.tar.gz  -C /usr/src/

[[email protected] /]# cd /usr/src/httpd-2.4.25/

配置:根据服务器的实际应用需要,灵活配置

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-list --enable-cgi

编译和安装

[[email protected] httpd-2.4.25]# make && make install

优化执行路径

[[email protected] httpd-2.4.25]# ln -s /usr/local/httpd/bin/* /usr/local/bin

[[email protected] httpd-2.4.25]# httpd -v        查看程序版本

Server version: Apache/2.4.25 (Unix)

Server built:   Aug  4 2020 17:05:56

 

添加系统服务

[[email protected] httpd-2.4.25]# cp /usr/local/httpd/bin/apachectl  /etc/init.d/httpd

[[email protected] httpd-2.4.25]# cd /etc/init.d/

[[email protected] init.d]# vim httpd

在第二行插入:

#chkconfig: 35 85 21

[[email protected] init.d]# chkconfig  --add httpd

[[email protected] init.d]# systemctl  start httpd

[[email protected] init.d]# netstat  -anput | grep httpd

tcp6       0      0 :::80                   :::*                    LISTEN      62581/httpd  

 

配置httpd服务,查找servername设置一个网站名称

199   ServerName www.web.com:80

检测语句是否正确

[[email protected] init.d]# apachectl  -t

Syntax OK

部署网页文档

[[email protected] init.d]# echo "web" >> /usr/local/httpd/htdocs/index.html

[[email protected] init.d]# cat /usr/local/httpd/htdocs/index.html

<html><body><h1>It works!</h1></body></html>

Web

在客户机进行访问测试

WEB网站服务(一)Apache 01

 

查看web站点的访问情况

[[email protected] ~]# tail /usr/local/httpd/logs/access_log

127.0.0.1 - - [04/Aug/2020:17:45:13 +0800] "GET / HTTP/1.1" 200 45

127.0.0.1 - - [04/Aug/2020:17:45:13 +0800] "GET /favicon.ico HTTP/1.1" 404 209

127.0.0.1 - - [04/Aug/2020:17:45:13 +0800] "GET /favicon.ico HTTP/1.1" 404 209