title: Symfony2 : Failed to start the session because headers have already been sent
body: <p>TL;DR
  Getting an error on a Linux box with Nginx / PHP-FPM stating "Failed to start the session because headers have already been sent.". Error is not occurring on Apache local machine setup</p>
  
  <p>So on my local machine I have the Symfony2 app running fine. No errors are popping up. But as soon as I deploy to our Linux Server I'm getting this error when I call a certain Action within a Controller class</p>
  
  <pre><code>Failed to start the session because headers have already been sent. 
  </code></pre>
  
  <p>In the index action I have already called </p>
  
  <pre><code>$session = $this-&gt;getRequest()-&gt;getSession();
  </code></pre>
  
  <p>And in another action within the same controller class I'm calling it again.  The error pops up when I try a </p>
  
  <pre><code>$session-&gt;set('foo', $bar);
  </code></pre>
  
  <p>In my Twig I'm calling the action by a form and a button with a formaction property like so</p>
  
  <pre><code>&lt;form id='blahblah'&gt;
      .... some fields here .....
      &lt;button type='submit' formaction='{{path('2ndAction')}}'&gt;&lt;/a&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So on my local machine, running Apache everything run fine. The Linux server is using Nginx and php-fpm and it's crashing for some reason. I checked the phpInfo() and the session auto start is set to off. Not sure if this is an Nginx/php-fpm issue or not but I thought it may be pertinent information.</p>
  
  <p>Here is the Controller declaration, indexAction(),  and my 2ndAction()</p>
  
  <pre><code>use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\HttpFoundation\Session\Session;    
  use CBSi\Utils\HTTPUtils\CURLUtil;
  
  class StartController extends Controller
  {
      /**
       * @var  CurlUtil $curlUtil
       */
      private $curlUtil;
  
      /**
       * @var AccessControl $accessControl
       */
  
      private $accessControl;
  
      /*placeholder for request object*/
      private $requestHolder;
  
  
     /**
      * @Route("/path/for/action/one", name="start")
      * @Template()
      */
  
  
  public function indexAction()
  {
   $session = $this-&gt;getRequest()-&gt;getSession();
   $this-&gt;curlUtil = $this-&gt;get('curlUtil');
   $this-&gt;requestHolder= Request::createFromGlobals();
  
  // Some logic is done here
  
  
  return $this-&gt;render('ListEngagementBundle:Start:start.html.twig');
  
  }
  
  /**
   * @Route("/path/to/second/action", name="2ndAction")
   * @Template
   */
  public function 2ndAction(){
      $session = $this-&gt;getRequest()-&gt;getSession();
      $this-&gt; curlUtil = $this-&gt;get('curlUtil');
      $this-&gt;requestHolder= Request::createFromGlobals();
  
      //Some logic is done here to get the data for the session variable
  
         $bar= logic output
  
                 $session-&gt;set('foo', $bar);
  
      return $this-&gt;redirect($this-&gt;generateUrl('start'));
  }
  }
  </code></pre>
  
  <p>If you need more info that I can provide I will :)</p>