Fatal Error:session_start (): Failed to initialize storage module:files problem Solving method _php techniques

Source: Internet
Author: User
Tags session id readable sessions phpmyadmin

Before compiling the installed LNMP environment +phpmyamdin4.02 version, this problem suddenly occurs today:

Copy Code code as follows:
Fatal Error:session_start (): Failed to initialize Storage module:files (path:) In/data/www/phpmyadmin/libraries/sessio N.inc.php on line 83

The approximate meaning is to store the path incorrectly when session initialization is initiated! The first reaction is to view the php.ini configuration file:
Copy Code code as follows:
Session.save_path = "/tmp"

The default is preceded by a semicolon, which indicates that it is not enabled, and I was previously configured to have it enabled. Then why is there an error? , and then found some information on the Internet, feeling all the same:

1, check Error.log (apache2.2\logs) file to see if there are error reports. Not found.
2, check the value of the Session.save_handler in the php.ini is files, if not changed to files
3, check the php.ini file Session.save_path is commented, if any, then remove the front of the ";"
4, change the path behind the Save_path to an existing path, such as "D:\php\temp"
5, check the Temp folder's properties are readable and writable.
6, restart the Apache server. Ok

Do not know those friends reprint when they have tried not (here to spray, the most annoying kind of their own do not have a test, a brain around.) Not responsible at all!)
According to the above process, after the investigation found that there is no solution, but the small series of the server is Nginx not Apache.
Then I wrote a script test.php:

Copy Code code as follows:

$r = Session_Start ();
Var_dump ($R);

Printing results are:
Copy Code code as follows:

Warning:session_start (): SAFE MODE restriction in effect. The script whose UID is 501 isn't allowed to access/tmp owned by UID 0 in/data/www/test.php on line 3 Fatal error:sess Ion_start (): Failed to initialize Storage module:files (path:) in/data/www/test.php on line 3

PHP5 a bug in a safe mode, the default session Save_path is the system's temporary directory, which checks permissions. And this script does not run through the/TMP owner UID for 0来. The UID is 501 also the WWW user group's permissions
There are two ways to solve this problem:

1. Turn off security mode;
2. Chown the owner of the file/directory at the command line

Of course both methods require you to have the permissions of the server.
The following is the configuration file for sample php.ini:

Copy Code code as follows:

[Session]
; Handler used to store/retrieve data.
; Http://php.net/session.save-handler
Session.save_handler = files;  Argument passed to Save_handler. In the case of files, this is the path
; Where data files are stored. Note:windows users have to change this
; Variable in order to use the PHP ' s session functions.

; The path can be defined as:

; Session.save_path = "N;/path"

;  Where N is an integer. Instead of storing all the sessions files in
; /path, what this would do are use subdirectories n-levels deep, and
;  Store the session data in those directories. This is useful if you
; Or your OS have problems with lots of files in one directory, and is
; A more efficient layout for servers that handle lots of sessions.

; Note 1:php won't create this directory structure automatically.
; You can use the script in the Ext/session dir for that purpose.
; Note 2:see the garbage collection below if you choose to
; Use subdirectories to session storage

; The file storage module creates files using mode by default.
; You can change this by using

; Session.save_path = "N; Mode;/path "

; Where mode is the octal representation of the mode. This is the note
; Does not overwrite the process ' s umask.
; Http://php.net/session.save-path
Session.save_path = "/tmp"
; Whether to use cookies.
; Http://php.net/session.use-cookies
Session.use_cookies = 1
; Http://php.net/session.cookie-secure
; session.cookie_secure =
; This option forces the PHP to fetch and use a cookies for storing and maintaining
; The session ID. We encourage this operation as it's very helpful in combatting
; Session hijacking the specifying and managing your own session ID. It is
; Not the "end" all is all of the sessions hijacking defense, but it ' s a good start.
; Http://php.net/session.use-only-cookies
Session.use_only_cookies = 1
; Name of the session (used as cookie name).
; Http://php.net/session.name
Session.name = Phpsessid
; Initialize session on request startup.
; Http://php.net/session.auto-start
Session.auto_start = 0
; Lifetime in seconds of cookies or, if 0, until browser is restarted.
; Http://php.net/session.cookie-lifetime
Session.cookie_lifetime = 0
; The path for which the cookies is valid.
; Http://php.net/session.cookie-path
Session.cookie_path =/
; The domain for which the cookies is valid.
; Http://php.net/session.cookie-domain
Session.cookie_domain =
; Whether or not to add the HTTPONLY flag to the cookie which makes it inaccessible to browser scripting languages as Javascript.
; Http://php.net/session.cookie-httponly
Session.cookie_httponly =
;  Handler used to serialize data. PHP is the standard serializer of PHP.
; Http://php.net/session.serialize-handler
Session.serialize_handler = PHP
; Defines the probability that's ' garbage collection ' process is started
; On every session initialization. The probability is calculated by using
; Gc_probability/gc_divisor. Where Session.gc_probability is the numerator
; And Gc_divisor is the denominator in the equation. Setting this value to 1
; When the Session.gc_divisor value is give to you approximately a 1% chance
; The GC would run on any give request.
; Default value:1
; Development value:1
; Production value:1
; Http://php.net/session.gc-probability
session.gc_probability = 1
; Defines the probability that's ' garbage collection ' process is started on every
; Session initialization. The probability is calculated by using the following equation:
; Gc_probability/gc_divisor. Where Session.gc_probability is the numerator and
; Session.gc_divisor is the denominator in the equation. Setting this value to 1
; When the Session.gc_divisor value is give to you approximately a 1% chance
; The GC would run on any give request. Increasing this value to 1000 'll give you
; A 0.1% chance the GC would run on any give request. For the high volume production servers,
; This is a more efficient approach.
; Default value:100
; Development value:1000
; Production value:1000
; Http://php.net/session.gc-divisor
Session.gc_divisor = 1000
; After this number of seconds, stored data would be seen as ' garbage ' and
; Cleaned up by the garbage collection process.
; Http://php.net/session.gc-maxlifetime
Session.gc_maxlifetime = 1440
; Note:if you are using the subdirectory option for storing session files
; (above Session.save_path), then garbage collection does
;  happen automatically. You'll need to do your own garbage
; Collection through a shell script, cron entry, or some method.
; For example, the following script would is the equivalent of
; Setting Session.gc_maxlifetime to 1440 (1440 seconds = minutes):
; Find/path/to/sessions-cmin +24 | Xargs RM
; PHP 4.2 and less have a undocumented feature/bug that allows
; To initialize a sessions variable in the global scope, even when register_globals
;  is disabled. PHP 4.3 and later'll warn for you, if it feature is used.
; You can disable the feature and the warning separately. At this time,
; The warning is only displayed, if BUG_COMPAT_42 is enabled. This feature
; Introduces some serious security problems if not handled correctly. It ' s
; Recommended that ' You don't use ' feature on production servers. But
; Should enable this on development servers and enable the warning as. If You
; Do don't enable the feature on development servers, your won ' t be warned when it ' s
; Used and debugging errors caused by this can is difficult to track down.
; Default Value:on
; Development Value:on
; Production Value:off
; Http://php.net/session.bug-compat-42
Session.bug_compat_42 = Off
; This setting controls whether or isn't you are warned by PHP when initializing a
; Session value to the global space. Session.bug_compat_42 must be enabled before
; These warnings can is issued by PHP. The directive above for more information.
; Default Value:on
; Development Value:on
; Production Value:off
; Http://php.net/session.bug-compat-warn
Session.bug_compat_warn = Off
; Check HTTP Referer to invalidate externally stored URLs containing IDs.
; Http_referer has to contain this substring
; considered as valid.
; Http://php.net/session.referer-check
Session.referer_check =
; How many bytes to read from the file.
; Http://php.net/session.entropy-length
Session.entropy_length = 0
; Specified here to create the session ID.
; Http://php.net/session.entropy-file
; On systems so don ' t have/dev/urandom/dev/arandom can be used
; On Windows, setting the Entropy_length setting would activate the
; Windows Random Source (using the CryptoAPI)
; session.entropy_file =/dev/urandom
; Set to {nocache,private,public,} to determine HTTP caching aspects
; Or leave this empty to avoid sending anti-caching headers.
; Http://php.net/session.cache-limiter
Session.cache_limiter = NoCache
; Document expires after n minutes.
; Http://php.net/session.cache-expire
Session.cache_expire = 180
; Trans SID support is disabled by default.
; Use the trans Sid may risk your the users security.
; Use the option with caution.
; -User may send URL contains active session ID
; to other person via. Email/irc/etc.
; -URL that is contains active session ID is stored
; In publically accessible computer.
; -User may access your site with the same session ID
; Always using URL stored in browser ' s history or bookmarks.
; Http://php.net/session.use-trans-sid
Session.use_trans_sid = 0
; Select a hash function for use in generating session IDs.
; Possible Values
; 0 (MD5 128 bits)
; 1 (SHA-1 160 bits)
; This option may also is set to the name of any hash function supported by
; The hash extension. A List of available hashes is returned by the Hash_algos ()
; function.
; Http://php.net/session.hash-function
session.hash_function = 0
; Define how many bits are stored during each character when converting
; The binary hash data to something readable.
; Possible values:
; 4 (4 bits:0-9, a-f)
; 5 (5 bits:0-9, a-v)
; 6 (6 bits:0-9, A-Z, a-Z, "-", ",")
; Default Value:4
; Development Value:5
; Production Value:5
; Http://php.net/session.hash-bits-per-character
Session.hash_bits_per_character = 5
; The URL rewriter'll look for URLs in a defined set of HTML tags.
; Form/fieldset are special; If you include them here, the Rewriter would
; Add a hidden <input> field with the info which is otherwise appended
;  To URLs. If you want XHTML conformity, remove the form entry.
; Note This all valid entries require a "=", even if no value follows.
; Default Value: "a=href,area=href,frame=src,form=,fieldset="
; Development Value: "A=href,area=href,frame=src,input=src,form=fakeentry"
; Production Value: "A=href,area=href,frame=src,input=src,form=fakeentry"
; Http://php.net/url-rewriter.tags
Url_rewriter.tags = "A=href,area=href,frame=src,input=src,form=fakeentry"

Because this is in a VPS configured above, there are several items, so small set to open a project, found that the project's verification code function is OK.
So look at the code as follows:

Copy Code code as follows:

$sessSavePath = "/data/sessions/";
Session Save Path
if (is_writeable ($sessSavePath) && is_readable ($sessSavePath)) {Session_save_path ($sessSavePath);}
if (!empty ($cfg _domain_cookie)) session_set_cookie_params (0, '/', $cfg _domain_cookie);

The above code is the folder in which the session sessions are to be judged before session_start () is initialized.
So in the phpmyadmin inside the saved file/phpmyadmin/libraries/session.inc.php made the following modifications:

Copy Code code as follows:

if (! isset ($_cookie[$session _name])) {
On ' Start of Session ' We check for errors
F.E. Session dir cannot is accessed-session file not created
$orig _error_count = $GLOBALS [' Error_Handler ']->counterrors ();
Session_save_path ('. tmp ');
Session_save_path ("/data/www/session");
$r = Session_Start ();
if ($r!== True
|| $orig _error_count!= $GLOBALS [' Error_Handler ']->counterrors ()
) {
Setcookie ($session _name, "", 1);
/*
* Session initialization are done before selecting language, so we
* Can not use translations here.
*/
Pma_fatalerror (' cannot start session without errors, please check errors given in your PHP and/or webserver log file and C Onfigure your PHP installation properly. Also Ensure that cookie are enabled in your browser. ');
}
unset ($orig _error_count);
} else {
Session_save_path ("/data/www/session");
Session_Start ();
}

In Session_Start (); Session_save_path ("/data/www/session") was added to the front; Solved the problem.
Remember to pass @ini_set (' Session.save_path ', "/data/www/session");
This problem has been bothering me for a few hours and finally solved, so it will be helpful for me to record it in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.