TL DR Getting an error in a Linux box with Nginx / PHP-FPM with the message "The session could not start because the headers have already been sent." Error installing local Apache machine
So, on my local machine, the Symfony2 application is working fine. No errors appear. But as soon as I deploy to our Linux server, I get this error when I call a specific action in the controller class
Failed to start the session because headers have already been sent.
In the index action, I have already named
$session = $this->getRequest()->getSession();
And in another action within the same controller class, I call it again. An error appears when I try to execute
$session->set('foo', $bar);
In my Twig, I invoke an action with a form and a button with the same formaction property
<form id='blahblah'> .... some fields here ..... <button type='submit' formaction='{{path('2ndAction')}}'></a> </form>
So, on my local machine running Apache, everything is working fine. The Linux server uses Nginx and php-fpm, and for some reason it crashes. I checked phpInfo () and automatic session start is disabled. Not sure if this is a Nginx / php-fpm problem or not, but I thought it might be relevant information.
Here is the controller declaration, indexAction () and my 2ndAction ()
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 { private $curlUtil; private $accessControl; private $requestHolder; public function indexAction() { $session = $this->getRequest()->getSession(); $this->curlUtil = $this->get('curlUtil'); $this->requestHolder= Request::createFromGlobals();
If you need more information that I can provide, I will :)