PHP: Why might session_start fail, claiming "no such file or directory"?
Here's a little problem that bit me after an OS upgrade to a webserver. Whenever session_start was called, PHP would throw a warning message and not actually start the session:
Warning: session_start() [function.session-start]: open(/tmp/php_sessions/sess_5q2snk41jrvq9tt1q8eddprlulm7jaflk0hgtfivm8uhqr2i85u0, O_RDWR) failed: No such file or directory (2) in /srv/www/htdocs/index.php on line 2
Warning: Unknown: open(/tmp/sess_5q2snk41jrvq9tt1q8eddprlulm7jaflk0hgtfivm8uhqr2i85u0, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp/php_sessions) in Unknown on line 0
While this normally means that the directory specified as PHP's session.save_path either does not exist or does not have the appropriate permissions set, I could see quite clearly that that directory in fact did exist and was owned by the appropriate user, with the correct permissions. It took me hours to find out what was wrong. It turns out that the OS upgrade made systemd redirect Apache's (and thus PHP's) references to /tmp to another location, something like /tmp/systemd-private-RiMSxa.
Solution #1: Create the directory
There's multiple solutions to this. One would be to simply create the appropriate directory as needed, as simple as:
<?php
mkdir (ini_get ('session.save_path', 0777, true));
?>
Solution #2: Move your sessions elsewhere
A second solution is to simply change your php.ini file, making the session.save_path directive point somewhere outside the /tmp directory, such as /var/lib/php.
Solution #3: Disable private temporary directory
And another would be to disable the redirection (which is what I did, as this is a development server where I sometimes find it useful to inspect the session files manually. For this, find the appropriate configuration file for systemd. For me, this was /usr/lib/systemd/system/apache2.service (the file could also be called httpd.service). In that, find the line:
PrivateTmp=true
and change true to false. Save the file, call systemctl daemon-reload and restart Apache.
Comments
this is not converting images any more please test it
Thanks, this article helped me figure out what was going on with my particular sessions case. This was on my localhost, and the baffling thing was that multiple other sites on my localhost were not affected. The one thing that was different with this virtual host was I had it's directory mapped to a network drive instead of a local directory - since this is a domain-authenticated network drive, Apache's user could not access it for reading. It was generating the session variable under the normal tmp/ directory, but I guess reading was getting redirected then. I couldn't find the PrivateTmp line in any config files (XAMPP for Windows), so I ended up moving the site to my localhost.
Once again, thanks for thanks for the information. This was far more helpful then every other resource I found of just "check your session.save_path"...
I want to register and I think perhaps I need troobleshooting!!!
Hwyd
fuuuuck you !!!!!!why i cant login using my facebook account???this is my account not your account!!!so i can do anything!!!!!!!!!!!!!!
why do i have to do a comment
No puedo a ser una cuenta nueva
Please open session
I want to register and I think perhaps I need troubleshooting!!!!
yes l do
GRACIAS AMIGO ME SIRVIO A PELO LA SEGUNDA OPCION!
I cannot access the page its giving me a session error
It is very nice
REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Hi
The session identified is missing
The session identifier is missing
The session identifier is missing
I can't login
The session identifier is missing
Regt no - BR/SD/A-20/500258
Very bad condition of software or website or may be both
I am N C C Cadet
Yes, USLR will send me a notification.
I am a NCC cadet.
Software is not working.
Hence, if USLR send me a notification of it.
Then I will join it.
I am a NCC cadet.
Software is not working.
Hence, if USLR send me a notification of it.
Then I will join it.
##Thank you##
I will be greatful if I get opportunity/chance to get your support,I will work hard with any given condition.
my soft ware is not working
help me events to start job
Thank you sir/madam
NCC cadets not working software
The session identifier is missing
FAMILY
Smile
Bharat internet utsav
Love this
Login problem
This session identifier is missing
Login problem
Post a comment