Symfony: Yui CSS compression with Assetic on Windows (WAMP) systems [SOLVED]

When I read about Symfony’s Assetic’s filters I felt quite excited and decided to try yui_css filter. When it comes to linux, everything worked just fine out of the box with the last Symfony release. But when I tried it in my Windows machine, it kept complaining ([exception] 500 | Internal Server Error | RuntimeException | blah-blah) and it has not an easy task to make yui work.

Just in case anyone can use this, here are the steps I followed to fix it:

0. Install JAVA JRE (in c:\Program Files (x86)\Java\jre6\), set the classpath and so on…

1. Prepare your templates for the use of filter='yui_css'. For instance (notice line 6):

1
2
3
4
5
6
7
8
9
{% stylesheets
	'@cursoe5Bundle/Resources/public/css/layout/mainStyle.css'
	'@cursoe5Bundle/Resources/public/css/layout/reset.css'
	'@cursoe5Bundle/Resources/public/css/layout/colors.css'
			output = 'css/compiled/styles.css'
			filter = 'yui_css'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
{% endstylesheets %}

2. Edit www-wamp-dir\Symmfony\config\config.yml and set the java path and the yui_css path. Here is my Assetic Configuration in config.yml (edit lines 5 and 11!)

1
2
3
4
5
6
7
8
9
10
11
# Assetic Configuration (www-wamp-dir\Symmfony\config\config.yml)
assetic:
    debug:          %kernel.debug%
    use_controller: false
    java: c:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe
    filters:
        cssrewrite: ~
        yui_css: 
            jar: %kernel.root_dir%\Resources\java\yuicompressor-2.4.7.jar
        # closure:
        #     jar: %kernel.root_dir%/java/compiler.jar

3. Download the last yui compressor jar (yuicompressor-2.4.7) and extract its contents.
Move the jar (usually located in the ‘build’ folder) to the Symfony %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar (%kernel.root_dir% is the one called ‘app’, which contains cache, config, logs, … folders. You should mkdir Resources and java folders inside).

3. If you get errors like “Runtime exception ...” (as this guy does) download the last Assetic stable release from assetic github and extract its contents.
Rename the extracted folder -originally called something like ‘kriswallsmith-assetic-b25d1fd‘)- to ‘assetic‘ and move it to wamp-www-dir\Symfony\vendor\ (will replace the old version! make sure you backup the old stuff before doing this!)

4. Assetic relies on Process Module. Previous version of Assetic had the code of Process module directly copied into Assetic (and had some bugs, like the PHP_WINDOWS_VERSION_MAJOR issue), but the last one just relies on the Symfony’s Process Module. [I recommend using Composer to make your life easier]

If you test your site and the CSS is broken, it is likely to be because of this. Check for something like “Fatal error: Class 'Symfony\Component\Process\ProcessBuilder' not found in src/Assetic/Filter“.
This means you have not installed ProcessBuilder, so download the last Process Module, which includes ProcessBuilder.
Extract the folder (originally called something like ‘symfony-Process-2e4da8c‘), rename it to ‘Process‘ and move it to wamp-www-dir\Synfony\vendor\symfony\src\Symfony\Component (will replace the old version! make sure you backup the old stuff before doing this!)

5. If you followed the steps, everything should be working by now. If you find some annoying messages like something was not found, or command not valid, or so, please make sure you have your cache cleared and your assets dumped:

php app/console --env=dev cache:clear
php app/console --env=dev cache:clear --no-debug
php app/console --env=dev assets:install web --no-debug
php app/console --env=dev assetic:dump --no-debug

Good luck! :)

2 Thoughts on “Symfony: Yui CSS compression with Assetic on Windows (WAMP) systems [SOLVED]

  1. Pingback: Symfony: create and update an Entity using doctrine [FULL EXAMPLE] | Informática - web | leccionespracticas.com

  2. You saved me so much time with this. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation