If you are a system administrator and have encountered the following error in your PHP logs:
PHP Warning: SessionHandler::write(): open(/var/cpanel/php/sessions/alt-php74/sess_ecc8f1037c9adc71a4c2a75064937e24, O_RDWR) failed: No such file or directory (2) in /home/user/public_html/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php on line 64 PHP Warning: session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /var/cpanel/php/sessions/alt-php74) in /home/user/public_html/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php on line 266
You are not alone. This error occurs when PHP cannot write to the specified path for saving sessions, usually caused by using the PHP Selector from CloudLinux.
Here, we explain how to fix this issue in a cPanel environment with CloudLinux 8, cPanel, and CageFS.
Step 1: Verify the existence of directories
First, make sure that the directories mentioned in the error exist. In this case, the directory is /var/cpanel/php/sessions/alt-php74. To create them, use the following commands (I include all versions from PHP 4.4 to PHP 8.3):
mkdir -p /var/cpanel/php/sessions/alt-php44 mkdir -p /var/cpanel/php/sessions/alt-php51 mkdir -p /var/cpanel/php/sessions/alt-php52 mkdir -p /var/cpanel/php/sessions/alt-php53 mkdir -p /var/cpanel/php/sessions/alt-php54 mkdir -p /var/cpanel/php/sessions/alt-php55 mkdir -p /var/cpanel/php/sessions/alt-php56 mkdir -p /var/cpanel/php/sessions/alt-php70 mkdir -p /var/cpanel/php/sessions/alt-php71 mkdir -p /var/cpanel/php/sessions/alt-php72 mkdir -p /var/cpanel/php/sessions/alt-php73 mkdir -p /var/cpanel/php/sessions/alt-php74 mkdir -p /var/cpanel/php/sessions/alt-php80 mkdir -p /var/cpanel/php/sessions/alt-php81 mkdir -p /var/cpanel/php/sessions/alt-php82 mkdir -p /var/cpanel/php/sessions/alt-php83
chmod 1777 /var/cpanel/php/sessions/alt-php44 chmod 1777 /var/cpanel/php/sessions/alt-php51 chmod 1777 /var/cpanel/php/sessions/alt-php52 chmod 1777 /var/cpanel/php/sessions/alt-php53 chmod 1777 /var/cpanel/php/sessions/alt-php54 chmod 1777 /var/cpanel/php/sessions/alt-php55 chmod 1777 /var/cpanel/php/sessions/alt-php56 chmod 1777 /var/cpanel/php/sessions/alt-php70 chmod 1777 /var/cpanel/php/sessions/alt-php71 chmod 1777 /var/cpanel/php/sessions/alt-php72 chmod 1777 /var/cpanel/php/sessions/alt-php73 chmod 1777 /var/cpanel/php/sessions/alt-php74 chmod 1777 /var/cpanel/php/sessions/alt-php80 chmod 1777 /var/cpanel/php/sessions/alt-php81 chmod 1777 /var/cpanel/php/sessions/alt-php82 chmod 1777 /var/cpanel/php/sessions/alt-php83
Step 2: Edit the cagefs.mp file
Add the following lines to the end of your /etc/cagefs/cagefs.mp
file so that CageFS includes these directories in its environment:
@/var/cpanel/php/sessions/alt-php44,700 @/var/cpanel/php/sessions/alt-php51,700 @/var/cpanel/php/sessions/alt-php52,700 @/var/cpanel/php/sessions/alt-php53,700 @/var/cpanel/php/sessions/alt-php54,700 @/var/cpanel/php/sessions/alt-php55,700 @/var/cpanel/php/sessions/alt-php56,700 @/var/cpanel/php/sessions/alt-php70,700 @/var/cpanel/php/sessions/alt-php71,700 @/var/cpanel/php/sessions/alt-php72,700 @/var/cpanel/php/sessions/alt-php73,700 @/var/cpanel/php/sessions/alt-php74,700 @/var/cpanel/php/sessions/alt-php80,700 @/var/cpanel/php/sessions/alt-php81,700 @/var/cpanel/php/sessions/alt-php82,700 @/var/cpanel/php/sessions/alt-php83,700
Step 3: Update and remount CageFS
After editing cagefs.mp, you need to rebuild and update CageFS for the changes to take effect:
cagefsctl --force-update cagefsctl --update cagefsctl --remount-all
Step 4: Verify the changes
To make sure the changes have been applied correctly, you can enter the CageFS environment of a specific user and verify that the directories are present:
cagefsctl --enter <username> ls /var/cpanel/php/sessions/
Replace with the username to verify that the new directories are present.
Conclusion
By following these steps, you should have resolved the PHP session writing issue within a cPanel environment with CloudLinux 8 and CageFS. Ensure that the session directories exist and are correctly configured in cagefs.mp, and always rebuild and update CageFS after making configuration changes.
SEO Keywords (ignore this)
- SessionHandler::write() failed: No such file or directory
- PHP session_write_close() error
- cPanel PHP sessions directory missing
- CloudLinux 8 CageFS session handling
- How to fix PHP session errors in cPanel
- Session directories in CageFS
- Symfony PHP session issues
- PHP Selector CloudLinux
- PrestaShop PHP Issues
- Prestashop 500 error
- Prestashop PHP Session
We hope this guide has been helpful in resolving the issue and that other system administrators can easily find this solution. Good luck!
Recent Comments