• PHP中级篇 Apache配置httpd-vhosts虚拟主机总结及注意事项(转载)


    此文转载http://blog.163.com/lgh_2002/blog/static/44017526201182514650248/

    经常使用Apache虚拟主机进行开发和测试,但每次需要配置虚拟主机时都习惯性的ctrl+c和ctrl+v,这次由于重装系统,需要配置一个新的PHP开发环境虚拟主机,于是总结一下Apaceh配置httpd-vhosts虚拟主机使用方法和步骤,便于查找和使用。

    开发环境:WAMP
    网址:http://www.wampserver.com/en/

    实例一,Apaceh配置localhost虚拟主机步骤
    1,用记事本打开apache目录下httpd.conf文件(如:D:wampinapacheapache2.2.8httpd.conf),找到如下模块

    1. #Virtual hosts
    2. #Include conf/extra/httpd-vhosts.conf

    去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,无法打开localhost,需要在httpd-vhosts.conf配置一下。

    2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd-vhosts文件中实例,修改成如下:

    1. <VirtualHost *:80>
    2. ServerAdmin webmaster@dummy-host.localhost
    3. DocumentRoot "D:wampwww"
    4. ServerName localhost
    5. ServerAlias localhost
    6. ErrorLog "logs/dummy-host.localhost-error.log"
    7. CustomLog "logs/dummy-host.localhost-access.log" common
    8. </VirtualHost>

    修改配置如下:
    DocumentRoot 修改为本地wamp环境下的www目录(如:D:wampwww)
    ServerName改为localhost

    3,重启Apache,发现localhost可以正常打开,配置localhost比较简单。

    实例二,Apaceh配置test.biuuu.com虚拟主机步骤

    1,方法同上,复制配置代码修改如下:

    1. <VirtualHost *:80>
    2. ServerAdmin test@biuuu.com
    3. DocumentRoot E:WebRootiuuu
    4. ServerName test.biuuu.com
    5. ErrorLog "logs/dummy-host2.localhost-error.log"
    6. CustomLog "logs/dummy-host2.localhost-access.log" common
    7. </VirtualHost>

    2,打开host文件(C:WINDOWSsystem32driversetchosts),增加一行代码

    1. 127.0.0.1       test.biuuu.com

    3,在浏览器中打开test.biuuu.com,发现如下错误403 Forbidden错误
    Forbidden You don't have permission to access / on this server.

    分析:这主要是目录访问权限没有设置,需要设置对目录的访问权!

    4,打开httpd文件,找到如下语句

    1. <Directory />
    2. Options FollowSymLinks
    3. AllowOverride None
    4. Order deny,allow
    5. Deny from all
    6. </Directory>

    复制以上代码,并进行目录修改,把/替换为E:WebRootiuuu,修改virtualHost代码如下

    1. <VirtualHost *:80>
    2. ServerAdmin test@biuuu.com
    3. DocumentRoot E:WebRootiuuu
    4. ServerName test.biuuu.com
    5. ErrorLog "logs/dummy-host2.localhost-error.log"
    6. CustomLog "logs/dummy-host2.localhost-access.log" common
    7.  
    8. <Directory E:WebRootiuuu>
    9. Options FollowSymLinks
    10. AllowOverride None
    11. Order deny,allow
    12. Deny from all
    13. </Directory>
    14.  
    15. </VirtualHost>

    在浏览器中测试发现还是打不开,提示如上403 Forbidden错误,修改其中的Deny from all为allow from all

    5,重启Apache,虚拟主机配置成功!

    注意事项
    1,目录路径,如E:WebRootiuuu
    2,访问权限,如上Deny from all修改为allow from all
    3,host文件,配置虚拟域名host指向
    4,httpd文件,打开Include conf/extra/httpd-vhosts.conf模块
    5,httpd-vhosts文件,配置虚拟主机

    6,还有可能是linux 的 selinux 防火墙导致这个原因,切记切记

    使用Apaceh配置httpd-vhosts虚拟主机对于开发人员来说比较简单,但却非常重要,仅供参考!

    参考资料:

    http://httpd.apache.org/docs/2.2/vhosts/

    http://httpd.apache.org/docs/2.0/vhosts/examples.html

    原创文章如转载,请注明:转载自 必优博客 http://www.biuuu.com/

    顾银鑫 注:如发生Fatal error: Allowed memory size of 8388608 bytes exhausted错误

    修改php.ini设置memory_limit = 12M(默认8M)

    或只需要在你的程序头部加入: ini_set("memory_limit","12M");

     

  • 相关阅读:
    合并一个二维数组中相同项,其他数量则相加
    清除空值
    数组的一维下标换为指定的key值
    二维数组排序
    word输出
    解决Zend加密的PHP页面出现Fatal error: Incompatible file format: The encoded file has format major ID 1, whereas the Loader expects 4 in
    nginx反向代理substitutions4nginx模块实现替换字符盗站 nginx.conf配置
    ubuntu 编译安装nginx 并添加substitutions4nginx模块
    windows 2008 R2 wincache 不稳定
    php5.5及php5.6 wincache无法启用问题
  • 原文地址:https://www.cnblogs.com/runong/p/3627968.html
Copyright © 2020-2023  润新知