开发者

After seting up a symfony project and changing hosts file, the non-symfony projects aren't working anymore on apache?

开发者 https://www.devze.com 2023-03-29 08:17 出处:网络
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>

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号