Just installed PHP 5.4 on Centos 6.4 with Apache 2.2 VPS, and received an error that permission is denied to open session. php.ini shows session.save_path = "/var/lib/php/session"
. Do I make /var/lib/php/session
permission 0777? Or maybe make Apache run as a given user, and then give that user rights to /var/lib/php/session
. I recall in the past changing session path to /tmp
, and wonder if that is a better strategy. Where should I set PHP to write sessions to?
-
Had you changed the user apache runs as before testing, as you answer, centos should have had it run as apache, and had proper permissions.– becomingwisestJun 23, 2013 at 18:10
4 Answers
In terms of flexibility and - even more importantly - security, you should configure the Apache to run the scripts (read: php-processes) as another, unprivileged user per vhost using suEXEC + FCGId or something similar. Then you can assign a own php.ini for every user and set the session path to a user-only writable path (for example in the users /home directory). There're plenty of tutorials for this common setup, just search for "centos apache suexec php"
This might be the most complex solution to your problem, but it also takes security and some flexibility for the future into account.
Make Apache run as user/group apache/apache. CentOS will automatically have permissions set correctly for /var/lib/php/session
.
If you have mod_fcgid
then the apache user won't be usable as a /var/lib/php/session
user/group owner.
Sessions should be stored with Memcached.
session.save_handler = memcached
session.save_path = "localhost:11211"