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.

I have an strange issue related with PHP an the session save path. I have configured in my php.ini the session.save_path = "/tmp", and I know that is correctly configured since in the server I could type the following command and the command result seems to be fine.

$ php -i | grep session.save_path
session.save_path => /tmp => /tmp

However, when I am trying to start a session from php code, I am getting the following error:

Warning: session_start(): open(/var/lib/php/session/sess_7ktfe84jqca3ga6ftk6fsrurv6, O_RDWR) failed: Permission denied (13)

So the path here is totally different from /tmp configured in php.ini.

Is there any reason for this behavior? I have checked that in my code there is no any call to session_save_path to change the default save path.

The server with this problem is an AWS EC2 instance.

share|improve this question
    
When you say "from php code", do you mean like php -r or through a web server? –  plasmid87 Dec 2 '13 at 12:11
1  
In many servers, CLI PHP uses a different php.ini... and you'll usually need to restart the web server after making changes. –  ceejayoz Dec 2 '13 at 13:13
    
From a php file located in a web server and loaded from web browser. I have also set session_save_path manually in php code just before start_session but with no luck –  alvarolb Dec 2 '13 at 13:17

4 Answers 4

You can also add this to your elastic beanstalk project.config file:

"/etc/httpd/conf.d/php.conf" : content: | php_value session.save_path "/tmp"

that will just set the session save path for you

share|improve this answer
up vote 0 down vote accepted

I found the issue, and seems a configuration problem. I have opened a phpinfo in the server and see the following:

Directive            Local Value            Master value
session.save_path   /var/lib/php/session    /tmp

The local value pointing /var/lib/php/session seems to be the problem as this directory is not writable by server user. I did not know anything about local and master value, and after some digging in google I read the following:

"Master Value" (from php.ini) could be overridden with "Local Value" in httpd.conf, .htaccess or other Apache configuration with php_value directive.

So after looking around server files i found /etc/httpd/conf.d/php.conf which contains:

#
Apache specific PHP configuration options
those can be override in each configured vhost
#
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"

So there is the problem, this php.conf is overwritting default php.ini configuration. I can comment this last line wih "#" and restart the server and all is working as expected again.

Hope this help.

share|improve this answer

You can also connect through ssh (if you have configured the key/pair initially) and change the permission of the folder so it's owned by webpp user

share|improve this answer

Quick solution for this one is to put the following before your session_start();

<?php
$dir = sys_get_temp_dir();
session_save_path($dir);
?>

... taken from here.

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.