安装了一个MediaWiki后,尝试了一下它的使用.注册用户正常,登录,结果发现报错如下:

"Wiki uses cookies to log in users. You have cookies disabled. Please enable them and try again."

这个错误似乎是说本地的cookie没有加上,但是须知,登录怎么可能要wiki呢,保存session不就够了?

google之,得到似乎有用信息如下:

1. Open to LocalSettings.php 2. Go to the bottom of the page, and enter in the following code: session_save_path("tmp"); 3. Next create a directory called tmp in the folder where you have MediaWiki installed. 4. Done!

我尝试了下,效果是居然不再报错了,看来这个就是原因了: php session 存储地方有问题。 但是,这个fix看起来超级不靠谱,居然把session存在当前目录,这不是找虐么。但是,至少方向明确了,估计是session的存储遇到什么故障了。

因为是httpd的web server,直接检查error log (居然这时候才想到看http的log,真够废的), 发现每次登录的时候它会报错有内容如下:

.... PHP 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, referer: ...

很明显的,这就是原因了,如之前所推测的,默认的存储session的地方(/var/lib/php/session)是权限有问题.

$ ls -al /var/lib/php
total 12
drwxr-xr-x  3 root root   4096 Sep 30 05:47 .
drwxr-xr-x 27 root root   4096 Oct 26 04:02 ..
drwxrwx---  2 root apache 4096 Sep 30 05:47 session

发现这session用户是apache的,而httpd的server配置中,我用的是另外一个用户。

# chown -R my_usr:my_usr /var/lib/php/session

然后就发现不再有这个错误提示了. 搞定收工

Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

2 Comments

boxer · December 18, 2015 at 17:30

Google Chrome 46.0.2490.86 Google Chrome 46.0.2490.86 Mac OS X  10.11.2 Mac OS X 10.11.2

这个帮助我解决了同样的问题,感谢!

    yu · December 19, 2015 at 02:23

    Google Chrome 47.0.2526.106 Google Chrome 47.0.2526.106 Mac OS X  10.11.2 Mac OS X 10.11.2

    @boxer 荣幸

Leave a Reply

Your email address will not be published. Required fields are marked *