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.

5
  • 1
    Did you look into Configuring your Apache web server Vhost for Symfony2 website or Symfony 2 on virtual hosts Commented May 14, 2015 at 12:21
  • Wonderful ! Every tutorials I've seen totally missed the <IfModule>...</IfModule> part ! Thanks ! Commented May 14, 2015 at 14:53
  • I guess I should add an answer and you accept it so that everybody else can benefit from it. Commented May 14, 2015 at 14:57
  • I must say I have never seen <VirtualHost my-project.local>. This directive is supposed to have an interface like <VirtualHost *:80> Commented May 14, 2015 at 15:02
  • @BentCoder done ! @Broncha how is it "better" to have *:80 instead of my virtual host name ? Commented May 14, 2015 at 16:06

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.