1、閑來搞下PHP的東東,今天搭了下PHP的運行環境,在測試date函數時老報如下錯:
"PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in"XXX
上網查了下資料,解決方案有三: 一、在頁頭使用date_default_timezone_set()設定 date_default_timezone_set('PRC'); //東八時區 echo date('Y-m-d H:i:s'); 二、在頁頭使用 ini_set('date.timezone','Asia/Shanghai'); 三、修改php.ini。開啟php5.ini尋找date.timezone 去掉前面的分號修改成為:date.timezone =PRC或Asia/Shanghai
看了下php.ini裡面有個datetime.zone的選項:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
訪問http://php.net/date.timezone 可以看到相關的內容,裡面提到china配置的時區:
// Shanghai, China, Asia
date.timezone = "Asia/Shanghai"
date.default_latitude = 31.5167
date.default_longitude = 121.4500
改完配置後,重啟apache,運行看了下,還是報一樣的錯,就是說改的東西沒有生效,但試了下其它的兩種方法是可以的。
後面在apache設定檔httpd.conf配置支援php的地方加上:PHPIniDir "D:/php5.4.7" 問題解決
Apache 設定的時候 PHPIniDir 有什麼作用呢。
與php4搜尋php.ini是在%SystemRoot%下不同的是,PHP5按照以下順序依次尋找PHP.ini:
* PHPIniDir (Apache 2 module only)
* 註冊表索引值:HKEY_LOCAL_MACHINE—SOFTWARE—PHPIniFilePath
* 環境變數:%PHPRC%
* PHP5的目錄 (for CLI), 或者web伺服器目錄(for SAPI modules)
* Windows目錄(C:\windows or C:\winnt)
所以如果是Apache + PHP5的話可以使用 PHPIniDir 指定php5的設定檔php.ini的路徑。
#以apache的模組方式運行php,全部配置如下:
LoadModule php5_module modules/php5apache2_2.dll
PHPIniDir "D:/php5.4.7"
AddType application/x-httpd-php .php .html