在Wamp服务器上为Zend应用程序设置VirtualHost [英] Setup VirtualHost for Zend Application on Wamp server

查看:81
本文介绍了在Wamp服务器上为Zend应用程序设置VirtualHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照本教程学习如何使用ZendFramework启动项目

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

当我设置虚拟主机时,我被卡住了.如果未按照本教程中的说明进行操作,则会显示错误(在我的所有项目中,无论是否为zend),都找不到文件.

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

无法在WAMP上运行zend框架MVC应用程序

按照页面底部的提示,当我尝试以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/

时,浏览器仍然显示未找到请求的URL/public在此服务器上未找到

我正在Windows上运行WAMP.这是博客"项目C:\wamp\www\blog

的绝对路径

@编辑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:/创建了一个名为网站"的新目录

解决方案

您需要更加具体地说明文件夹的位置.我猜本教程是为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>

注意 NameVirtualHost *:80 Apache 2.4.x不再需要

再次,最好避免使用Require all granted并使用Require local,直到您真正希望让Universe看到您的站点为止.

已编辑,在发问者留言后:

对,这是Apache的默认设置.如果输入url,它将找不到虚拟主机定义,因为它将默认为您提供的第一个虚拟主机定义,即您的博客.

好,所以现在您需要为其他每个项目创建一个虚拟主机,并且最重要的是,第一个必须为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 file:
127.0.0.1  blog.local
127.0.0.1  project2.dev

我希望这会有所帮助.

I'm following this tutorial to learn how to start a project using ZendFramework

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

When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.

Then I found this tutorial on StackOverflow very handy

Can't run zend framework MVC application on WAMP

Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/

This is what I got

on hosts (Windows/System32/drivers/etc/hosts) file

127.0.0.1       blog.local

on httpd-vhosts.conf file

<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>

Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/

I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog

@Edit RiggsFolly

this is what I got now in the httpd-vhosts.conf file

<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>

And I created a new directory at C:/ called 'websites' as you suggested

解决方案

You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.

For Apache 2.2.x use this syntax:

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>

You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.

For Apache 2.4.x use this syntax:

<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>

Note NameVirtualHost *:80 no longer required for Apache 2.4.x

Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.

EDITED After comment from Questioner:

Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.

Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.

Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.

So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg

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

Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.

Like this:

<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>

Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.

hosts file:
127.0.0.1  blog.local
127.0.0.1  project2.dev

I hope this helps.

这篇关于在Wamp服务器上为Zend应用程序设置VirtualHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆