discuz 與相容 php 5.4 的問題

最近有客戶的discuz論壇,因為需使用特殊 api ,所以需要升級使用 php 5.4 ,
但升級後,發現有相容於 php 5.4 的問題,所以我們又著手協助處理。

discuz php5.4的問題,根據discuz論壇提供的資料 http://www.discuz.net/thread-3095848-1-1.html

原來是 discuz 本身的程式碼,只有相容於 ISO-8859-1 ,所以php 5.3 之前的版本都沒有問題,php 5.4 則是使用 utf8 ,則會因此導致使用到ISO-8859-1編碼的功能出錯。

如果是根據 discuz論壇的資料,只要在 php compile 前,修改 ext/standard/html.c ,
不過這時糗事發生了,因為cpanel本身要 complie apahce或是 php ,都要透過內建的 easyapache (script 或是 gui 都行),否則可能會發生無法預期的錯誤。
以下是除錯的內容:
1. 翻了一下 cpanel 官方 knowledge ,或是 google 其他討論區,
   都沒發現 php souce 的路逕,導致無法修改 html.c 。
2. 使用 locate 找主機內的關鍵字, 也只搜索到   /home/cpeasyapache/src/php-5.4.34/ext/standard
    但這是已經 compile 過的,所以去修改 html.c ,也不會產生效果。
3.  一籌莫展下,發現在執行 easyapche 時,其實也會跑出 log 資料,抓出大約的 log 檔:
 If the browser window is closed or stopped the build will continue in the background.
The build output should start shortly…!! Local template detected: /var/cpanel/templates/apache2/vhost.local !!!! Local template detected: /var/cpanel/templates/apache2/ssl_vhost.local !!!!
If there are issues with your local templates you might be interested in setting the ‘When there are problems with local templates and the default templates are tried, move the local one to a .broken extension.’ preference. !!Distilled successfully
!! Verbose logfile is at ‘/usr/local/cpanel/logs/easy/apache/build.1415086948’ !!
!!
Output from ‘/bin/sh -c “ulimit -a”‘:
core file size          (blocks, -c) 1048576
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 127421
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 127421
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
!!
!! Creating backup of working apache in ‘/usr/local/apache.backup’. !!
!! Symlink encountered (/usr/local/apache/etc), preserving target (conf)… !!!! Backup of working apache complete. !!
Checking that all tarballs are present and up to date.
Checking that all packages are present and up to date.
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirror.hmc.edu
* extras: linux.mirrors.es.net
* rpmforge: mirror.hmc.edu
* updates: mirrors.usc.edu
Setting up Install Process
No package automake19 available.
Package gettext-0.17-18.el6.x86_64 already installed and latest version
Package libstdc++-4.4.7-11.el6.x86_64 already installed and latest version
Package 2:libpng-devel-1.2.49-1.el6_2.x86_64 already installed and latest version
Package openssl-1.0.1e-30.el6_6.2.x86_64 already installed and latest version
No package libpng-dev available.
Package zlib-devel-1.2.3-29.el6.x86_64 already installed and latest version
No package autoconf261 available.
Package libidn-devel-1.18-2.el6.x86_64 already installed and latest version
No package gmake available.
Package libidn-1.18-2.el6.x86_64 already installed and latest version
Package libXpm-3.5.10-2.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-30.el6_6.2.x86_64 already installed and latest version
Package automake-1.11.1-4.el6.noarch already installed and latest version
Package coreutils-8.4-37.el6.x86_64 already installed and latest version
Package patch-2.6-6.el6.x86_64 already installed and latest version
No package libltdl3-devel available.
No package libltdl available.
No package libopenssl0.9.7-static-devel available.
Package libtool-ltdl-devel-2.2.6-15.5.el6.x86_64 already installed and latest version
Package libXpm-devel-3.5.10-2.el6.x86_64 already installed and latest version
Package sed-4.2.1-10.el6.x86_64 already installed and latest version
No package libXpm-dev available.
Package lsof-4.82-4.el6.x86_64 already installed and latest version
No package krb5-dev available.
Package flex-2.5.35-9.el6.x86_64 already installed and latest version
No package glibc-dev available.
No package expat-dev available.
Package krb5-devel-1.10.3-33.el6.x86_64 already installed and latest version
No package libstdc++-devel.x64_64 available.
No package xorg-x11-devel available.
Package libtool-ltdl-2.2.6-15.5.el6.x86_64 already installed and latest version
No package libssl-dev available.
Package pam-devel-1.1.1-20.el6.x86_64 already installed and latest version
No package libopenssl0-devel available.
No package zlib1-devel available.
Package expat-devel-2.0.1-11.el6_2.x86_64 already installed and latest version
No package libopenssl0-dev available.
Package glibc-devel-2.12-1.149.el6.x86_64 already installed and latest version
Package expat-2.0.1-11.el6_2.x86_64 already installed and latest version
Package gcc-c++-4.4.7-11.el6.x86_64 already installed and latest version
Package zlib-1.2.3-29.el6.x86_64 already installed and latest version
Package bison-2.4.1-5.el6.x86_64 already installed and latest version
Package libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64 already installed and latest version
No package libtool-libltdl-devel available.
Package libtool-2.2.6-15.5.el6.x86_64 already installed and latest version
No package openssl-dev available.
No package libopenssl0 available.
No package libz-devel available.
No package libjpeg-dev available.
No package pam-dev available.
Package coreutils-8.4-37.el6.x86_64 already installed and latest version
No package libltdl-devel available.
No package libopenssl0.9.7-devel available.
Package e2fsprogs-devel-1.41.12-21.el6.x86_64 already installed and latest version
No package ca_root_nss available.
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
No package libstdc++-dev.x86_64 available.
Package libX11-devel-1.6.0-2.2.el6.x86_64 already installed and latest version
Package gd-2.0.35-11.el6.x86_64 already installed and latest version
Package cpp-4.4.7-11.el6.x86_64 already installed and latest version
No package xorg-x11-dev available.
Package gcc-4.4.7-11.el6.x86_64 already installed and latest version
No package ssl-dev available.
Package autoconf-2.63-5.1.el6.noarch already installed and latest version
No package lex available.
Nothing to do
!! Processing RPMs… !!

— Begin opt ‘Deflate’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘Deflate’ —

— Begin opt ‘Expires’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘Expires’ —

— Begin opt ‘Mod FastCGI v2.3.9’ —
— Begin dryrun test ‘Store FCGID working directory’ —
— End dryrun test ‘Store FCGID working directory’ —
— Begin dryrun test ‘Patch mod_fcgid’ —
Patch tested at -p1; ../mod_fcgid_patches/0001-only_signal_running.patch
Applying patch; ../mod_fcgid_patches/0001-only_signal_running.patch
patching file modules/fcgid/fcgid_proc_unix.c
Hunk #1 succeeded at 417 (offset -5 lines).
— End dryrun test ‘Patch mod_fcgid’ —

— Begin step ‘Create task list to do after apache is built’ —
— End step ‘Create task list to do after apache is built’ —
— End opt ‘Mod FastCGI v2.3.9’ —

— Begin opt ‘Fileprotect’ —
— Begin dryrun test ‘turning it on…’ —
— End dryrun test ‘turning it on…’ —

— Begin step ‘Run /usr/local/cpanel/scripts/enablefileprotect after Apache is installed’ —
— End step ‘Run /usr/local/cpanel/scripts/enablefileprotect after Apache is installed’ —
— End opt ‘Fileprotect’ —

— Begin opt ‘Headers’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘Headers’ —

— Begin opt ‘MPM Prefork’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘MPM Prefork’ —

— Begin opt ‘MemCache’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘MemCache’ —

— Begin opt ‘Proxy’ —

— Begin step ‘Adding –enable-proxy to Apache configure line’ —
— End step ‘Adding –enable-proxy to Apache configure line’ —
— End opt ‘Proxy’ —

— Begin opt ‘UniqueId’ —

— Begin step ‘Applying EasyApache patches’ —
Patch tested at -p1; /home/cpeasyapache/src/cppatch/0001-Provided-a-fallback-for-mod_unique_id-when-hostname-.patch
Applying patch; /home/cpeasyapache/src/cppatch/0001-Provided-a-fallback-for-mod_unique_id-when-hostname-.patch
patching file modules/metadata/mod_unique_id.c
— End step ‘Applying EasyApache patches’ —

— Begin step ‘to config options’ —
— End step ‘to config options’ —
— End opt ‘UniqueId’ —

— Begin opt ‘Apache 2.2’ —
— Begin dryrun test ‘Applying patches if any’ —
Patch tested at -p1; ../cppatch/2.2.6-ssl_engine_rand.patch
Applying patch; ../cppatch/2.2.6-ssl_engine_rand.patch
patching file modules/ssl/ssl_engine_rand.c
Patch tested at -p1; ../cppatch/2.2.8_ssl_scache_dbm.patch
Applying patch; ../cppatch/2.2.8_ssl_scache_dbm.p

4. 掃了一下log,看到的確也有擺放 source template 的位置,大約是在  /var/cpanel/ ,
     但不太確定,只好在多看幾行, 又看到 ../cppatch,在 locate cppatch 真實的路逕,
     在去vim 數個xxx.path , 看到了在  /var/cpanel/perl/easy/Cpanel/Easy/PHP5/ 。

5.  cd  /var/cpanel/perl/easy/Cpanel/Easy/PHP5 後,在仔細看一下資料夾內的資料,              發現了  4_34.pm.tar.gz ,解開這個壓縮檔, ext/standard/html.c  果然躲在這裡,
     修改完,在使用 easyapache compile ….. finish

================================================================

以上是透過主機的解法。 另快也可以透過修改程式去解決(比較能一勞永逸)

1.  php的官方網站,也有列出這樣的問題,以及大約要修改的語法:
http://php.net/manual/en/function.htmlspecialchars.php

2. php 官方真是相當地體貼, 把內容及除錯的方式都寫的很清楚(也就是強制讓語法使用
ISO-8859-1) :

As of PHP 5.4 they changed default encoding from “ISO-8859-1” to “UTF-8”. So if you get null from htmlspecialchars or htmlentities

where you have only set
<?php
echo htmlspecialchars($string);
echo
htmlentities($string);
?>

you can fix it by
<?php
echo htmlspecialchars($string, ENT_COMPAT,‘ISO-8859-1’, true);
echo
htmlentities($string, ENT_COMPAT,‘ISO-8859-1’, true);
?>

3. 在linux 底下,用 grep 就可以快速找出有問題的地方:
On linux you can find the scripts you need to fix by
grep -Rl “htmlspecialchars\\|htmlentities” /path/to/php/scripts/

 

================================================

以上是我們的處理心得,希望也能解決你的問題!!