PHPバージョンアップでエラー続出、何とかクリアしたが・・

2019年9月17日

php7へのバージョンアップ、いろいろ調べると、最新のwordpressは、php7にすべきなんて記事が出てきます。

2017年1月5日の記事ですが、この記事では、著者が結論として、「PHP7にすべきである。」と言っています。事実を3つほど挙げて解説しています。

いつWordPressをPHP7にすべきか?

60爺ですが、なぜ、php7へのバージョンアップを考えたかというと、理由は簡単です。

今回、テーマを無料の sinmplicity2 から The Thor に変更しようとしたところ、その1番目にPHPのバージョンは、7.0 以上であることと記されていたからです!

スポンサーリンク

バージョンアップの方法の調査

早々に、60爺のPHPバージョンを調べてみると、以下のように、5.6であることがわかりました。これでは、 The Thor の実行条件を満たしていません。

mizutan@raspbian:~ $ sudo php -v
password for mizutan:
PHP 5.6.40-0+deb8u4 (cli) (built: Jun 3 2019 18:18:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies 

チャチャッと動かしてみる手はあったのですが、wordpress が動かなくなる可能性が記されているので、危うい所で断念しました。

そこで、PHPのバージョンアップの方法をいろいろと調べたのですが、RaspberryPi における良さそうな記事が見つけられず、ようやく※参考1の記事にたどり着きました。

この記事に従って、バージョンアップを開始します。


バージョンアップへの道!

60爺が、こういうことをやると、必ず何かが起こります。ネガティブな考えをしてはいけないのですが、大体記事通り、すんなり終了することは稀なんです。

この記事では、php7.1.7を採用していますが、どうせなら、最新版にしようと php7.3.7 を選びました。

記事と違うことをやるなんて、60爺自ら死地を選んでいるのではと言われても仕方ありませんね。案の定、エラーの嵐に遭遇することになりました。

./configuareでエラー

① ワーニング

まず、ワーニング発生です!
上記記事では、「エラーが出たら頑張ってください」と書かれています。

configure: WARNING: unrecognized options: --with-mcrypt, --with-t1lib, --enable-gd-native-ttf, --with-mysql

そして、これらは調べると以下のように不要であることがわかりましたので無視します。

–with-mcrypt
最新版はopensslにも対応しているので、必須ではないそうです

–with-t1lib
PHP 7.0.0 で削除されました

–enable-gd-native-ttf
これは PHP 5.5.0 以降では何の効果もなくなりました。PHP 7.2.0 で削除される予定です

② ファイルapxs2不明

次にこいつです。apxs2 がない!

Sorry, I cannot run apxs. Possible reasons follow:
1.Perl is not installed
2.apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3.Apache was not built using --enable-so (the apxs usage page is displayed)
The output of /usr/bin/apxs2 follows:
./configure: line 6311: /usr/bin/apxs2: No such file or directory

確かに、フォルダ /usr/bin/ を見ても、このファイル apxs2 が存在しません。ということは、きっと何かのインストールが足りていないと思われます。

ググりまくりましたが、なかなか正解にたどり着きません。しかし、諦めずに散々調べた挙句、※参考2の記事の中にそれらしきものを見つけ、以下のインストールで対応できました。

apxs2 が存在しない場合、以下をインストールする。
prefork なら apache2-prefork-dev

これで、aps2 がないエラーは解消されたようです。

③ libzipがない

さて、これで、./configuare が正常終了するかと思いきや、新たなエラーが発生しました。

checking for the location of zlib… /usr
checking for pkg-config… (cached) /usr/bin/pkg-config
checking for libzip… not found
configure: error: Please reinstall the libzip distribution

libzipをインストールするよう促されましたが、調査したところ、これはなくても問題がなさそうなので、オプションから –enable-zip を削除しました。

④ ようやくOKとなる

さて、再実行したところ、./configuare が正常終了しました。

Configuring TSRM
Configuring libtool
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| *** WARNING *** |
| |
| You have built PHP for Apache's current non-threaded MPM. |
| If you change Apache to use a threaded MPM you must reconfigure |
| PHP with --enable-maintainer-zts |
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mcrypt, --with-t1lib, --enable-gd-native-ttf, --with-mysql

ふう・・・!第一関門突破です。

make test と make install

参考にした記事では、make test を時間の関係で実行しなかったといっていますが、60爺は実行してみました。とくに、問題なく完了しましたので、続けて make install を実行しました。

こちらも特に問題なく終了しました。

root@raspbian:~/php7/php-7.3.7# make install
Installing PHP SAPI module: apache2handler
/usr/share/apache2/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' libphp7.la /usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install install libphp7.la /usr/lib/apache2/modules/
libtool: install: install .libs/libphp7.so /usr/lib/apache2/modules/libphp7.so
libtool: install: install .libs/libphp7.lai /usr/lib/apache2/modules/libphp7.la
libtool: install: warning: remember to run libtool --finish /root/php7/php-7.3.7/libs' chmod 644 /usr/lib/apache2/modules/libphp7.so 
[preparing module `php7' in /etc/apache2/mods-available/php7.load]
Enabling module php7.
To activate the new configuration, you need to run:
service apache2 restart
Installing shared extensions: /opt/php7/lib/php/extensions/no-debug-non-zts-20180731/
Installing PHP CLI binary: /opt/php7/bin/
Installing PHP CLI man page: /opt/php7/php/man/man1/
Installing phpdbg binary: /opt/php7/bin/
Installing phpdbg man page: /opt/php7/php/man/man1/
Installing PHP CGI binary: /opt/php7/bin/
Installing PHP CGI man page: /opt/php7/php/man/man1/
Installing build environment: /opt/php7/lib/php/build/
Installing header files: /opt/php7/include/php/
Installing helper programs: /opt/php7/bin/
program: phpize
program: php-config
Installing man pages: /opt/php7/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /opt/php7/lib/php/
[PEAR] Archive_Tar - installed: 1.4.7
[PEAR] Console_Getopt - installed: 1.4.2
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.3
[PEAR] PEAR - installed: 1.10.9
Wrote PEAR system config file at: /opt/php7/etc/pear.conf
You may want to add: /opt/php7/lib/php to your php.ini include_path
/root/php7/php-7.3.7/build/shtool install -c ext/phar/phar.phar /opt/php7/bin
ln -s -f phar.phar /opt/php7/bin/phar
Installing PDO headers: /opt/php7/include/php/ext/pdo/ 
スポンサーリンク

バージョンアップ確認

php7有効化、php5無効化

php7を有効化します。

root@raspbian:~/php7/php-7.3.7# a2enmod php7
Module php7 already enabled

続けて、php5を無効化しました。

root@raspbian:~/php7/php-7.3.7# a2dismod php5
Module php5 disabled.
To activate the new configuration, you need to run:
service apache2 restart

コンフィグファイル作成

記事に従い、コンフィグファイルを作成します。

root@raspbian:~/php7/php-7.3.7# cd /etc/apache2/conf-available
root@raspbian:/etc/apache2/conf-available# vi php7.conf
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule> 

続けて、以下コマンドを実行して終了です。

root@raspbian:/etc/apache2/conf-available# a2enconf php7
Enabling conf php7.
To activate the new configuration, you need to run:
service apache2 reload
root@raspbian:/etc/apache2/conf-available# apache2ctl restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

これで、apache2 を再起動して、さあ、やることはやりました。これで、php のバージョンは上がっているはずです。

以下のファイルを作成し、/var/www/html/ 配下にセットします。

<?php
phpinfo();
?>

その結果、以下のようにバージョンが 7.3.7 となっていることが確認できました。

しかし、コマンドだと相変わらず php5 になっちゃいます。

mizutan@raspbian:~ $ sudo php -v
password for mizutan:
PHP 5.6.40-0+deb8u4 (cli) (built: Jun 3 2019 18:18:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies 

これは、PATHが通っていないせいですね。ひとまず、このままで・・・

※参考
1.Raspbianで公式php7をビルド & インストールする
2.Debian8(jessie)にphp7をインストールしてApache2.4で動かす

スポンサーリンク
この記事を書いた人

60爺

60路を越え、RaspberryPi と出会い、その関係でブログ開設(2017/2~)となりました。始めてみると、コツコツやるのが性に合ってしまい、漢字の記事から家の補修・将棋・windows10関係・別名・言い方などジャンルを拡大して今に至ってます。まだまだ、元気なので新たな話題を見つけて皆様に提供できればと思っています。「プロフィールはこちら

ブログ運営

Posted by 60爺