musicmaster Posted February 13, 2025 Share Posted February 13, 2025 (edited) Suddenly I had in my PS 8.2 a "Failed to start the session" error that blocked me from entering my backoffice. I tried emptying the cache and deleting the browser cookies but without effect. What finally helped was forcing Prestashop to create a new session key. The error happened on line 193 of /vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php This was the relevant code: if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,250}$/', $sessionId)) { // the session ID in the header is invalid, create a new one session_id(session_create_id()); } // ok to try and start the session if (!session_start()) { throw new \RuntimeException('Failed to start the session.'); } What helped was changing it to: if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,250}$/', $sessionId)) { // the session ID in the header is invalid, create a new one session_id(session_create_id()); } session_id(session_create_id()); /* ADDED CODE */ // ok to try and start the session if (!session_start()) { throw new \RuntimeException('Failed to start the session.'); } Of course after I had successfully logged in into the backoffice I undid this change. Edited February 13, 2025 by musicmaster (see edit history) Link to comment Share on other sites More sharing options...
Ewonta Posted February 14, 2025 Share Posted February 14, 2025 This usually happens when your hosting or server has session recording disabled. Link to comment Share on other sites More sharing options...
Marco Rinaldi Posted February 6 Share Posted February 6 [SOLVED] Failed to start session - Alternative fix without Core Hacks (Hosting/Path issue) Hi everyone, I recently faced the "Failed to start the session" error on PrestaShop 8.2 (PHP 8.1/8.2) on a shared Linux hosting. While many suggest patching the Symfony core files, I found a cleaner solution that addresses the root cause without touching the PrestaShop core. In my case, the issue wasn't the code, but the server's inability to write session files in the default system directory. How to diagnose and fix it: Enable Debug Mode Edit your /config/defines.inc.php file and set: define('_PS_MODE_DEV_', true); Identify the specific Error Check your Front Office or Back Office for a warning like this: Warning: SessionHandler::read(): open(/var/cpanel/php/sessions/alt-php81/..., O_RDWR) failed: No such file or directory If you see this, it means your hosting environment is trying to save sessions in a path that is either missing or restricted (common on cPanel/CloudLinux). Change the session.save_path Instead of fixing the code, change where PHP stores sessions. You can do this via your cPanel PHP Selector (Options tab) or by editing your .user.ini / php.ini file. Create a private folder in your hosting (preferably outside public_html) and set it as the path: session.save_path = "/home/youruser/php_sessions" Once I updated the path and cleared the /var/cache/ folder, the error disappeared completely without any core modifications. Hope this helps someone avoid hacking the vendor files! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now