0

I'm working with WAMP on Windows 7. Every time I try to create a Virtual Host to work with "clean" URLs for a Symfony2 project, I get 404 errors.

Here's my httpd.conf:

NameVirtualHost localhost

<VirtualHost localhost>     
    DocumentRoot "D:/Documents/wamp/"
    ServerName localhost    
</VirtualHost>

<VirtualHost my-project.local>
    ServerName my-project.local
    DocumentRoot "D:/Documents/wamp/my-project/web/"
    DirectoryIndex app.php
    <Directory "D:/Documents/wamp/my-project/web/">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

My hosts file:

127.0.0.1       my-project.local

When I try to reach http://my-project.local, I get a Symfony 404 error. When I check with http://my-project.local/app.dev, I'm redirected to http://my-project.local so I also get a 404 error and finally, when I try to reach http://my-project.local/app_dev.php, the correct page is loaded but with absolutely no CSS.

I also tried to replace DirectoryIndex app.php with DirectoryIndex app_dev.php but I still get 404.

I don't have any issue when I create Virtual Hosts for other projects powered by Laravel for example.

Flobesst
  • 1,281
  • 1
  • 16
  • 26
  • 1
    Did you look into [Configuring your Apache web server Vhost for Symfony2 website](https://breinjhel.wordpress.com/2012/10/30/configuring-your-apache-web-server-vhost-for-symfony2-website/) or [Symfony 2 on virtual hosts](http://stackoverflow.com/questions/8962054/symfony-2-on-virtual-hosts) – BentCoder May 14 '15 at 12:21
  • Wonderful ! Every tutorials I've seen totally missed the `...` part ! Thanks ! – Flobesst May 14 '15 at 14:53
  • I guess I should add an answer and you accept it so that everybody else can benefit from it. – BentCoder May 14 '15 at 14:57
  • I must say I have never seen ``. This directive is supposed to have an interface like `` – Broncha May 14 '15 at 15:02
  • @BentCoder done ! @Broncha how is it "better" to have `*:80` instead of my virtual host name ? – Flobesst May 14 '15 at 16:06

3 Answers3

3

Example VirtualHost 1)

Read for further info: https://breinjhel.wordpress.com/2012/10/30/configuring-your-apache-web-server-vhost-for-symfony2-website/

<VirtualHost *:80>
    ServerName yourproject.com
    DocumentRoot "C:/xampp/htdocs/yourproject/web"
    DirectoryIndex app_dev.php
    <Directory "C:/xampp/htdocs/yourproject/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_dev.php [QSA,L]
        </IfModule>
    </Directory>
</VirtualHost>

Example VirtualHost 2)

Read for further info: Symfony 2 on virtual hosts

<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>
Community
  • 1
  • 1
BentCoder
  • 12,257
  • 22
  • 93
  • 165
1

For Symfony 4:

<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com  
DocumentRoot "c:/wamp64/www/symfony4_mysite/public/index.php"
<Directory  "c:/wamp64/www/symfony4_mysite/public/index.php">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
</Directory>

Akın Köker
  • 405
  • 5
  • 7
0

If you check your web/.htaccess see you must have mod_rewrite enabled for apache, else fallback to app.php / app_dev.php. So check this module is loaded into your wamp.

For assets you must install them. In a terminal :

cd D:/Documents/wamp/my-project/

php app/console assets:install

This command must hardcopy assets bundles into web directory, try with --symlink for symbolic directory

bastien
  • 190
  • 1
  • 9
  • mod_rewrite is already enabled in Apache, so this isn't my issue's source. On the other side, concerning assets, you solved my problem :) – Flobesst May 14 '15 at 14:47