それは、サーバー運営会社からの一通のメールからはじまった
このブログおよび、当教室公式サイトhttps://curio-shiki.com/は、2月13日(の深夜)~、PHP7.0.7で動作しています。それまでは、PHP5.6.22でした。
きっかけは、レンタルサーバー(Xserver)から届いた一通のメールでした。
[XSERVER インフォメーション] 推奨PHPバージョン変更のお知らせ
平素はエックスサーバーをご利用いただき、誠にありがとうございます。この度エックスサーバーでは、
推奨するPHPバージョンを「7.0」に変更いたします。引き続きPHP 5.6 もご利用いただけますが、今後はPHP 7.0 のご利用を推奨いたします。
また、新規に追加設定されるドメインにおいて、
初期状態でご利用いただけるPHPのバージョンを「7.0」に変更いたします。詳細は、以下をご参照ください。
———————————————————————-
■変更日
2017年2月13日(月)(中略)
■PHP 7.0 について
PHP7 は、PHP5 に比べ2倍以上の実行速度を誇り、
メモリ使用量が大幅に改善されたPHPの最新バージョンです。
PHP7 をご利用いただくことにより、
高速なウェブサイトを運用することが可能となります。
これまでも、何度も「おすすめ」されてはきましたが、今回は
「新規設定ドメインの初期バージョンをPHP7.0に変更する」
という、ちょっと大胆なご提案でした。新規契約でなく新規追加ドメインですから、既存の契約でもドメインを追加すればそこだけ最初からPHP7が設定されるということになります。
WordPress 4.7の安定が大きなきっかけか?
Xserverは、Wordpressをはじめさまざまな「自動インストール」に対応していますから、つまり
すべての自動インストールプログラムがPHP7推奨となった
ことを意味すると読めます。Wordpress4.7がリリースされて2か月。初期のこまかいアップデートが、4.7.2でだいたい落ち着いたということのようですね。
しかしPHPバージョン変更は、ちょっと勇気がいる・・・
そうはいっても、PHPのバージョン変更はちょっと勇気がいります。現にサービスを提供しているサイトが、いきなり動作を停止するかもしれないのです。
当教室の場合、試験受付のフォームを運用していますので、もしもちょうど入力中の受験者の方がいたりなんかすると、いきなり500エラーに変わってしまって大変失礼なことになります。
プラグインはすべてアップデートして、Wordpress4.7との互換性チェック
まずは、前回Wordpress4.7に更新して痛い目にあった記憶も新しいため、すべてのプラグインの互換性チェックを行います。
WordPress4.7はPHP7推奨 > ということはプラグインもWordpress4.7と互換性のあるものにすれば大丈夫のはずです。
すべてアップデートし、互換性が明確でないものはいったん停止します。
php7ccでコードチェック
そのあと、いろいろ調べて検討したあげく、php7ccというチェッカーを使って、コードチェックを行うことにしました。
ダウンロード元> php7cc PHP 7 Compatibility Checker (GitHub)
このphp7ccのインストールにはcomposerという別プログラムが必須です。
XserverにSSH設定を行い、Teratermでコマンドライン接続します。
(サーバー名が出ているためコマンドプロンプトは省略し、実際に入力したコマンドのみ表示しております)
curl -sS https://getcomposer.org/installer | php ~composerインストールのごにょごにょ~ php composer.phar global require sstalle/php7cc ~php7ccインストールのごにょごにょ~ php php7cc.phar 【チェックするディレクトリ名】
うちの場合は安直にサーバールートで起動してしまったので、PATHの設定は不要。そのままルートにcomposer.pharとphp7cc.phar ができ、そのまま実行しました。
インストール途中、PHPバージョンが古いよ、という警告が出ますが、どうしようもないのでそのまま実行しました。
WordPress4.7に大量の互換性エラーが・・・
というわけで、php7ccでチェックしてみたところ、メインサイトhttps://curio-shiki.com/の方はまったく問題なくクリア。
ところが、Wordpressの部分 https://curio-shiki.com/blog に、大量のエラーが発生しているではありませんか。
[【サーバ名】@【サーバ番号】 curio-shiki.com]$ php php7cc.phar public_html File: /home/【サーバ名】/curio-shiki.com/public_html/blog/xmlrpc.php > Line 20: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 21: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 25: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 26: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 26: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/cron.php > Line 206: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/class-wp-admin-bar.php > Line 119: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(0); > Line 120: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(0); > Line 120: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(2); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random.php > Line 203: Cannot redeclare global function "random_bytes" function random_bytes($length) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_dev_urandom.php > Line 46: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_openssl.php > Line 42: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_libsodium.php > Line 42: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_int.php > Line 39: Cannot redeclare global function "random_int" function random_int($min, $max) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_mcrypt.php > Line 42: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/error_polyfill.php > Line 31: Class/trait/interface "Error" was added in the global namespace class Error extends \Exception { } > Line 38: Class/trait/interface "TypeError" was added in the global namespace class TypeError extends \Error { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_com_dotnet.php > Line 40: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/random_compat/random_bytes_libsodium_legacy.php > Line 42: Cannot redeclare global function "random_bytes" function random_bytes($bytes) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/rest-api/class-wp-rest-server.php > Line 731: Nested by-reference foreach loop, make sure there is no iteration over the same array foreach ($handlers as $key => &$handler) { } > Line 1272: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 1278: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 1279: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; > Line 1282: Removed "HTTP_RAW_POST_DATA" variable used $HTTP_RAW_POST_DATA; File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/class-wp-rewrite.php > Line 1700: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(2); > Line 1754: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(3); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/wp-db.php > Line 834: Removed function "mysql_set_charset" called mysql_set_charset($charset, $dbh); > Line 840: Removed function "mysql_query" called mysql_query($query, $dbh); > Line 861: Removed function "mysql_query" called mysql_query('SELECT @@SESSION.sql_mode', $this->dbh); > Line 875: Removed function "mysql_result" called mysql_result($res, 0); > Line 907: Removed function "mysql_query" called mysql_query("SET SESSION sql_mode='{$modes_str}'", $this->dbh); > Line 1093: Removed function "mysql_select_db" called mysql_select_db($db, $dbh); > Line 1173: Removed function "mysql_real_escape_string" called mysql_real_escape_string($string, $this->dbh); > Line 1300: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 1357: Removed function "mysql_error" called mysql_error($this->dbh); > Line 1488: Removed function "mysql_free_result" called mysql_free_result($this->result); > Line 1568: Removed function "mysql_connect" called mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags); > Line 1570: Removed function "mysql_connect" called mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags); > Line 1646: Removed function "mysql_ping" called mysql_ping($this->dbh); > Line 1780: Removed function "mysql_errno" called mysql_errno($this->dbh); > Line 1805: Removed function "mysql_error" called mysql_error($this->dbh); > Line 1826: Removed function "mysql_affected_rows" called mysql_affected_rows($this->dbh); > Line 1833: Removed function "mysql_insert_id" called mysql_insert_id($this->dbh); > Line 1846: Removed function "mysql_fetch_object" called mysql_fetch_object($this->result); > Line 1879: Removed function "mysql_query" called mysql_query($query, $this->dbh); > Line 2886: Removed function "mysql_client_encoding" called mysql_client_encoding(); > Line 3096: Removed function "mysql_num_fields" called mysql_num_fields($this->result); > Line 3098: Removed function "mysql_fetch_field" called mysql_fetch_field($this->result, $i); > Line 3194: Removed function "mysql_close" called mysql_close($this->dbh); > Line 3291: Removed function "mysql_get_client_info" called mysql_get_client_info(); > Line 3336: Removed function "mysql_get_server_info" called mysql_get_server_info($this->dbh); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/theme.php > Line 695: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg(1); > Line 2219: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 2501: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 2611: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/update.php > Line 333: Nested by-reference foreach loop, make sure there is no iteration over the same array foreach ($plugin->compatibility as &$data) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/plugin.php > Line 184: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 198: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 231: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 432: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 451: Function argument(s) returned by "func_get_arg" might have been modified func_get_arg($a); > Line 502: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/class-wp-user.php > Line 721: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/deprecated.php > Line 1789: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 1802: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 2065: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 2120: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 2177: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/shortcodes.php > Line 426: Nested by-reference foreach loop, make sure there is no iteration over the same array foreach ($attributes as &$attr) { } File: /home/【サーバ名】/curio-shiki.com/public_html/blog/wp-includes/class-wp-theme.php > Line 1056: Nested by-reference foreach loop, make sure there is no iteration over the same array foreach ($post_type as &$post_template) { } PHP Fatal error: Maximum execution time of 30 seconds exceeded in phar:///home/【サーバ名】/curio-shiki.com/php7cc.phar/src/NodeVisitor/NewAssignmentByReferenceVisitor.php on line 14 Status: 500 Internal Server Error X-Powered-By: PHP/5.3.3 Content-type: text/html
最後はなんとサーバータイムアウトです。いったいこの何倍のエラーがあるのか見当もつきません。
こうなるともう、判断は「人間の領域」です。
ここまで思いっきりエラーを吐かれると、かえって思考はスッキリしますね(笑)
- WordPress4.7の推奨動作環境はPHP7です。
- なのに、PHP7互換性エラーが大量に出ています。
- じゃあ君はどうする??
しょうがないので、Wordpressを丸ごとコピーして、テスト環境を構築して移行テストを実施することにしました。
WordPressを丸ごとコピーしてテスト環境を構築
WordPressのコピーといっても、データベースまで複製しないといけないので、結構大変です。
- サーバー画面で、新規データベースを追加
- 運用中DBのPHPMyAdminから、DB内容を丸ごとエクスポート→ダウンロード(gz圧縮)
- gzを新規DBにインポート
- WordPressファイルをテスト用ドメインに全部コピー
- 新規DBのPHPMyAdminから、Wordpressアドレスを変更
- /wp-config.php のDB名、ユーザ名、パスワードを新DBのものに変更
- テスト環境の.htaccessを確認(変なリダイレクトをしてないか)
これでやっと、テスト環境ができあがります。
PHP7.0.7切り替え成功!
テスト環境ができたので、おもむろにテスト用ドメインのPHPバージョンを7.0.7に変更してみました。
うまくいきますように! 神頼みではないですが、まぁ、Linuxに神様がいるとすればなんとかしてください的な感じです。
結果 >> 拍子抜けするぐらい正常に変更完了しました。
あの互換性エラーの山は一体なんだったのかという感じなのですが、おそらくPHP5への後方互換性を維持するコードなのではないか、ということにしておきました。(精査する時間もスキルもないので・・・)
テスト環境の切り替え成功をうけ、ぶじ当ブログ本体もPHP7.0.7に切り替えて運用しはじめました。
これでやっと、当店クライアント様の環境もバージョン変更に着手できます。やれやれ安心しました。
切り替えの効果は・・・
PHP7に切り替えたところで、目立ってどうという効果は今のところ感じません。
ちょっとだけ表示が早いような気がしますが、ネットワーク速度の影響の方が大きく、Wordpress程度の負荷では「うわー早く表示される!」 なんてことはたぶんないと思います。負荷が大きいと、これだけのスピードアップ幅であれば、違うのでしょうね。
コメント