12

I have a problem here with Symfony 2. I want to have virtual host on Windows Vista PC, so I can access my Symfony application like this myapp.local.com. What I have tried:

  • I added these lines to hosts file

    127.0.0.1 local.com    
    127.0.0.1 myapp.local.com
    
  • These I added to apache httpd-vhosts.conf

    < VirtualHost myapp.local.com:80 >
       DocumentRoot "d:/data/www/myapp/web"
       ServerName myapp.local.com
       Alias /sf /$sf_symfony_data_dir/web/sf
    < Directory "/$sf_symfony_data_dir/web/sf" >
       AllowOverride All
       Allow from All
    < /Directory >
    < Directory "d:/data/www/myapp/web" >
       AllowOverride All
       Allow from All
    < /Directory >
    < /VirtualHost >
    

but when I write myapp.local.com in my browser, it brings the index of my www directory. What am I doing wrong?

ArVan
  • 4,225
  • 8
  • 36
  • 58

2 Answers2

49

You are using the virtualhost configuration proposed for Symfony 1.

My virtualhost for Symfony2 under linux looks like this:

<VirtualHost *:80>
    ServerName www.domain.com.localhost
    ServerAlias domain.com.localhost
    ServerAdmin webmaster@localhost

    DocumentRoot /home/user/www/project/web
    <Directory /home/user/www/project/web/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ /app.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

Try this (adapted to your config in windows), restart Apache, and try accessing the URL again.

You will find more informations on Symfony2 virtual hosts on this cookbook entry.

Nanocom
  • 3,696
  • 4
  • 31
  • 46
  • Ok, forgot the '/' in `Directory /home/user/www/project/web/>` line. Now I get the index of `web/` folder. Need to change something to refer to app.php I guess. – ArVan Jan 22 '12 at 16:54
  • 3
    You need to install the mod_rewrite apache module – Nanocom Jan 22 '12 at 17:14
  • 3
    Or add line DirectoryIndex app.php – Nanocom Jan 22 '12 at 17:14
  • Thank you @Nanocom, that module was really missing :) – ArVan Jan 22 '12 at 17:33
  • 1
    Symfony 1.x explicitly laid out vhost config in every demo/tutorial....why the hell is there a universal absence of all things vhost related in symfony2 documentation? Am I missing something? – herringtown Mar 16 '13 at 23:11
  • 1
    @herringtown [and what about this](http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html) The preferred (and easiest) way to start using Symfony2 is to use the php's built in web server and the `php ./app/console server:run` command. If you want to use a web server you probably know how to configure it and if not you should consult the web server's documentation. – 1ed Jun 17 '13 at 21:15
  • Don't forget to go to the app_dev.php – Szenis Jun 08 '15 at 17:44
  • Works with Symfony 4, just change `app.php` by `index.php` – Benj Jun 29 '19 at 00:35
0

Windows version for symfony 3.4:
Just simple like this:

C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
  DocumentRoot "C:/xampp/htdocs/symfony_CRUD/web"
  DirectoryIndex app_dev.php
  ServerName fudu.symfony.net
</VirtualHost>

C:\Windows\System32\drivers\etc

127.0.0.1 fudu.symfony.net

Then you go fudu.symfony.net/app_dev.php
Hope it help some one :)

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
fudu
  • 617
  • 1
  • 10
  • 19