php配置open_basedir後及Apache對應配置 和Yii驗證碼無法出現解決方法
阿新 • • 發佈:2019-02-06
本來沒有考慮這個問題,是對絕對路徑下的檔案進行讀寫的時候報了錯,使用的是fopen()函式
fopen("c:\\cmd.txt","r");
出現以下錯誤提示:
Warning: fopen("c:\\cmd.txt","r") - No such file or directory in
查了下,可能是沒有給PHP讀寫檔案的許可權。需要用到open_basedir進行配置
在php.ini檔案中配置:
上面這條指令設定了php指令碼可以訪問的兩個目錄,注意在windows系統中目錄之間用分號隔開
因為我用的是Apache伺服器,查了有關資料還可在Apache的配置檔案中進行設定。 Apache虛擬主機配置
1、如果開啟了虛擬主機,可以在Apache\Apache24\conf\extra\httpd-vhosts.conf中配置
<VirtualHost *:80>
DocumentRoot "D:/www"
ServerName 121.com
<Directory "D:/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
php_admin_value open_basedir "D:\www;E:\history"
</Directory>
</VirtualHost>
php_admin_value open_basedir “D:\www;E:\history”添加了這一句
2、如果沒有開啟虛擬主機,可以在Apache\Apache24\conf\httpd.conf設定
加上修改Apcahe配置檔案
php_admin_value open_basedir “D:\www;E:\history”
引號中的地址是允許PHP訪問的地址
重啟Apache後,一般情況就可以解決上述問題了。
由於使用的YII框架中用到了session ,而載入網頁的時候出現了驗證碼出現不了的情況。
驗證碼出現不了
網上查了很多資料,終於找到了,謝謝這位樓主開啟
原因:
由於用到session,所以需要允許訪問session的地址,
首先設定session存放地址 session.save_path
可以根據自己的需要確定存放的路徑
然後重啟Apache
驗證碼可以正確出現。
寫在最後
我開啟許可權之後,可以自由讀寫,然後我把允許訪問的資料夾刪掉了,如上面E:/history,我刪掉了history。
開始報錯
is_dir(): open_basedir restriction in effect. File(E:\history\cmdsd) is not within the allowed path(s): (D:\www;E:\history) in
mkdir(): open_basedir restriction in effect. File(E:\history) is not within the allowed path(s): (D:\www;E:\history) in
fopen(): open_basedir restriction in effect. File(E:\history\cmdsd) is not within the allowed path(s): (D:\www;E:\history) in
我一開始很疑惑,怎麼剛才還可以執行,現在不行了。
其實原因是沒有E盤的根目錄的訪問許可權,故不能操作了。之前是因為有history資料夾本來就存在,然後其子目錄都可以訪問,就順其自然的完成了建立資料夾和檔案的工作。