在Wamp服务器上为Zend应用程序设置VirtualHost

时间:2014-02-12 05:19:05

标签: php windows zend-framework wamp virtualhost

我正在按照本教程学习如何使用ZendFramework

启动项目

http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html

当我设置虚拟主机时,我遇到了困难。如果我完全按照教程所说的那样,它会向我显示一个错误(在我的所有项目中,是否为zend),表示找不到该文件。

然后我发现StackOverflow上的这个教程非常方便

Can't run zend framework MVC application on WAMP

当我尝试以zendProject.local/

访问我的应用时,页面底部的人说出了同样的错误

这就是我得到的

主机上的

(Windows / System32 / drivers / etc / hosts)文件

127.0.0.1       blog.local

在httpd-vhosts.conf文件

<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public

SetEnv APPLICATION_ENV "development"

<Directory /blog/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

你能告诉我我做错了什么吗?当我转到http://blog.local/

时,浏览器仍然显示未找到此服务器上找不到请求的网址/公开

我在Windows上运行WAMP。这是“博客”项目C:\wamp\www\blog

的绝对路径

@Edit RiggsFolly

这是我现在在 httpd-vhosts.conf 文件中获得的

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"

    <Directory "C:/wamp/www">
        AllowOverride All
        # make sure this is only allowed to be accessed by the local machine
        # then if/when you open one of your other sites up to the internet and somebody uses your IP
        # they will get directed here as its the first VH def and then receive a 403 not allowed to access
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/websites/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

    <Directory "C:/websites/blog/public">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted        
    </Directory>
</VirtualHost>

我按照你的建议在C:/称为'网站'创建了一个新目录

1 个答案:

答案 0 :(得分:4)

您需要更加具体地了解文件夹位置。我想本教程是为Unix编写的,你使用的是Windows。

对于Apache 2.2.x,请使用以下语法:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/wamp/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

<Directory "C:/wamp/www/blog/public">
    DirectoryIndex index.php
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

您最好避开Allow from all并使用Allow from localhost 127.0.0.1 ::1,直到您确实希望允许Universe查看您的网站。

对于Apache 2.4.x,请使用以下语法:

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/wamp/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

<Directory "C:/wamp/www/blog/public">
    DirectoryIndex index.php
    AllowOverride All
    Require all granted        
</Directory>
Apache 2.4.x不再需要

注意 NameVirtualHost *:80

再次,您最好避开Require all granted并使用Require local,直到您确实希望允许Universe查看您的网站。

编辑在发问者的评论之后:

是的,那是Apache的默认值。如果您输入的网址无法找到虚拟主机定义,则默认为您提供的第一个虚拟主机定义,即您的博客。

好的,现在你需要为你的每个其他项目创建一个虚拟主机,而且最重要的是第一个需要localhost并且只允许从本地PC有一点额外的安全性。

现在我个人借此机会将我的实际网站移动到\ wamp \文件夹结构之外的完全独立的文件夹结构中,这样就不会混淆对\ wamp \ www文件夹和其他网站的权限。

例如,创建一个文件夹c:\websites\www并在该文件夹中为每个项目创建一个文件夹,例如

c:\websites\www\blog
c:\websites\www\project2

然后将虚拟主机指向包含站点代码的相关文件夹(如果您愿意,可以在另一个磁盘上)。这允许您专门为每个VHOSTS指定Apache安全性(允许进入此站点的用户)。因此,当您希望客户或朋友能够使用一个站点时,您只需更改该站点的安全性,同时让它们播放。

像这样:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/wamp/www"

    <Directory "C:/wamp/www">
        AllowOverride All
        # make sure this is only allowed to be accessed by the local machine
        # then if/when you open one of your other sites up to the internet and somebody uses your IP
        # they will get directed here as its the first VH def and then receive a 403 not allowed to access
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName blog.local
    DocumentRoot "C:/websites/www/blog/public"
    Options Indexes FollowSymLinks
    SetEnv APPLICATION_ENV "development"

    <Directory "C:/websites/www/blog/public">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted        
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName project2.dev
    DocumentRoot "C:/websites/www/project2"
    Options Indexes FollowSymLinks

    <Directory "C:/websites/www/project2">
        DirectoryIndex index.php
        AllowOverride All
        Require local
        # this site also available to other PC's on my internal network
        Require ip 192.168.0
    </Directory>
</VirtualHost>

请记住,对于您创建的每个新虚拟主机站点,您还需要将该ServerName(project2.dev)添加到hosts文件中。

hosts file:
127.0.0.1  blog.local
127.0.0.1  project2.dev

我希望这会有所帮助。