Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get my session to write to apache

I switched servers recently, and now my home page won't work. It gives the following text:

Warning: session_start() [function.session-start]: open(/var/lib/php/session/sess_eqbchncji8kj22f0iqa9g3v7u2, O_RDWR) failed: Permission denied (13) in /var/www/vhosts/alt.alternativedc.com/httpdocs/index.php on line 6

Warning: Unknown: open(/var/lib/php/session/sess_eqbchncji8kj22f0iqa9g3v7u2, O_RDWR) failed: Permission denied (13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

I assumed that this meant that the session folder was not writable, so I ran the following command after I ssh-ed into the server:

chmod o+rw /var/lib/php/session

That didn't seem to solve the problem. Not sure what to do now...

like image 394
Daniel Kats Avatar asked Jul 08 '11 17:07

Daniel Kats


People also ask

How do I enable a session?

PHP installations do not need any special configuration to enable sessions. They are enabled by default. You should make sure you have session_start(); as the first line in any page that you intend to use sessions; it should be the very first line, before any whitespace (an empty line, for example).

Where does Apache store sessions?

By default, session data is stored in the server's /tmp directory in files that are named sess_ followed by a unique alphanumeric string (the session identifier).

What is the default Apache session timeout?

Usually, the default session timeout in the Apache Tomcat application server is 30 minutes. Unless it is set as per the application requirement, it can result in website errors.

What is Mod_session?

mod_session. The Session directive enables a session for the directory or location container. Further directives control where the session will be stored and how privacy is maintained.


4 Answers

Try changing your session save path in your php config file, /tmp is a good location.

php.ini

session.save_path = /tmp

http://www.php.net/manual/en/session.configuration.php#ini.session.save-path

like image 178
Eddie Avatar answered Oct 12 '22 18:10

Eddie


Just had the same issue on CentOS:

chown -R apache:apache /var/lib/php/session

Making the httpd user the ower of the session directory should work, as well.

like image 33
Martin Zeitler Avatar answered Oct 12 '22 19:10

Martin Zeitler


You probably changed a parent folder's permissions recursively, most likely to your own user.
Go to your sessions folder:
cd ~;cd /var/lib/php/

If you find a sessions folder, just write these two commands in your terminal:
cd ~; to go home, then
sudo chown -R www-data:www-data /var/lib/php/session

Or, if your sessions folder is "sessions" instead of "session":
cd ~; to go home, then
sudo chown -R www-data:www-data /var/lib/php/sessions

This way your server will be able to write sessions into your project.
I'm Quite sure about this approach.

like image 42
daniel Warui Avatar answered Oct 12 '22 17:10

daniel Warui


both of tmp and /var/lib/session must be chmod 1777

and problem solved.

like image 22
Muharrem Avatar answered Oct 12 '22 17:10

Muharrem