session_start(): open(/tmp/sess_aabb3a6218468f7eb03c8a4b732b2be2, O_RDWR) failed: Permission denied (13)

I know this question has been answered before at least once here:

but that didn't seem to help my problem.  I am hosting my own php/apache server and most solutions I've found for this problem is "Asked sys admin to fix it"  Well I'm the sysadmin and I can't fix it :)

this is the error:
Warning: session_start(): open(/tmp/sess_aabb3a6218468f7eb03c8a4b732b2be2, O_RDWR) failed: Permission denied (13) in /home/esports/public_html/authenticate.php on line 2

It should be noted that this is an intermittant problem.  It'll work about 90% of the time then you get this error and I get stumped.

this is what I've tried so far
-I've 777'd the temporary directory /tmp there are numerous sess_* files in there already
-I've tried using ini_set to change save path to a local dir
-I've viewed the php settings page and the session save path is /tmp

Any new ideas on this one?  Thanks
Who is Participating?
Ah, that brings us into a new kittle of fish.

I didn't know that it was only new PHP Session files that were wrong. This suggests that the system is creating them with 'bad' permisisons. I'm not sure what to do about that, but is there a possibility it could be a umask problem?
DaK00L1Author Commented:
cthe cgi-central says to change permissions, which are already set to 777 and  I'm not sure what the comparison operators have to do with this... can you elaborate?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

From your error this clearly isn't a Problem with PHP, so much as it is a problem with your enviornment. The syscall to open the file has failed.

Are you using Linux? Are you sure there is sufficient space in /tmp

What filesystem are you using?

I suspect that your problem is with your kernel(as it is a system call that fails).
DaK00L1Author Commented:
File system: EXT3
O/S: RedHat Linux 9
Linux: 2.4.20-8
free space - 20 gig +

I have googled this problem and it seems to be a common problem with php but I have yet to find a solution that works for me.  The fact that it is in intermitant problem leads me to believe I have some kind of timeout problem or permissions problem.
A very common problem, you're right.
Change you session.save_path in your php.ini or via ini_set.
Make sure you're using right php.ini

Hmm.. It also can be if you're passing sessions between different PHP's handlers.
To say one is CGI and one is mod_php. Check permissions and owners on session files.
It can be, that owner is mod_php and permissions are set for session file so that CGI version can't read them, because it is running under different user.

If nothing helps, provide your PHP version.
Tray to delete that file. And then give to tmp filder chmod 755
I would recommend crossposting this on the Linux area of the site.

Can you show us the permissions of a created session file?

I would also suggest checking your syslogs for any hints. of what is wrong.
DaK00L1Author Commented:
Session save path is /tmp, and I have sessions already in the /tmp dir.

aolXFT - I'm pretty this is a php settings problem because there are posts in forums about the same problem on a windows box.

Aliev - if I delete the sess_* files then everything works again.

OK! I just did an ls on my tmp and found that some of the sessions have 000 as permissions.   while some have the proper 600.  Is there anyway to explicitly set the permission of the session file?  Does anyone know why some sessions are 000 and some are 600?

ls -al /tmp
----------    1 apache   apache        109 Apr 30 10:26 sess_9e8c09293210dedff29
----------    1 apache   apache          0 Apr 30 08:24 sess_ac59bd6390a2d80cab4
-rw-------    1 apache   apache        109 Apr 30 08:30 sess_ec42d20f4f2083c6766

I normally don't post my pages but I'm really stumped so this is the php info page...
Does anyone see anything in the session section that could be causing it?

One more thing is  $_SESSION['sSessionName'] the same as  $_SESSION["sSessionName"]?

thanks for the help
Perhaps some cron job, which sets 000 attributes, so nobody can read temp files. Or some script explicitly chmod's them. These are only ideas that came into my mind. Try to make different directory for sessions and set audit for it somehow.
I'd agree with techtonik on this one.

Something seems to be changeing the permissions on your session files.

The handiest way would be to try putting your sessions somewhere else (ie outside of /tmp), by setting the php.ini accordingly.

If you want a quick fix, you could just dynamicly chmod them back to whatever they should be

chmod ("/tmp/sess_" . $_COOKIE['PHPSESSID'], 0600)

or something like that before calling session_start();

>> $_SESSION['sSessionName'] the same as  $_SESSION["sSessionName"]
They are the same. The only difference I see is that Strings are delimited by single and dbl quotes. This would only make a difference if you wanted to use escapable characters(like \"'$, etc), or variable substitution.

Oh yeah:

do a crontab -u apache -l, and a crontab -u root -l to see if there are any cron jobs making life hard for you.
DaK00L1Author Commented:
ya no cron jobs... and I've watched the sessions appear in /tmp...

another thing i've noticed...
if I get the session problem... then I go to my IE and clear my cookies and try again It will work again.

I'm still convinced it is a PHP setting problem... it doesn't seem to be handling the cookies properly... I'll try the chmod as a quick fix for now... though
Did you try a different session save path? It seems that your distro is periodicly setting the permissions of your temp files to 000.

That wouldn't be a PHP setting.

I recommend posting a Link to this to the Linux area of the site.
DaK00L1Author Commented:
I've done tests with Perl, and local files and I could not get the permissions to change for me.  In addition I've tried to change the sessions path and I had the same problem.

and php builder seems to have people posting messages with similar problems.

Don't get me wrong I appreciate the suggestions but the fact that only php session files get set to 000 and they only get set when I "create new ones" (on the web page) leads me to believe strongly that it is not a problem with linux alone but is actually a php problem (possibly in combination with linux).

Any other possible suggestions?
DaK00L1Author Commented:
sorry I didn't get back sooner I was away for a couple days....

I've decided to check the actual bugs in php and I found a lot... something... that was quite similar to the problem I'm having

I didn't know I had to specifically set the damn umask :)  I'm not sure if this is the problem but I'll try it tonight and see if it works.

for future reference for other people having this problem...

or do what we'll be doing in about a month is store the sessions in the database not the filesystem itself.  This will prevent this problem I'm having, and it will make it O/S independent.  
DaK00L1Author Commented:
It's going to be about a week before I can confirm if that was the problem... but points are coming
DaK00L1Author Commented:
I'm sorry I can't confirm the umask thing... maybe someone else can...

instead I switched to database session handler.

Thanks for the help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.