Symfony2 LessPHP works fine in dev environment but not in prod

1.5k Views Asked by At

I have a website under Symfony2 using LessPHP. In dev environment everything works fine. When I hit http://mylocalsite/app_dev.php/ the browser reaches http://mylocalsite/app_dev.php/css/XXXX_myFile_1.css.

But when I hit http://mylocalsite/ the browser tries to reach http://mylocalsite/css/XXXX_myFile_1.css and gets a 404 error.

prod.log contains no more than this

[2014-01-24 12:08:46] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /css/XXXX_myFile_1.css"" at /the/path

The config.yml

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        lessphp:
            apply_to: "\.less$"
            file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
            # Formatter options: compressed, lessjs, classic
            formatter: "compressed"
            preserve_comments: false

The twig template

{% stylesheets '@ProjectMyBundle/Resources/less/myFile.less' %}
    <link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

EDIT

I did php app/console assetic:dump --env=prod --no-debug which gave me a web/css/XXXX.css file. But the browser is still looking for a file called XXXX_myFile_1.css.

I tried to set the output like this

{% stylesheets output='css/myFile.css'
    '@ProjectMyBundle/Resources/less/myFile.less' %}
    <link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

Executed php app/console assetic:dump --env=prod --no-debug another time which gave me a web/css/myFile.css file. But now the browser is looking for a file called myFile_myFile_1.css.

ANSWER

use_controller must be set to true in the config.yml file.

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You need to dump the assets (= assetic will combine all these assets into one big file). On the dev environment the file is served through the main controller and is generated dynamically. When you deploy an app, you should dump the assets using

php app/console assetic:dump --env=prod --no-debug

So as to generate these files physically on the file system. Read more in the Symfony docs.