title: Phusion Passenger + Workling + RabbitMQ
body: <p>I am trying to deploy a RoR app that does some asynchronous task. I use workling for that and the message queue is RabbitMQ. This combination worked flawlessly with Starling but we decided to change the MQ for Rabbit. 
  I read somewhere that I should include the following code in my environment.rb</p>
  
  <pre><code>require 'mq' 
  if defined?(PhusionPassenger) 
    PhusionPassenger.on_event(:starting_worker_process) do |forked| 
      if forked 
        if EM.reactor_running? 
          EM.stop_event_loop 
          EM.release_machine 
          EM.instance_variable_set( '@reactor_running', false ) 
        end 
        Thread.current[:mq] = nil 
        AMQP.instance_variable_set('@conn', nil) 
      end 
      th = Thread.current 
      Thread.new{ 
        AMQP.connect(:host =&gt; 'localhost'){ 
          th.wakeup 
        } 
      } 
      Thread.stop 
    end 
  end 
  </code></pre>
  
  <p>But that now Apache fails completely with message: The server encountered an internal error or misconfiguration and was unable to complete your request</p>