首先说如何在控制台下开启关闭Apache:进入cmd(这里要注意必须是以管理员身份打开cmd),进入apache安装目录的bin目录下,输入httpd –k shutdown是关闭Apache服务,httpd –k shart是开启,httpd –k restart是重新启动。
如果想在任意目录下就对Apache进行操作,我们需要配置一下环境变量。
进入本机的计算机信息,进入高级系统配置,进入环境变量,编辑用户的PATH,在最后加入Apache安装的bin目录即可。
下面是修改虚拟目录。打开apache的conf下httpd.conf,用编辑器打开。
1. 添加虚拟目录的节点
#配置虚拟目录
<IfModule dir_module>
#direcotory相当于是欢迎页面
DirectoryIndex index.html index.htm index.php
#请输入你的站点别名
Alias /myblog "F:/web/php/myblog"
<Directory F:/web/php/myblog>
#这是访问权限设置
Order allow,deny
Allow from all
</Directory>
</IfModule>
2. 注销documentroot路径
#DocumentRoot "D:/apache2.2/htdocs"
3. 测试
http://localhost/myblog/welcome.html
4. 设置欢迎页面
把上面的改为DirectoryIndex welcome.html index.html index.htm index.php即可。
接下来我们配置虚拟主机,步骤如下:
1. 启用 httpd-vhosts.conf
在 httpd.conf 文件中
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
如图
2. 在httpd-vhosts.conf文件中做配置
#配置我们自己的虚拟主机
<VirtualHost 127.0.0.1:80>
DocumentRoot "F:/web/php/myblog"
#这里配置欢迎首页面
DirectoryIndex index.html index.htm index.php
<Directory />
Options FollowSymLinks
#不许可别人修改我们的页面
AllowOverride None
#设置访问权限
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3. 修改hosts 文件
C:\Windows\System32\drivers\etc目录下,打开hosts文件
添加:127.0.0.1 www.feng.com
测试:
输入http://www.feng.com/myblog/或者http://www.feng.com均可看到
说明配置成功。