meWantToLearn meWantToLearn - 3 months ago 16
Apache Configuration Question

symfony2 does not work fresh install

I downloaded symfony2 using composer

composer create-project symfony/framework-standard-edition path/ "2.5.*"


When I start it from the command line

php bin/console server:run


It displays

Server running on http://localhost:8000


but when I visit the url nothing appear.

In the log file this is what gets written

[09-Jul-2014 14:04:51 Europe/Berlin] PHP Warning: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in C:\xampp\htdocs\Symfony\app\cache\prod\appProdUrlMatcher.php:32
Stack trace:
#0 C:\xampp\htdocs\Symfony\vendor\symfony\symfony\src\Symfony\Component\Routing\Matcher\UrlMatcher.php(106): appProdUrlMatcher->match('/')
#1 C:\xampp\htdocs\Symfony\vendor\symfony\symfony\src\Symfony\Component\Routing\Router.php(233): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#2 C:\xampp\htdocs\Symfony\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php(125): Symfony\Component\Routing\Router->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#4 C:\xampp\htdocs\Symfony\vendor\symfony\symf in C:\xampp\htdocs\Symfony\app\cache\prod\appProdUrlMatcher.php on line 32

Answer

Symfony\Component\Routing\Exception\ResourceNotFoundException means undefined route name. It looks like you've got somewhere in your error template {{ path('wrong_route') }}.

If not there many other possibilities : vendor, cache or configuration issues.

For vendor try :

  • Remove all folders in your /vendor
  • Run in terminal : composer update

For cache :

  • Delete your app/cache/dev and app/cache/prod folders manually
  • Run in terminal : php app/console cache:clear
  • Run in terminal : php app/console assetic:dump

For configuration

  • Issue with .htaccess

    Check your web/.htaccess file, it must look like that :

    DirectoryIndex app.php
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
        RewriteRule ^(.*) - [E=BASE:%1]
    
        RewriteCond %{ENV:REDIRECT_STATUS} ^$
        RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule .? - [L]
    
        RewriteRule .? %{ENV:BASE}/app.php [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        <IfModule mod_alias.c>
            RedirectMatch 302 ^/$ /app.php/
        </IfModule>
    </IfModule>
    

    And check in your Apache configuration if mod_rewrite Apache module is enabled.
    To activate the module, the following line in httpd.conf needs to be active:

    LoadModule rewrite_module modules/mod_rewrite.so
    
  • Issue with timezone

    It seems you're using Europe/Berlin time so make sure there is this line in your php.ini : date.timezone = "Europe/Berlin"
    If not write it.
    If still doesn't work add this following lines in your app/AppKernel.php before clear your cache again :

    public function init()
    {
        date_default_timezone_set( 'Europe/Berlin' );
        parent::init();
    }