Creating new tmp folder for PHP to use?

2020-05-07 16:14发布

问题:

I think I'm having problems using PHP sessions because I've got cPanel installed on the same server and I believe it has additional security in place that prevents write access to /tmp

I can set a new folder, but am unsure what permissions / owners should this folder have.

Also where should it ideally be located?

回答1:

/tmp should always be accessible. You can of course create a new "tmp" folder somewhere near you application. Just make sure it does not reside within the web root. Give it read/write permissions and chown it to the user of the webserver.

You then need to change the session_save_path to your new "tmp" folder.



回答2:

Look, bro.
You are pulling this log from the wrong end. Guessing will never help you.

There is a thing called error message.
And you desperately need to get in touch with it.
It will tell you everything of the reasons why your sessions doesn't work.

If it's really a /tmp problem, PHP got a special error message for tis case:

Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp))

If you get this message, you can be certain that it's the reason for your sessions doesn't work and you can start to repair it.

It has an error message for the wrong session handler as well. As well for the every other problem.

So, you have to get error message first. Then read it nd it makes you know, what certain problem you have. Easy-peasy.

As a quick workaround you can use this code to bring error messages on the screen

error_reporting(E_ALL);
ini_set('display_errors',1);

but only to debug this situation and then remove it. Error messages shouldn't be output on the screen a production server.
So, learn to read error logs. I am sure your server put all errors messages into error_log. Just find it and look for PHP errors.