2021-08-07

CentOS4.9, Apache2.0, PHP5.1, Smarty2.6 から CentOS7.9, Apache2.4, PHP5.6, Smarty2.6 へシステム移行

 前回の続きの作業記録です。 前回はCentOS7に(対応している一番古いバージョンの)PHP5.6を入れてphpMyAdminも使えるようにしました。この環境にCentOS4.9, PHP5.1, Smarty2.6で動いているシステムを移行したいという依頼だったのですが、PHPバージョンアップに伴うエラーが続出したため、PHP5.1か5.2に入れ替えることを提案したのですが、そのまま5.6で何とかして欲しいということなのでとりあえずトライしました。

PHPのエラーとして

PHP Fatal error:  Call-time pass-by-reference has been removed in ...

というのがあり、これは参照渡しの fatal error とのことです。


を参考にして対応しました。また、

PHP Parse error:  syntax error, unexpected 'goto' (T_GOTO), expecting identifier (T_STRING) in ...

という parse error が出たのですが、PHP5.3以降からは goto という名前の関数は使えないそうです。


Smartyについては新しくインストールせず、そのまま古いファイルをごっそりコピーしました。

PHP Fatal error:  Smarty error: unable to write to $\$$compile_dir '/.../libs/smarty/templates_c'. Be sure $compile_dir is writable by the web server user. in /.../libs/smarty/libs/Smarty.class.php

とエラーが出たので該当ディレクトリのパーミッションを chmod0777 としました。それ以外にも公開画像やファイルが入っているディレクトリのパーミッションを変更しました。Smarty2についてはPHP5.1からPHP5.6にあげてもとりあえずは動いてくれるようです。

その他、設定ファイルの変更やhtaccessファイルが使えるようにhttpd.confの編集を行いました。(AllowOverride NoneをAllに変更。)

# vim /etc/httpd/conf/httpd.conf
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All
# systemctl restart httpd

また、旧サーバと見比べてPHP.iniを変更しました。関連して、

PHP Warning:  strftime(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in ...

と出たので


を参考にして、

# vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Asia/Tokyo"
# systemctl restart httpd

と対応。

データベースへのアクセスにエラーが出たのでmysqliにしないといけないのかと一瞬焦りましたが、設定ファイルでパスワードが間違っていたためでした。DB周りのスクリプトはそのまま使えました。


PHPの警告、非推奨メッセージ

PHP Warning:  preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in ...
PHP Deprecated:  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ...

が出ましたが、非推奨についてはPHP7でないので関係ありませんでした。警告については対応する必要があります。


● Pager install

Pagerパッケージを使っているページは

PHP Warning:  require_once(Pager/Pager.php): failed to open stream: No such file or directory in ...

となりHTTP500エラーが出てしまったので、pearからPagerをインストールして解決しました。まずpearのインストールはphpMyAdminの時と同様にPHP5.6に対応したものを入れます。

#  yum -y --enablerepo=remi-php56 install php-pear
Complete!
# pear version
PEAR Version: 1.10.12
PHP Version: 5.6.40
Zend Engine Version: 2.6.0

OK! っぽい

# pear install Pager
install ok: channel://pear.php.net/Pager-2.5.1

これでとりあえずメインのページは表示できました!!まだ表示できないところもありますが、必要であればエラーログ

# tail -f /var/log/httpd/error_log

を確認して対応したいと思います。

それにしても2007年の環境で(他人が)作ったシステムをいまの環境に移行するのはめんどくさいです!バージョンの互換性の確認が手探り状態なので大変です。バージョン管理の意義も理解できますが、できるだけ古いものも使えるようにバージョンアップしてくれないものでしょうか?まあ、古いの使うな!ってことなのでしょうけど。(私も使いたくないですが、こういう時は往々にして決定権が自分にな~い!)

0 件のコメント: