It’s clearly a problem of your server configuration on creating, storing and reading your session file that caused the message like this: Warning: session_start(): open(/var/lib/php/session) failed: Permission denied . To fix the issue, you have to double-check your session storage directory which is the value of session.save_path setting in your php.ini file.
It’s not a common problem on almost web server include shared hosting environment but in case the location path is wrong or point to un-writable folder, the issue will occur.
This tutorial will show you 3 ways to fix the issue if your server doesn’t config the session.save_path correctly.
1. Use .htaccess to change the session save_path
Open the .htaccess you already have or create a file named .htaccess in the root folder of your site and simply add a line below:
php_value session.save_path ‘/path/to/a/writeable/folder’
2. Use ini_set() PHP function to overwrite the current configuration
Put the PHP script line below above the calling session_start(), it sets the value of the session.save_path configuration option and will keep this new value during the script’s execution. It’ll be restored at the script’s ending.
<?php ini_set('session.save_path', '/home/4rapiddev.com/public_html/session_path'); session_start(); $_SESSION["status"] = "success"; echo "session_id: " . session_id() . "<br>"; echo "status: " . $_SESSION["status"]; echo $_SESSION["bbb"]; ?>
3. Edit your php.ini file
If you have full control the server, you can change the value of the session.save_path setting in the php.ini file to a path of writable directory. Just open the php.ini file in a text editor and search for keyword: session.save_path.
Note: it’s required that the new folder location must be writable and all session files which will be created in that folder must be writable too.