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.

  • 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

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


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.

  • worked for me!!. I had the same issue where my PHP 7.4 session is working only for the same page, and when I was checking session on another page it was missing and the strange thing was 'echo session_id();' wasn't showing anything. when I checked PHP info the session.save_path had different values for master and local. changing in "/etc/httpd/conf.d/php.conf" fixed my issue. Note - I had tried each and everything on the internet but nothing worked except this. I am an EC2 user with ALB using PHP 7.4. – Neeraj Singh Dec 14 '20 at 11:58

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


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

$dir = sys_get_temp_dir();

... taken from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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