How can I fix the Permission error when I call ses

2019-01-03 18:47发布

when I uploaded the script to the server I got this error

Warning: Unknown: open(/tmp/sess_58f54ee6a828f04116c2ed97664497b2, O_RDWR) failed: Permission denied (13) 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) in Unknown on line 0

the error appeared when I call session_start(); although I set the permission of /tmp folder to 777 .

15条回答
放我归山
2楼-- · 2019-01-03 19:09

Additionally, you may want to use ini_set('session.save_path', '/dir/here'); assuming you have access to this function. The other ways suggested are valid.

查看更多
不美不萌又怎样
3楼-- · 2019-01-03 19:13

you will need to change your session.save_path php.ini directive

You can do that using session_save_path

查看更多
干净又极端
4楼-- · 2019-01-03 19:14

I've just had exactly the same problem with one of my PHP scripts and I was like what did I break 'cos it worked perfectly the day before and I'm running it from my own local Puppy Linux machine so it's not even a host or anything.

The only thing I'd been doing before that was trying to get Java to work in the web browser, so some how I'd managed to get Java to work but broke PHP - oops!

Anyway I did remember that whilst trying to get Java to work I had deleted the contents of the /tmp folder to wipe anything out that may be causing a problem (it actually turned out with Java I was using the old plugin oij with the new Firefox)

To solve this problem I opened up Rox File Manager, went to the / folder and right clicked on the tmp folder -> Mount Point 'tmp' and clicked properties.

I noticed the permissions were set as Owner - Read, Write, Exec, but Group and World were only set at Read and Exec and not Write. I put a tick in Write for both Group and World and now PHP works fine again.

I don't know at what point the permissions for tmp must have changed but for PHP to use them it must be set to have Write permissions.

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-03 19:16

Check that you're not running into diskspace issues. If all the permissions are correct (and 777 ought to do it for you), then you might still get this error (for some versions of PHP and Apache) if there isn't enough space to write to the disk.

查看更多
爷的心禁止访问
6楼-- · 2019-01-03 19:18

If you have SSH access, here is how to correct the permission and ownership

sudo chown -R NAME_OF_USER /tmp

Replace NAME_OF_USER by the user under which runs php. You can find it by simply putting these lines in a php file:

$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
exit;
查看更多
家丑人穷心不美
7楼-- · 2019-01-03 19:19

I have the same problem of permission, but on /var/lib/php/session/.

To fix it, I delete the file and restart php-fpm.

rm -rf /var/lib/php/session/sess_p930fh0ejjkeeiaes3l4395q96
sudo service php5.6-fpm restart

Now all works well.

查看更多
登录 后发表回答