如何让我的会话写入 apache

发布于 2024-11-19 04:10:15 字数 728 浏览 4 评论 0原文

我最近更换了服务器,现在我的主页无法使用。它给出以下文本:

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

我认为这意味着会话文件夹不可写,因此我在 ssh 进入服务器后运行了以下命令:

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

这似乎没有解决问题。不知道现在该怎么办...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

や三分注定 2024-11-26 04:10:15

尝试更改 php 配置文件中的会话保存路径,/tmp 是一个不错的位置。

php.ini

session.save_path = /tmp

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

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

jJeQQOZ5 2024-11-26 04:10:15

刚刚在 CentOS 上遇到了同样的问题:

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

让 httpd 用户成为会话目录的所有者应该也可以。

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.

﹎☆浅夏丿初晴 2024-11-26 04:10:15

您可能递归地更改了父文件夹的权限,很可能是您自己的用户。
转到您的会话文件夹:
cd ~;cd /var/lib/php/

如果你找到了一个sessions文件夹,
只需在终端中写入这两个命令:
cd ~; 回家,然后
sudo chown -R www-data:www-data /var/lib/php/session

或者,如果您的会话文件夹是“sessions”而不是“session”:
cd ~; 回家,然后
sudo chown -R www-data:www-data /var/lib/php/sessions

这样您的服务器就能够将会话写入您的项目中。
我对这种方法非常确定。

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.

习惯成性 2024-11-26 04:10:15

tmp/var/lib/session 都必须 chmod 1777

并解决问题。

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

and problem solved.

风透绣罗衣 2024-11-26 04:10:15

尝试将会话目录的所有者更改为www-data。为此,请运行此命令sudo chown -R www-data /var/lib/php/sessions。这对我有用。

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.

煞人兵器 2024-11-26 04:10:15

我尝试了这里的所有解决方案,但它们不起作用,因为 php.ini 被其他配置覆盖。

为了找到罪魁祸首,我使用了这个技巧

grep -lR 'php_value' /etc/

并且那里是 /etc/httpd/conf.d/php.conf 搞砸了。
因此,我将其值从 php_value session.save_path "/var/lib/php/session" 更改为 php_value session.save_path "/tmp"

重新启动 Apache(service httpd restart)后,它终于工作了!

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!

哆啦不做梦 2024-11-26 04:10:15

在 ubuntu 12.04 /var/lib/php5 上有 1733 权限
我将 php.ini session.save_path 更改为 /tmp 以正确存储会话
或者,您可以通过 ini_set('session.save_path',path_where_apache_have_permission_777); 在代码中设置参数

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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文