Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location for session files in Apache/PHP

What is the default location of session files on an installation of Apache/PHP on Ubuntu 10.10?

like image 741
cambraca Avatar asked Feb 07 '11 23:02

cambraca


People also ask

Where are PHP session files stored?

PHP Session Start By default, session data is stored in the server's /tmp directory in files that are named sess_ followed by a unique alphanumeric string (the session identifier). By itself, the session_start() function doesn't add much functionality to a web page.

What is PHP session path?

PHP - session_save_path() Function Sessions or session handling is a way to make the data available across various pages of a web application. The session_save_path() is used to set or retrieve the path where the current session data is saved.

Where are PHP sessions stored on Windows?

PHP Default Session Storage (File System): In PHP, by default session data is stored in files on the server. Each file is named after a cookie that is stored on the client computer. This session cookie (PHPSESSID) presumably survives on the client side until all windows of the browser are closed.

Where does session save?

The session data that you read and write using $_SESSION is stored on server side, usually in text files in a temporary directory. They can not be accessed from outside.


2 Answers

The default session.save_path is set to "" which will evaluate to your system's temp directory. See this comment at https://bugs.php.net/bug.php?id=26757 stating:

The new default for save_path in upcoming releaess (sic) will be the empty string, which causes the temporary directory to be probed.

You can use sys_get_temp_dir to return the directory path used for temporary files

To find the current session save path, you can use

  • session_save_path() — Get and/or set the current session save path

Refer to this answer to find out what the temp path is when this function returns an empty string.

like image 144
Gordon Avatar answered Sep 25 '22 12:09

Gordon


First check the value of session.save_path using ini_get('session.save_path') or phpinfo(). If that is non-empty, then it will show where the session files are saved. In many scenarios it is empty by default, in which case read on:

On Ubuntu or Debian machines, if session.save_path is not set, then session files are saved in /var/lib/php5.

On RHEL and CentOS systems, if session.save_path is not set, session files will be saved in /var/lib/php/session

I think that if you compile PHP from source, then when session.save_path is not set, session files will be saved in /tmp (I have not tested this myself though).

like image 39
Rich Avatar answered Sep 22 '22 12:09

Rich