设置 symfony 项目并更改主机文件后,非 symfony 项目不再在 apache 上运行?

发布于 2024-11-30 20:38:07 字数 1054 浏览 0 评论 0原文

我正在使用xampp。

我已经在 symfony 中设置了一个项目并将其添加到 apaches httpd.conf:

<VirtualHost 127.0.0.1:80>
  ServerName www.plusoneboosters.com.localhost
  DocumentRoot "C:\my_xampp\xampp\htdocs\plusoneboosters\web"
  DirectoryIndex index.php
  <Directory "C:\my_xampp\xampp\htdocs\plusoneboosters\web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf "C:\my_xampp\xampp\htdocs\plusoneboosters\lib\vendor\symfony\data\web\sf"
  <Directory "C:\my_xampp\xampp\htdocs\plusoneboosters\lib\vendor\symfony\data\web\sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

我还将其添加到主机文件(Windows):

127.0.0.1 www.plusoneboosters.com.localhost

该项目可以工作,但是所有未安装 symfony 的项目都不再工作 - 正在运行localhost/project/index.php 将重定向到 symfony 项目。

我怀疑这是因为 htaccess 发生的,但不知道要替换什么才能使其工作。

我也尝试添加另一个虚拟主机,但没有成功。

我该如何解决这个问题?

编辑:我想我找到了解决方案。

我在 httpd.conf 中添加了另一个具有不同 IP 的虚拟主机:127.0.0.2,现在似乎工作正常。我不确定这是否是正确的方法......

I am using xampp.

I've set up a project in symfony and added this to apaches httpd.conf:

<VirtualHost 127.0.0.1:80>
  ServerName www.plusoneboosters.com.localhost
  DocumentRoot "C:\my_xampp\xampp\htdocs\plusoneboosters\web"
  DirectoryIndex index.php
  <Directory "C:\my_xampp\xampp\htdocs\plusoneboosters\web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf "C:\my_xampp\xampp\htdocs\plusoneboosters\lib\vendor\symfony\data\web\sf"
  <Directory "C:\my_xampp\xampp\htdocs\plusoneboosters\lib\vendor\symfony\data\web\sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

I also added this to hosts file (Windows):

127.0.0.1 www.plusoneboosters.com.localhost

This project works, but all the projects that are not installed with symfony aren't working anymore - running localhost/project/index.php will redirect to the symfony project.

I suspect this is happening because htaccess, but do not know what to replace in order to make it work.

I also tried adding another virtual host, didn't work.

How can I work around this?

Edit: I think I found a solution.

I added another Virtual host in httpd.conf with a different IP: 127.0.0.2 and it seems to be working fine now. I'm not sure if this is the right way to do it though...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李白 2024-12-07 20:38:07

当您开始使用虚拟主机时,您需要定义至少两个虚拟主机以保持旧配置正常工作,否则您的 symphony 虚拟主机将成为默认虚拟主机并拦截所有请求。因此,在 symphony vhost 配置之前添加以下行到您的 apache 配置中

# this allows vhost based on hostname and NOT on ip only
NameVirtualHost *

<VirtualHost _default_>
  ServerName localhost
  DocumentRoot "your old document root"
  DirectoryIndex index.php
  <Directory "your old root document root">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *>
  ServerName www.plusoneboosters.com.localhost
  ...
</VirtualHost>

如果您有权访问 apache 命令行工具,您可以使用 apachectl -S 来检查 vhost 配置和优先级,它会为您提供所有定义的虚拟主机

Apache 虚拟主机示例

When you start to use virtual hosts you need to define at least two of them to keep your old configuration working otherwise your symphony vhost became the default vhost and intercept all the requests. So add to your apache configuration the following lines BEFORE the symphony vhost configuration

# this allows vhost based on hostname and NOT on ip only
NameVirtualHost *

<VirtualHost _default_>
  ServerName localhost
  DocumentRoot "your old document root"
  DirectoryIndex index.php
  <Directory "your old root document root">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

<VirtualHost *>
  ServerName www.plusoneboosters.com.localhost
  ...
</VirtualHost>

If you have access to apache command line tool you can check the vhost configuration and priority with apachectl -S which gives you a report of all the defined virtual hosts

Apache virtual host examples

不及他 2024-12-07 20:38:07

我在 Xampp for Symfony 中的设置是:

  • 在主机文件中为我的项目添加条目(例如 127.0.0.1 www.jobeet.com.localhost

  • 确保conf/extra/httpd-vhosts.conf包含在httpd.conf中(我相信它是默认的:)

    # Virtual hosts
    Include "conf/extra/httpd-vhosts.conf"
  • 在conf/extra/httpd-vhosts.conf 中,添加(取消注释) & 编辑)默认主机的条目:
    
        ServerName localhost
        DocumentRoot "C:/Matt/xampp/htdocs/"
        ErrorLog "logs/localhost-error.log"
        CustomLog "logs/localhost-access.log" combined
    
  • 然后,在其下方添加 Symfony 项目的条目:
    
    ServerName www.jobeet.com.localhost
    DocumentRoot "C:/Matt/xampp/htdocs/jobeet/web"
    DirectoryIndex index.php
    
        AllowOverride All
        Allow from All
    
    Alias /sf "C:/Matt/xampp/htdocs/jobeet/lib/vendor/symfony/data/web/sf"
    
        AllowOverride All
        Allow from All
    
    

请注意,我没有在 httpd.conf 文件中添加任何 VirtualHost 条目本身。这个设置对于我使用最新的 Xampp 来说效果很好,我可以访问 http://localhost/test.html 和 http://www.jobeet.com.localhost 。 > 很好。

My setup in Xampp for Symfony is:

  • Add entry for my project in hosts file (e.g. 127.0.0.1 www.jobeet.com.localhost)

  • Make sure conf/extra/httpd-vhosts.conf is included in httpd.conf (I believe it is by default:)

    # Virtual hosts
    Include "conf/extra/httpd-vhosts.conf"
  • In conf/extra/httpd-vhosts.conf, add (uncomment & edit) the entry for the default host:
    
        ServerName localhost
        DocumentRoot "C:/Matt/xampp/htdocs/"
        ErrorLog "logs/localhost-error.log"
        CustomLog "logs/localhost-access.log" combined
    
  • Then, below that, add the entry for the Symfony project(s):
    
    ServerName www.jobeet.com.localhost
    DocumentRoot "C:/Matt/xampp/htdocs/jobeet/web"
    DirectoryIndex index.php
    
        AllowOverride All
        Allow from All
    
    Alias /sf "C:/Matt/xampp/htdocs/jobeet/lib/vendor/symfony/data/web/sf"
    
        AllowOverride All
        Allow from All
    
    

Note that I've not added any VirtualHost entries in the httpd.conf file itself. This setup works fine for me with the latest Xampp, and I can visit both http://localhost/test.html and http://www.jobeet.com.localhost just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文