title: Rails 3.1 Deploy to Production (with Apache & Passenger) Asset Problems
body: <p>Rails 3.1 has changed the way it handles the asset pipeline and it is causing issues when deploying to production.</p>
  
  <p>I am using Apache and Passenger, which seem to work fine.</p>
  
  <p>My production is setup like this (for now).</p>
  
  <pre><code># congif/environments/production.rb
  config.cache_classes = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true
  config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  </code></pre>
  
  <p>I run rake assets:precompile on Ubuntu and start server.  And... nothing.  None of my images load.</p>
  
  <p>The legendary 'I can't find an image at this URL' box.</p>
  
  <p>I run rake assets:precompile on CentOS and start server.  And... permission errors.</p>
  
  <pre><code>*Error Compiling CSS Asset*
  Errno::EACCESS: Permission Denied - [app path]/tmp/cache/assets/E95
  [path to RVM Ruby]/fileutils.rb:243:in 'mkdir'
  </code></pre>
  
  <p>I can't get it to budge.  Any help is greatly appreciated.  Thank you!</p>
  
  <h2>UPDATE</h2>
  
  <p>This solution has worked every time for me:</p>
  
  <p>First Clean out your Assets</p>
  
  <pre><code>rm -rf public/assets
  </code></pre>
  
  <p>and</p>
  
  <pre><code>rake assets:clean RAILS_ENV=production
  </code></pre>
  
  <p>Second, in #production.rb change</p>
  
  <pre><code>config.assets.compile = false
  </code></pre>
  
  <p>to</p>
  
  <pre><code>config.assets.compile = true
  </code></pre>
  
  <p>Third, run to precompile your assets</p>
  
  <pre><code>rake assets:precompile RAILS_ENV=production
  </code></pre>
  
  <p>Fourth, in #production.rb change</p>
  
  <pre><code>config.assets.compile = true
  </code></pre>
  
  <p>back to</p>
  
  <pre><code>config.assets.compile = false
  </code></pre>
  
  <p>Fifth, restart your server by running:</p>
  
  <pre><code>touch tmp/restart.txt
  </code></pre>
  
  <p>Sixth, un-restrict permissions on your newly created assets by running this command</p>
  
  <p>chmod -R 777 public/assets</p>
  
  <p>Seventh, celebrate!!</p>