php学习记录之apache虚拟目录和虚拟主机

首先说如何在控制台下开启关闭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. 设置欢迎页面

        http://localhost/myblog/

 

        把上面的改为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均可看到

   

说明配置成功。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值