Debian Linux 使用 testing 的話, 若於上星期有做過 dist-upgrade 的話, 就會發現 PHP 已經被升級到 5.3.1-5, 而且出現一堆警告訊息.
我遇到的有下面這三種錯誤訊息:
- PHP Warning: strtotime(): 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 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /tmp/a.php
- PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/imagick.so' /usr/lib/php5/20090626/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
- PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0
strtotime() 修正
- PHP Warning: strtotime(): 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 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /tmp/a.php
strtotime() 出現的這個警告是要我們先指定正確的時區(Timezone), 再來使用這個 function.
解法下述幾種 (挑其一即可, 建議用 1 或 3 的方法)
- 於 PHP 檔案內使用 date_default_timezone_set()
ex:
<?php
date_default_timezone_set('Asia/Taipei');
echo strtotime('2010-03-01');
?> - 設定 php.ini
vim /etc/php5/apache2/php.ini # 於 php.ini 的 date.timezone
;date.timezone =
改成
date.timezone = "Asia/Taipei" - 設定 php.ini (於 Debian 比較建議這樣做, 就不用去分別改 apache / cgi / cli 的 php.ini)
vim /etc/php5/conf.d/date_timezone.ini # 於此檔案加下述
date.timezone = "Asia/Taipei"
PHP Startup: Unable to load dynamic library 修正
- PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/imagick.so' /usr/lib/php5/20090626/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
發現下述這幾個都不見了 (php5-imagick, php5-mhash, php-apc)
- /usr/lib/php5/20090626/apc.so
- /usr/lib/php5/20090626/mhash.so
- /usr/lib/php5/20090626/imagick.so
- php5-mhash 已經包進去, 不需另外安裝, imagick、apc 目前還沒看到.
解法
- rm /etc/php5/cli/conf.d/apc.ini /etc/php5/cli/conf.d/imagick.ini /etc/php5/cli/conf.d/mhash.ini
Comments starting with '#' are deprecated 修正
- PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0
cat /etc/php5/cli/conf.d/imagick.ini # 第一行有個註解 "#"
解法
- 在 PHP 5.3.x 這些 ext 的註解已經不建議使用 "#", 所以將這個註解拿掉, 或者將 "#" 改成 ";" 開頭即可. (開頭 ; 也是註解的意思)