SessionHandler::gc(): ps_files_cleanup_dir | Permission denied (13)
When running PrestaShop 1.7 on CentOS within a WHM/cPanel environment, you may encounter a session garbage collection failure. The error manifests as SessionHandler::gc(): ps_files_cleanup_dir: opendir(/var/cpanel/php/sessions/ea-php70) failed: Permission denied (13). This specific notice often appears in the logs or console output when the PHP application attempts to clean up expired sessions.
The root cause is straightforward but frequently misunderstood: the PHP process lacks read and write permissions on the designated session directory. In cPanel environments, session storage is often isolated to a user-specific directory managed by the control panel, such as /var/cpanel/php/sessions/ea-php70. While this isolation enhances security for shared hosting, it requires careful configuration of file ownership and group memberships. If the web server user (or the specific PHP-FPM user) cannot access this folder, opendir() will fail, triggering the permission denied error.
Diagnosing the Ownership Mismatch
To resolve this, you must verify who owns the session directory and compare it against the user executing the PHP code. The error message explicitly points to /var/cpanel/php/sessions/ea-php70. Run the following command in a terminal on your CentOS server:
ls -ld /var/cpanel/php/sessions/ea-php70
You will likely see output indicating ownership by root or a cPanel-specific system user (like psasys), with group permissions set to root or restricted groups. Meanwhile, your PrestaShop application runs under the context of your specific cPanel account username. Since standard cPanel accounts usually cannot write directly to /var/cpanel, attempting to change ownership globally is often a bad idea and may violate security policies enforced by the hosting provider.
Configuring SELinux Contexts
In many CentOS setups with WHM, the barrier isn't just POSIX file permissions (chmod/chown) but also SELinux contexts. Even if you manually set the directory to be writable, SELinux might still block the access because it doesn't recognize the transition from the PHP process context to that specific session path as valid.
Check the current context with:
ls -Z /var/cpanel/php/sessions/ea-php70
If the context is system_u or similar, but your PHP process expects a different label, you may need to adjust the context. However, modifying global system directories via chcon is generally discouraged without understanding the implications for other services on the node. A safer approach in cPanel is often to ensure the session handler configuration points to a directory where your user has explicit write permissions, rather than fighting for access to a restricted system folder.
Switching Session Handlers in PrestaShop
The most robust solution within the constraints of a shared hosting environment is to change the session storage path to one you control. In PrestaShop 1.7, you can configure this by editing the app/config/parameters.php file or via the admin panel settings if available for your specific version and theme configuration.
You need to define where sessions are stored so they reside within your home directory structure, which is naturally writable by your user. Add or update the following parameters:
'PS_SESSION_SAVE_PATH' => '/home/onywf3fr9a/public_html/app/cache',
Ensure that the path specified exists and is writable by your cPanel account. If using Symfony cache configuration as implied by the file path in the error (app/cache/dev/classes.php), verify that app/cache has 755 permissions and belongs to your user/group. This shifts the responsibility of session management from a restricted system directory to your own filesystem, bypassing the permission denied error entirely.
Verifying PHP Configuration
Sometimes the issue persists because PHP is configured to ignore these application-level settings in favor of a global directive or an environment variable set by cPanel. Check your php.ini (accessible via the command line or within PrestaShop's debug tools) for the session.save_path directive. If it points to /var/cpanel/php/sessions/ea-php70, you must either change that directive to a path under your home directory or ensure that the PHP-FPM pool associated with your site has elevated privileges that allow access to that specific subdirectory.
Changing the PHP configuration globally can affect other sites on the server, so modifying session.save_path in .user.ini (supported by cPanel) is often the preferred method for individual accounts:
session.save_path = "/home/onywf3fr9a/public_html/app/cache"
After making these changes, clear your PrestaShop cache and restart the PHP-FPM service if necessary. By aligning the session storage location with your user's permissions and managing SELinux contexts appropriately, you eliminate the Permission denied (13) error without compromising the security architecture of your CentOS server.