草庐IT

php - 在 Wamp 服务器上为 Z​​end 应用程序设置 VirtualHost

coder 2024-06-17 原文

我正在按照本教程学习如何使用 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/

时,浏览器仍然显示 Not Found The requested URL/public was not found on this server

我在 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:/中创建了一个名为“websites”的新目录

最佳答案

您需要更具体地指定您的文件夹位置。我猜本教程是为 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 直到您真正想让整个世界看到您的网站。

对于 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,直到您真正想让全世界都看到您的网站为止。

在发问者发表评论后编辑:

没错,这是 Apache 的默认设置。如果您输入一个 url,它找不到虚拟主机定义,因为它将默认为您给它的第一个虚拟主机定义,在您的例子中是博客。

好的,现在您需要为每个其他项目创建一个虚拟主机,最重要的是,第一个 需要是 localhost 并且只允许可以从本地 PC 访问以获得额外的安全性。

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

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

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

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

像这样:

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

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

hosts file:
127.0.0.1  blog.local
127.0.0.1  project2.dev

希望对您有所帮助。

关于php - 在 Wamp 服务器上为 Z​​end 应用程序设置 VirtualHost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21719300/

有关php - 在 Wamp 服务器上为 Z​​end 应用程序设置 VirtualHost的更多相关文章

  1. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  2. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  3. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  4. ruby-on-rails - Rails 应用程序之间的通信 - 2

    我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此

  5. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  6. ruby-on-rails - Rails 应用程序中的 Rails : How are you using application_controller. rb 是新手吗? - 2

    刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr

  7. ruby-on-rails - 启动 Rails 服务器时 ImageMagick 的警告 - 2

    最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru

  8. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  9. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  10. ruby - 用 Ruby 编写一个简单的网络服务器 - 2

    我想在Ruby中创建一个用于开发目的的极其简单的Web服务器(不,不想使用现成的解决方案)。代码如下:#!/usr/bin/rubyrequire'socket'server=TCPServer.new('127.0.0.1',8080)whileconnection=server.acceptheaders=[]length=0whileline=connection.getsheaders想法是从命令行运行这个脚本,提供另一个脚本,它将在其标准输入上获取请求,并在其标准输出上返回完整的响应。到目前为止一切顺利,但事实证明这真的很脆弱,因为它在第二个请求上中断并出现错误:/usr/b

随机推荐