apache的安装,Apache教程,Apache详解,Apache配置
一、什么是Apache?
Apache是一种服务器软件。
什么是服务器:
从硬件角度来讲,服务器就是一台配置很高的电脑,使用者是服务器管理员
从软件角度来讲,服务器就是安装了某一种软件的电脑,
例如:
安装了Apache服务器软件的电脑就是Apache服务器。
安装了MySQL数据库服务器软件的电脑就是数据库服务器。
这里以windows安装为主,linux的Apache安装会写在lamp的整体安装那篇文章里
1、安装Apache
下载地址:
http://httpd.apache.org/download.cgi

设置域名、服务器名、管理员邮箱

选择自定义安装(为了更好的学习,作为一名程序员,我们需要明确并控制我们的每一个工具的安装位置和目录详情)



服务管理器的打开方式:services.msc

2、Apache的目录结构

bin目录:Apache的主程序文件

conf目录:Apache的配置文件目录


htdocs目录: 站点根目录
modules目录: apache的功能目录
说明:
Apache是以模块进行设计的,并不是所有的模块在启动的时候都加载,用户可以根据需求来自定义加载。

二、主机的配置文件详解
1、httpd.conf详解
httpd.conf是Apache的主配置文件
打开httpd.conf,我们来仔细研究Apache都配置了什么
①、ServerRoot
Apache的安装位置

②、Listen
Apache的监听端口号

端口号详解

小结:
IP在计算机之间进行通讯是用于标识电脑
端口号是用于标识计算机内的具体程序
Apache 默认的端口号是80
③、ServerAdmin
用于设置管理员邮箱

④、ServerName

⑤、DocumentRoot

说明:
DocumentRoot是与ServerName对应的,当外部通过域名来访问Apache服务器时,Apache会到域名对应的DocumentRoot指定的目录中找文件。找到就返回,找不到就报错
⑥、Directory配置段
主要是用于对站点根目录的特性的设置,配置格式如下
<Directory "E:/PHP/WAMP/Apache2.4/htdocs">
DirectoryIndex index.html
Indexes Includes FollowSymLinks
Options Indexes FollowSymLinks
AllowOverride None
Order deny,allow
allow from all
Require all granted
</Directory>
说明:
DirectoryIndex 用于设置默认首页,当指定了域名,没有指定具体的文件时,Apache会将此项设置文件返回给用户。
Options indexes FollowSymLinks 是否列出目录结构,当请求文件不存在时,会将站点的目录结构显示出来。(注销掉就关了)

提示:
在开发阶段,要么允许列出目录结构,要么设置默认首页。
AllowOverride All或none 用于配置是否开启外部配置文件
Order 配置项 用于配置此目录访问权限
语法1:
Order deny,allow 如果没有明确的拒绝则全部允许
denyfrom ip地址或all
allowfrom ip地址或all

语法2:
Order allow,deny 如果没有明确的允许则全部拒绝
allowfrom ip地址或all
denyfrom ip地址或all

Require all granted

三、主机的配置
业务场景:
域名 xiaowu.xyz
站点根目录:e:php9
默认首页:index.html
允许列出目录结构
不允许110.110.110.110这个ip访问,其他都允许


在hosts文件中配置域名与ip地址的对应关系。

四、httpd.exe作用
httpd.exe位置,bin目录

①、Apache服务的维护
cmd的命令:
dir 查看当前目录的内容
cd 更改目录的位置(change dir)
httpd.exe文件可以进行Apache服务的启动、停止、重新启动
语法:
httpd.exe–k stop 停止Apache服务
httpd.exe–k start 启动Apache服务
httpd.exe–k restart 重启Apache服务
②、配置文件的语法检查
httpd -t

③、window环境变量
window的环境变量纪录了很多的路径,当我们在cmd窗口,执行一个命令时,如果当前目录找不到所要执行的文件时,window会到环境变量中所纪录的位置依次进行查找,找到就执行,找不到才报错。

环境变量

网友评论