- October 2020
- June 2020
- May 2020
- October 2019
- June 2019
- September 2018
- May 2018
- December 2017
- April 2017
- June 2016
- February 2016
- November 2015
- January 2015
- August 2014
- July 2014
- May 2014
- March 2014
- February 2014
- January 2014
- November 2013
- August 2013
- June 2013
- May 2013
- April 2013
- March 2013
- February 2013
- December 2012
- November 2012
- September 2012
- June 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- September 2011
- July 2011
- June 2011
- May 2011
- March 2011
- January 2011
- October 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- September 2009
- July 2009
- June 2009
- May 2009
- March 2009
- September 2008
- April 2008
- December 2007
- June 2007
- June 2005
- September 2004
- May 2002
- October 2001
- August 2001
2014-05-09: 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
Post a comment