Fatal error: session_start(): Failed to initialize storage m_PHP教程
本文章来给各位同学介绍Fatal error: session_start(): Failed to initialize storage module: files问题的解决办法。
原创解决: Fatal error: session_start(): Failed to initialize storage module: files问题
之前编译安装的LNMP环境+phpmyamdin4.02的版本,今天突然出现这个问题:
Fatal error: session_start(): Failed to initialize storage module: files (path: ) in /data/www/phpmyadmin/libraries/session.inc.php on line 83
大致意思是session会话初始化的时候储存路径有误!第一反应就是查看php.ini的配置文件中的:
代码如下 | 复制代码 |
|
默认前面是加的分号,表示不启用,我之前配置的时候已经启用了。那为什么还会报错呢?,于是网上找了一些资料,感觉都千篇一律:
1、检查error.log(Apache2.2logs)文件,查看是否有错误报告。未发现。
2、检查php.ini中的session.save_handler的值是否为files,如果不是改为files
3、检查php.ini文件中session.save_path是否被注释了,如果有,则去掉前面的”;”。
4、将save_path后面的路径改成已有的路径,比如”D:phptemp”
5、检查temp文件夹的属性是否可读可写。
6、重启APACHE服务器。OK
不知道那些哥们转载的时候自己试过了没有(在这里喷一下,最讨厌那种自己都没有亲测,就一股脑的转来转去。一点都不负责!)
根据上面的流程,排查了之后发现压根就没有解决,不过璞玉的服务器是nginx非apache。
然后自己写了一个脚本test.php:
代码如下 | 复制代码 |
$r = session_start(); var_dump($r); |
打印结果为:
Warning: session_start(): SAFE MODE Restriction in effect. The script whose uid is 501 is not allowed to access /tmp owned by uid 0 in /data/www/test.php on line 3 Fatal error: session_start(): Failed to initialize storage module: files (path: ) in /data/www/test.php on line 3
意思是 php5一个安全模式的bug,默认session的save_path是系统的临时目录,这样会要校验权限。而这个脚本不能通过/tmp拥有者uid为0来执行uid是501也是www用户组的权限
解决这个有两种解决方法:
1。关闭安全模式;
2。在命令行下chown改文件/目录的拥有者
当然两种方法都要求你有服务器的权限。
下面是璞玉php.ini的配置文件:
代码如下 | 复制代码 |
[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 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 session files in ; /path, what this will do is 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 will not create this directory structure automatically. ; You can use the script in the ext/session dir for that purpose. ; NOTE 2: See the section on garbage collection below if you choose to ; use subdirectories for session storage ; ; The file storage module creates files using mode 600 by default. ; You can change that by using ; ; session.save_path = "N;MODE;/path" ; ; where MODE is the octal representation of the mode. Note that this ; 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 PHP to fetch and use a cookie for storing and maintaining ; the session id. We encourage this operation as it's very helpful in combatting ; session hijacking when not specifying and managing your own session id. It is ; not the end all be all of session 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 cookie or, if 0, until browser is restarted. ; http://php.net/session.cookie-lifetime session.cookie_lifetime = 0 ; The path for which the cookie is valid. ; http://php.net/session.cookie-path session.cookie_path = / ; The domain for which the cookie 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 such 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 the '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 100 will give you approximately a 1% chance ; the gc will 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 the '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 100 will give you approximately a 1% chance ; the gc will run on any give request. Increasing this value to 1000 will give you ; a 0.1% chance the gc will run on any give request. For 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 will 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 ; (see session.save_path above), then garbage collection does *not* ; happen automatically. You will need to do your own garbage ; collection through a shell script, cron entry, or some other method. ; For example, the following script would is the equivalent of ; setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes): ; find /path/to/sessions -cmin +24 | xargs rm ; PHP 4.2 and less have an undocumented feature/bug that allows you to ; to initialize a session variable in the global scope, even when register_globals ; is disabled. PHP 4.3 and later will warn you, if this 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 do not use this feature on production servers. But you ; should enable this on development servers and enable the warning as well. If you ; do not enable the feature on development servers, you won't be warned when it's ; used and debugging errors caused by this can be 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 not you are warned by PHP when initializing a ; session value into the global space. session.bug_compat_42 must be enabled before ; these warnings can be issued by PHP. See 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 for the session to be ; 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 that don't have /dev/urandom /dev/arandom can be used ; On windows, setting the entropy_length setting will 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 of trans sid may risk your users security. ; Use this option with caution. ; - User may send URL contains active session ID ; to other person via. email/irc/etc. ; - URL that contains active session ID may be 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 be 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 in 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 will look for URLs in a defined set of HTML tags. ; form/fieldset are special; if you include them here, the rewriter will ; add a hidden field with the info which is otherwise appended ; to URLs. If you want XHTML conformity, remove the form entry. ; Note that 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" |
因为这个是在一台VPS上面配置的,上面有多个项目,于是璞玉打开一个项目,发现此项
目的验证码功能是OK的。
于是查看代码如下:
代码如下 | 复制代码 |
|
上面这个代码是在session_start() 初始化之前来判断是否存在session会话的文件夹。
于是就在phpmyadmin里面的保存的那个文件/phpmyadmin/libraries/session.inc.php做了下修改:
代码如下 | 复制代码 |
|
在 session_start(); 前面添加了 session_save_path(“/data/www/session”); 就解决了这个问题。
切记通过@ini_set(‘session.save_path’, ”/data/www/session”);无效!
这个问题困扰了我几个小时,终于解决了,所以就记录下来,对日后应该会有帮助。
如果对你有帮助,请留言。如果有什么意见欢迎交流!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Win10에서 게임을 열 때 치명적인 오류가 발생하면 어떻게 해야 하나요? 소프트웨어나 게임을 실행할 때 치명적인 오류 메시지가 나타나면 어떻게 해야 합니까? 이 사이트에서는 Win10에서 게임을 열 때 발생하는 치명적인 오류를 처리하는 방법을 사용자에게 주의 깊게 소개합니다. Win10에서 게임을 열 때 치명적인 오류가 발생하면 어떻게 해야 하나요? 방법 1: 파일 손상이나 일부 크래킹 패치 사용 등 게임 클라이언트에 문제가 있어 치명적인 오류 오류가 발생하면 게임을 다시 다운로드할 수 있습니다. 방법 2: 컴퓨터 메모리가 너무 작으면 치명적인 오류 오류가 발생할 수도 있습니다. 실제 메모리가 충분하면 시스템의 가상 메모리를 설정할 수 있습니다.

PHP는 오랫동안 사용되어 온 인기 있는 웹 개발 언어입니다. PHP에 통합된 PDO(PHP 데이터 개체) 클래스는 웹 애플리케이션 개발 중에 데이터베이스와 상호 작용하는 일반적인 방법입니다. 그러나 일부 PHP 개발자가 자주 직면하는 문제는 PDO 클래스를 사용하여 데이터베이스와 상호 작용할 때 다음과 같은 오류가 발생한다는 것입니다. PHPFatalerror:CalltoundefinemethodPDO::prep

C++ 코드의 "error:incompletetypeisnotallowed" 문제를 해결하십시오. C++ 프로그래밍 프로세스 중에 흔히 발생하는 오류 중 하나는 "error:incompletetypeisnotallowed"입니다. 이 오류는 일반적으로 불완전한 유형에서 작업할 때 발생합니다. 이 문서에서는 이 오류의 원인을 설명하고 몇 가지 해결 방법을 제공합니다. 첫째로, 나는

Vue 애플리케이션에서 axios를 사용하는 것은 매우 일반적입니다. axios는 브라우저와 Node.js에서 사용할 수 있는 Promise 기반 HTTP 클라이언트입니다. 개발 과정에서 "Uncaught(inpromise)Error: Requestfailedwithstatuscode500"이라는 오류 메시지가 나타나는 경우가 있는데, 개발자 입장에서는 이 오류 메시지를 이해하고 해결하기 어려울 수 있습니다. 이 기사에서는 이에 대해 알아볼 것입니다.

Final Fantasy 7을 플레이할 때 많은 플레이어가 치명적인 오류 문제에 직면하고 이를 해결하는 방법을 모릅니다. 일반적으로 메모리를 읽을 수 없는 문제에 관한 것이므로 문제를 해결하려면 게임을 다시 설치하는 것이 좋습니다. 파이널판타지7 치명적인 오류 해결 방법 1. 게임 재설치 파일 손상, 불완전성, 일부 크랙 패치 사용 등의 게임 클라이언트 문제로 인해 게임 재설치를 권장합니다. 2. 모든 파일의 읽기 전용 속성을 제거합니다. 일부 파일 속성은 읽기 전용이 아닌 읽기 전용으로 설정되어 있습니다. 예를 들어 게임을 실행할 수 없는 경우 게임을 마우스 오른쪽 버튼으로 클릭하여 폴더를 설치하고 읽기 전용 속성을 취소하세요. 3. 물리적 메모리가 충분하지 않은 경우 가상 메모리를 설정하는 경우 메모리가 너무 작을 수 있습니다.

C++ 코드의 "error:expectedinitializerbefore'datatype'" 문제를 해결하세요. C++ 프로그래밍에서 코드를 작성할 때 가끔 컴파일 오류가 발생하는 경우가 있습니다. 일반적인 오류 중 하나는 "error:expectedinitializerbefore'datatype'"입니다. 이 오류는 일반적으로 변수 선언이나 함수 정의에서 발생하며 프로그램이 올바르게 컴파일되지 않거나

세션 실패는 일반적으로 세션 수명 만료 또는 서버 종료로 인해 발생합니다. 해결 방법은 다음과 같습니다. 1. 세션 수명을 연장합니다. 3. 쿠키를 사용합니다. 4. 세션 관리 미들웨어를 사용합니다.

PHPSession의 도메인 간 문제 해결 프런트엔드와 백엔드 분리 개발에서 도메인 간 요청이 표준이 되었습니다. 도메인 간 문제를 처리할 때 일반적으로 세션 사용 및 관리가 포함됩니다. 그러나 브라우저 원본 정책 제한으로 인해 기본적으로 도메인 간에 세션을 공유할 수 없습니다. 이 문제를 해결하려면 도메인 간 세션 공유를 달성하기 위한 몇 가지 기술과 방법을 사용해야 합니다. 1. 도메인 간 세션을 공유하기 위한 쿠키의 가장 일반적인 사용
