Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  becomingwisest Jun 23 '13 at 18:10

4 Answers 4

up vote 4 down vote accepted

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.

share|improve this answer

Make Apache run as user/group apache/apache. CentOS will automatically have permissions set correctly for /var/lib/php/session.

share|improve this answer

If you have mod_fcgid then the apache user won't be usable as a /var/lib/php/session user/group owner.

share|improve this answer

Sessions should be stored with Memcached.

session.save_handler = memcached 
session.save_path = "localhost:11211"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.