※当サイトの記事には、広告・プロモーションが含まれます。

LaravelとWordPressの共存って...その前に、php.iniのextensionたちが認識されないなどなど...

花粉症で、腸内環境の乱れが甚だしい、どうもボクです。

PHPフレームワークのLaravelと、PHPCMSWordPressを連携させたいということで、

ts0818.hatenablog.com⇧   Apache HttpdPHP、Laravel あたりをインストール。

ts0818.hatenablog.com

⇧  MySQL 8.0の新しい認証方法でハマる。 

ts0818.hatenablog.com

⇧ 結局、MySQL 8.0の新しい認証方法は断念。

このへんで、中途半端な状態になってたわけですが、WordPressをインストールしちゃいましょうということで、今回は、PHPのお話。

かなり、まとまりのない内容になってしまっているので、お時間のある方のみご照覧ください。

そんでは、レッツトライ~。

 

WordPressのインストール

インストールする場所は、

f:id:ts0818:20190224181122p:plain

⇧  Laravel と同じ階層で。WordPressのインストールに必要なファイル一式は配置できているので、後は、WordPress用に空のデータベースを用意してあげると。

で、自分の場合は、

f:id:ts0818:20190224182614p:plain

に、配置しているMySQLを使ってます。

で、ログインし(ポートとかはご自分のお使いの環境に合わせてください。デフォルトの3306ポートであれば、ポートは特に指定不要)、

f:id:ts0818:20190224183946p:plain

いま、存在するデータベースの一覧を確認。

f:id:ts0818:20190224184043p:plain

というわけで、

www.adminweb.jp

⇧  上記サイト様を参考に、

WordPress用に、空のデータベースを作成します。

f:id:ts0818:20190224184233p:plain

んで、ユーザーを作成し、

f:id:ts0818:20190224184544j:plain

作成したデータベースに対する権限を、作成したユーザに付与。

f:id:ts0818:20190224184902j:plain

とりあえず、データベースの準備はOK。

んで、Apache Httpdのを起動します。自分は、Chocolateyでインストールしたので、

f:id:ts0818:20190224185955p:plain

⇧  みたいな場所にインストールされています。

起動しようと思ったら、Windowsのサービスとして既に起動されてたようです。

f:id:ts0818:20190224190225p:plain

⇧  Windowsが起動したら、自動起動となるような設定になってたみたいです。

で、ブラウザからアクセスするも、

f:id:ts0818:20190224191347p:plain

「昨日探し当てた場所に 今日もジャンプしてみるけれど なぜか NOT FOUND 今日は NOT FOUND」っていうMr.Childrenの懐かしの曲『NOT FOUND』が出たとことで、

はい、404 です...。

これは、Apacheで指定されてるドキュメントルート以外の場所に、WordPressのサイトのファイルを配置してるからですかね。

よく分からんですが、Webサーバは、ドキュメントルートに配置されたファイル群しか読み込んでくれないってことですかね。

www.be-webdesigner.com

⇧  上記サイト様が詳しいです。

んで、「"C:\HTTPD\Apache24\conf\httpd.conf"」とか見てみると、

f:id:ts0818:20190224193226p:plain

⇧ DocumentRoot が、「${SRVROOT}/htdocs」とかってなっていて、「SRVROOT」はというと、「C:/HTTPD/Apache24」となっている。

f:id:ts0818:20190224193402p:plain

つまり、DocumentRootは、「C:/HTTPD/Apache24/htdocs」のフォルダになり、このフォルダ配置されたものにアクセスしとるそうな。

つまり、「C:\Users\Toshinobu\Desktop\php_project\wordpress」にはアクセスされないんですな...

つまり、

  1. DocumentRootに、サイトのファイルを配置する
  2. DocumentRootのパスを修正する

のどちらかの対応をする必要があると。(他にも、VirtualHostとかでもできるのかな?サーバ詳しくないから分からんです...)

今回は、1.DocumentRootに、サイトのファイルを配置で。

f:id:ts0818:20190224194301p:plain

配置されました。

f:id:ts0818:20190224194655p:plain

f:id:ts0818:20190224194802p:plain

んで、再び、ブラウザで、WordPressを配置したディレクトリにアクセスすると(自分の場合ですと「http://localhost/php_project/wordpress/」)

f:id:ts0818:20190224195003p:plain

⇧  ちょっと、おかしな表示になってしまっているのですが、下の方にスクロールすると、「2. wp-admin/install.php をブラウザーで開きます。」ってあるので、リンクをクリックで。

f:id:ts0818:20190224195104p:plain

そしたら、完全に、バグってますな...phpが認識されとらん...

f:id:ts0818:20190224195453p:plain

どうも、手順が誤っていたらしい...

wpdocs.osdn.jp

⇧  wp-config.php ってファイルを作成する必要があるらしい。「wp-config-sample.php」ってファイルをリネームして編集すれば良いらしい。

というわけで、リネーム。

f:id:ts0818:20190224200647p:plain

そしたらば、適当なテキストエディターで開き、

f:id:ts0818:20190224200747p:plain

データベースの接続情報を設定。

f:id:ts0818:20190224201510j:plain

認証用ユニークキーの設定。

wp-config.phpの認証用ユニークキーのコメント部分に記載されているhttps://api.wordpress.org/secret-key/1.1/salt/ にアクセスすると、自動で生成してくれるらしい。

f:id:ts0818:20190224201902j:plain

⇧  上記の内容を全部コピって、wp-config.phpに保存で。

f:id:ts0818:20190224202122j:plain

で、変わらず...

sanuki-tech.net

⇧  上記サイト様によりますと、Webサーバ側で、phpを使えるようにしてあげる必要があるらしい...

自分の場合ですと、ChocolateyでインストールしたPHPを使うので、

f:id:ts0818:20190224211050p:plain

⇧  「php7apache2_4.dll」、「php.ini」ってファイルの場所をApacheに教えて上げる必要があるようです。ご自分の使用したいPHPのものに合わせてください。

httpd.conf に設定してあげます。

f:id:ts0818:20190224211349p:plain

で、Apache httpd を再起動で。

f:id:ts0818:20190224211612p:plain

で、PHPが機能してるかのテスト用に、適当なphpファイルを作成し、

f:id:ts0818:20190224212140p:plain

下記の内容で保存し、

f:id:ts0818:20190224212210p:plain

http://localhost/phpinfo.php」にアクセス。

f:id:ts0818:20190224212014p:plain

⇧  PHPが認識されました。

で、WordPressのほうはというと...変わらんやんけ~!

f:id:ts0818:20190224212513p:plain

エラーの内容が、

WordPress requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.」って...サーバはPHP認識しとるわ~、このたわけが~!

すみません、取り乱しました...

そして、「http://localhost/php_project/wordpress/index.php」にアクセスしたら、

f:id:ts0818:20190224214846p:plain

⇧  ん?データベース系でエラー?

qiita.com

money-affairs.com

⇧  php.ini の設定で、「extension=mysqli」を使えるよう、コメントアウトを外す必要があるそうな...

f:id:ts0818:20190224220454p:plain

⇧  コメントアウトされとるがな...

おりゃ~!

f:id:ts0818:20190224220530p:plain

変わらんやんけ~!

f:id:ts0818:20190224214846p:plain

phpinfo.php に追記して、extension が読み込めてるのかチェック。

f:id:ts0818:20190224223249p:plain

f:id:ts0818:20190224223351p:plain

ん?なんか読み込めてなくない?

pg.4696.info

qiita.com

⇧  上記サイト様を参考に、httpd.conf に追記。

f:id:ts0818:20190224231551p:plain

Apache を再起動するも、変わらず...

d.hatena.ne.jp

⇧  上記サイト様によりますと、OpenSSLのバージョンが怪しいときがあるとのこと。

で、Apacheにアクセスして、使用しているOpenSSLのバージョンを確認してみると、

f:id:ts0818:20190302191848p:plain

⇧  OpenSSL/1.02p ってなってるから、要件を満たしてそうに思えるのですが...

Apacheを再起動して、Apacheのログファイル(自分の場合ですと「C:\HTTPD\Apache24\logs\error.log」)を見てみたら、

[Sat Mar 02 19:31:21.189709 2019] [mpm_winnt:notice] [pid 12896:tid 612] AH00455: Apache/2.4.37 (Win64) OpenSSL/1.0.2p PHP/7.2.10 configured -- resuming normal operations
[Sat Mar 02 19:31:21.189709 2019] [mpm_winnt:notice] [pid 12896:tid 612] AH00456: Server built: Oct 19 2018 09:39:26
[Sat Mar 02 19:31:21.189709 2019] [core:notice] [pid 12896:tid 612] AH00094: Command line: 'C:\\HTTPD\\Apache24\\bin\\httpd.exe -d C:/HTTPD/Apache24'
[Sat Mar 02 19:31:21.189709 2019] [mpm_winnt:notice] [pid 12896:tid 612] AH00418: Parent: Created child process 7156
[Sat Mar 02 19:31:21.573013 2019] [ssl:warn] [pid 7156:tid 492] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
[Sat Mar 02 19:31:21.698005 2019] [ssl:warn] [pid 7156:tid 492] AH01909: localhost:443:0 server certificate does NOT include an ID which matches the server name
PHP Warning:  PHP Startup: mbstring: Unable to initialize module\nModule compiled with build ID=API20170718,NTS,VC15\nPHP    compiled with build ID=API20170718,TS,VC15\nThese options need to match\n in Unknown on line 0
PHP Warning:  PHP Startup: exif: Unable to initialize module\nModule compiled with build ID=API20170718,NTS,VC15\nPHP    compiled with build ID=API20170718,TS,VC15\nThese options need to match\n in Unknown on line 0
PHP Warning:  PHP Startup: mysqli: Unable to initialize module\nModule compiled with build ID=API20170718,NTS,VC15\nPHP    compiled with build ID=API20170718,TS,VC15\nThese options need to match\n in Unknown on line 0
PHP Warning:  PHP Startup: openssl: Unable to initialize module\nModule compiled with build ID=API20170718,NTS,VC15\nPHP    compiled with build ID=API20170718,TS,VC15\nThese options need to match\n in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_mysql_xdevapi' (tried: C:\\chocolatey-package\\php72\\ext\\php_mysql_xdevapi (%1 \xef\xbf\xbd\xcd\x97L\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd Win32 \xef\xbf\xbdA\xef\xbf\xbdv\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdP\xef\xbf\xbd[\xef\xbf\xbdV\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xc5\x82\xcd\x82\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xdc\x82\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdB), C:\\chocolatey-package\\php72\\ext\\php_php_mysql_xdevapi.dll (\xef\xbf\xbdw\xef\xbf\xbd\xe8\x82\xb3\xef\xbf\xbd\xea\x82\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdW\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd[\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xc2\x82\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xdc\x82\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdB)) in Unknown on line 0
[Sat Mar 02 19:31:21.729253 2019] [mpm_winnt:notice] [pid 7156:tid 492] AH00354: Child: Starting 64 worker threads.

拡張モジュール、つまり、extensionの読み込みにことごとく失敗してますな... 

When you update the version of PHP (especially when going from version X.Y to version X.Z)you must update the PHP extensions as well.
This is because PHP extensions are developped in C, and are "close" to the internals of PHP -- which means that, if the APIs of those internals change, the extension must be re-compiled, to use the new versions.

memcached - Apache is "Unable to initialize module" because of module's and PHP's API don't match after changing the PHP configuration - Stack Overflow

とあり、WindowsLinux系で対処法が分かれると。

How to update your PHP extensions will depend on which system you are using.

If you are on windows, you can find the .dll for some extensions here : http://downloads.php.net/pierre/ 
For more informations about the different versions, you can take a look at what's said on the left-sidebar of windows.php.net.

If you are on Linux, you must either :

  • Check what your distribution provides
  • Or use the pecl command, to re-download the sources of the extensions in question, and re-compile them.

memcached - Apache is "Unable to initialize module" because of module's and PHP's API don't match after changing the PHP configuration - Stack Overflow 

stackoverflow.com

⇧  PHPの管理なら、composerがあるやん、composerで、extension とかのupgradeとか良しなにしてくれるんでしょ?って思ってたのが浅はかでした...

PEARPHP Extension and Application Repository)の問題点を解消するためにリリースされたはずのcomposerのはずだと思うんですがね...

まぁ、composer でPHPのextensionを管理できるのか分からずです...面目ない。

 

で、エラーの内容で、mbstring モジュールを例に見てみると、

PHP Warning:  
PHP Startup: mbstring: Unable to initialize module\n
Module compiled with build ID=API20170718,NTS,VC15\n
PHP    compiled with build ID=API20170718,TS,VC15\n
These options need to match\n in Unknown on line 0

拡張モジュールとPHPで、コンパイルに使用しようとしてる情報が合ってないようです、すれ違う2人の思い、どうなる?

qiita.com

⇧  上記サイト様によりますと、 

※TSはThread Safe=マルチスレッド対応。NTSはNon Thread Safe=スレッド非対応。
参考:PHP のNon Thread Safe とThread Safe の違い

【PHP】pthreadsでマルチスレッド - Qiita

ということで、自分の場合ですと、 拡張モジュール側は、NTSで、PHP側はTSでコンパイルしようとして、初期化できないってなってるのかと、と言うか、エラーの内容の差異を見てもそこしか違いが無いんだから、それ以上は分からんです。(なんか他に分析の仕方があるのかもしらんですが、わたくしは存じ上げません。)

というか、ChocolateyでインストールしたPHPだから不具合なのか...Chocolatey使わないほうが良いのかしら。

 

As you are on Windows, you need the TS (Thread Safe) version of the dll and not the NTS (Not Thread Safe) version.

Make sure that the php.ini file is loading only the TS extension.

cakephp - How to recompile PHP with either NTS or TS? - Stack Overflow

stackoverflow.com

⇧  まじか...Windowsは、TS (Thread Safe) なextension のみ許容されるとな...

で、やっぱり、ChocolateyでインストールしたPHPがスレッドセーフでなかったと。

一旦、アンインストールで。(ChocolateyでPHPをインストールしてない場合は、アンインストールは不要です。)

コマンドだとアンインストール失敗するので、エクスプローラーから直接削除で。(Apacheが動いてると、PHPを参照してるって成ってフォルダが消せないので、一旦、Apacheのサービスは止めときます。)

f:id:ts0818:20190302222914p:plain

f:id:ts0818:20190302223758p:plain

f:id:ts0818:20190302224007p:plain

環境変数とかからも削除で。

f:id:ts0818:20190302224251p:plain

で、改めて、PHPをインストール。結局、またChocolatey使ってますが...

f:id:ts0818:20190302224535p:plain

f:id:ts0818:20190302225005p:plain

毎回、見事に指定したところにはインストールされないと...安定の不親切さ。

とりあえず、php.iniを。

f:id:ts0818:20190302225337p:plain

f:id:ts0818:20190302225632p:plain

Apachehttpd.confも修正。

f:id:ts0818:20190302225843p:plain

で、Apache再起動。

ようやく、extension が読み込まれました。いや~、スレッドセーフじゃないと拡張機能が有効にできんとか知らんがな...むちゃくちゃハマってしまった...時間を返して欲しいですわ(涙)。

f:id:ts0818:20190302230024p:plain

WordPressphpファイルも認識されました、エラーになってるけど...。

f:id:ts0818:20190302230254p:plain

MySQLのポートを3306から3309に変えていたので、wp-config.phpのデータベースの設定を変える必要があったようです。

wpdocs.osdn.jp

変更後、か、変わらんやん...

たぶん、extension が足りてないんだとは思うけども...もうちょい調査が必要ですかね。

中途半端ですが、今回はこのへんで。

 

2019年3月3日(日)追記:↓ ここから

どうやら、問題だったのは、MySQLのほうで、

blog.codebook-10000.com

e-joint.jp

  1. flush privilegesしてなくて、権限が反映されてなかった
  2. MySQL 8.0の[caching_sha2_password]っていう認証プラグインが、WordPressに対応していない

ということだったので、 

f:id:ts0818:20190303200825p:plain

⇧  上記の対応を行ったところ、無事にWordpressのインストール画面に遷移できましたとさ、MySQL 8.0 の認証プラグインとか新しくしてくれるのは良いんだけど、使えないなら意味ないじゃん...

f:id:ts0818:20190303201420p:plain

f:id:ts0818:20190303201819p:plain

で、無事、ログインできると思いきや、なんかエラー出てるし...

f:id:ts0818:20190303202037p:plain

ログインしたら...涙

f:id:ts0818:20190303202124p:plain

⇧  なんだろう、WordPressって簡単にインストールできるって聞いたけど、全然簡単にインストールできないですけど...

blog.ohgaki.net

⇧  上記サイト様によりますと、

曖昧なcontinue文の禁止

PHP 7.3未満でも文法的には曖昧ではなかったのですが「次のループ処理に移行する」つもりでcontinueを書いても、switch文内ではbreakの意味で動作していました。

本来、switchを抜けるにはbreakを用いるべきであり、上位ブロックのループから抜ける為にcontinueを使うはに”continue 2″などでなければなりません。PHP以外の言語では、switch文の中で”continue”を使うとPHPでいう所の”continue 2″の意味として動作します。この為、間違えやすい仕様であると長年指摘されてきました。

要するにPHP 7.3から”break”の代わりに”continue”は使えなくなります。

PHP 7.3 – yohgaki's blog

ということみたいです。

github.com

WordPressを最新に更新すればOKらしい。旧いほうのwp-config.phpだけデスクトップとかにコピーしようと思ったけど、そもそも、wp-config.php自体はデフォルトで存在しないので、まるごとwordpressフォルダを上書きで問題ないかと。

f:id:ts0818:20190303204435p:plain

エラーは消えたんですが、

f:id:ts0818:20190303204852p:plain

ログイン後は変わらず...

f:id:ts0818:20190303204950p:plain

ちなみに、「themes.php」をクリックしたら、管理画面に遷移したけども...

f:id:ts0818:20190303205706p:plain

どうやら、apacheの設定の問題らしい。

www.ritolab.com

⇧  上記サイト様を参考に、「Options Indexes FollowSymLinks」を「Options FollowSymLinks」に変更したら、

f:id:ts0818:20190303213253p:plain

Index ofの一覧表示はされなくなったんだけども、サイト自体も表示されなくなったと...

原因は、Apachehttpd.confの設定でした。

teratail.com

DirectoryIndexに、「index.php」、「/index.php」を追加し、何故か知らんけど、「.htaccess」ファイルとかのアクセスが拒否されてたんで、「Require all granted」にしました。っていうか、Apacheの設定とか知らんし...

f:id:ts0818:20190303215119p:plain

んで、一応、Apache Httpdサーバの再起動とかしました。

f:id:ts0818:20190303215609p:plain

で、無事、サイトも表示されましたとさ...疲れました。

f:id:ts0818:20190303215658p:plain

Laravelのほうは、Apacheで動いてるのか、内部サーバで動いてるのか、ちょっとまだ確認できてないです...たぶん、Apacheのほうで動いてるんだと思いますが...

たしかLaravel内臓の簡易サーバのポートは、8000だった気がするし。

f:id:ts0818:20190303222400p:plain


なんか、WordPress用のApacheの設定とか他にもあるのかもしらんけども...
とりあえず、今回も疲れた(「失われた時を求めて(著:マルセル・プルースト)」を読み切ったぐらいの気持ち)ので、時間あるときに調査で...
 
2019年3月3日(日)追記:↑ ここまで