How to get my session to write to apache

2019-02-04 15:51发布

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...

7条回答
smile是对你的礼貌
2楼-- · 2019-02-04 15:54

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-02-04 15:54

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.

查看更多
Fickle 薄情
4楼-- · 2019-02-04 15:56

on ubuntu 12.04 /var/lib/php5 has 1733 permission I change in php.ini session.save_path to /tmp to correctly store sessions alternatively you can set parameter in your code by ini_set('session.save_path',path_where_apache_have_permission_777);

查看更多
小情绪 Triste *
5楼-- · 2019-02-04 16:02

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

查看更多
三岁会撩人
6楼-- · 2019-02-04 16:02

I tried all the solutions here but they didn't work, because php.ini was being overwritten by other configs.

To find the culprit I used this trick:

grep -lR 'php_value' /etc/

And there it was /etc/httpd/conf.d/php.conf messing it up. So I changed its value from php_value session.save_path "/var/lib/php/session" to php_value session.save_path "/tmp".

After restarting Apache (service httpd restart) it finally worked!

查看更多
一纸荒年 Trace。
7楼-- · 2019-02-04 16:12

Try changing the owner of the session directory to www-data. To do this run this command sudo chown -R www-data /var/lib/php/sessions. This works for me.

查看更多
登录 后发表回答