This error occurs because the framework: session: parameters in "app/config.yml" are not set properly so without the fix below, Symfony2 application will try to store the session data in non existing or unpermitted path.


Warning: SessionHandler::read(): open(/var/lib/php5/sessions/sess_tb9m9, O_RDWR) failed: Permission denied (13)
500 Internal Server Error - ContextErrorException



Update config file


Set handler_id and save_path parameters because Symfony2 uses session handler from "php.ini" by default and it will highly likely have no value assigned to it. Click here for more information.


# app/config/config.yml
framework:
.....
.....
session:
handler_id: session.handler.native_file
save_path: "%kernel.cache_dir%/sessions"
.....
.....

Clear your cache


You might need to define environment with --env= tag if necessary. By default, command below would clear the cache of "dev" environment. Click here for more information.


php app/console cache:clear

Grant Symfony2 "write" permissions


Commands below apply to Ubuntu. Click here for more information.


HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d  -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs