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条回答
\"骚年 ilove
2楼-- · 2019-01-03 18:56

if you are using Apache web server, the quick fix is to go to your command line and type:

open /etc/apache2/

then from the window opened, open the file called httpd.conf and search for User or Group change these 2 lines to:

User  _www
Group _www

This is because you want your server to have permission to your systems directories, especially you want to change the User or you can leave your Group to either staff or admin.

查看更多
一夜七次
3楼-- · 2019-01-03 19:01

I initially had this issue due to nginx owning the /tmp location and php-fpm was running under 'apache' user and group due to the www.conf. I swapped out the user/group in that file and then it worked ok. You may want to check <?php echo exec('whoami'); ?> to verify.

查看更多
Emotional °昔
4楼-- · 2019-01-03 19:02

Change session path where you can write data or contact server administrator about /tmp problem

http://php.net/manual/en/function.session-save-path.php

查看更多
家丑人穷心不美
5楼-- · 2019-01-03 19:02

Using PHP 5.6 I had already used session_save_path() to point to a directory within the domain's structure. It worked fine until I upgraded to PHP 7.0, at which time I received the noted error. At PHP.net I found several comments that indicated assigning a direct path didn't always work, so I used their suggestion.

session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));

worked perfectly. Remember to change /../session to the relative location of your actual session directory.

查看更多
闹够了就滚
6楼-- · 2019-01-03 19:05

For me the problem seems to be a WHM bug! I have a bunch of add on domains and all work fine but with a subdomain it brings this error.

Strange thing but if I use the full URL with the main domain it works fine:

main-domain.com/my.subdomain.com

If I use the subdomain directly it brings "Permission denied (13)":

my.subdomain.com

The thing is all addon domains root is:

/home/xx/

But for my subdomain, don't know why, the root is: (I shouldn't have access to that dir)

/

So it´s really trying to reach: /tmp instead of /home/xx/tmp

Which also exists but don't have the right permissions

To clarify this are examples of the whole path:

/home/my-account/public_html

/home/my-account/tmp

/tmp

The workaround I used was:

session_save_path('/home/my-account/tmp');

session_start();

查看更多
成全新的幸福
7楼-- · 2019-01-03 19:08

I realize that this is an old post, however I just ran into this problem, and found an easy solution.

For me, the issue was happening with one of my websites deployed locally. I hadn't tried accessing the websites using other browsers, but it was happening every time I tried to access this site via Chrome. I decided to go into the Chrome developer tools, under the application tab -- and clicking "Clear Storage". Voila -- everything is working like magic again.

Hope this helps someone else!

查看更多
登录 后发表回答