CakePHPを使う前の各設定

CakePHPを使用する前には、Webサーバ設定ファイルの修正やPHP設定ファイルの修正などやらなければならないことがいくつかあります。ここではCakePHPを使う前の準備として必要なことをまとめます。

 

Webサーバ設定ファイルの修正

CakePHPではApache HTTP Severの「mod_rewrite」というモジュールを使用しています。そのため、このモジュールを読み込まれる状態なっているか確認する必要があります。XAMPPなどの開発ツールを使用しているのであれば、このモジュールがあらかじめ有効になっている可能性が高いです。

確認ファイルの場所をWindowsのみについて紹介します。私は開発環境の構築にXAMPPを使っているので、XAMPP内の設定ファイル場所を紹介させていただきます。なお、設定ファイル名は「httpd.conf」というものです。

・Windows

C:\xampp\apache\conf\httpd.conf

この「httpd.conf」というファイルの中で、以下の行を検索し、有効(#が冒頭に記載されていないこと)になっていることを確認します。あらかじめ#が外れているのであれば、そのままで構いません。

LoadModule rewite_module modules/mod_rewrite.so

もしファイルを修正したのであれば、Apacheサーバを再起動してください。そうすることで修正が反映されます。

 

PHP設定ファイルの修正

次はPHPに関する修正です。使用しているPHP内のphp.iniというファイルをテキストエディタで開いてください。xampp内のphpの場合以下の場所です。

C:\xampp\php\php.ini

このファイルの中にライブラリ使用のための文を追記する必要があります。この手続きをしないと、cakephpのアプリを作成するときに以下のようなエラーが出てしまいます。

 

Your requirements could not be resolved to an installable set of packages.

Problem 1
– cakephp/cakephp 3.5.9 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.8 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.7 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.6 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.5 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.4 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.3 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.2 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.14 requires ext-intl * -> the requested PHP extension intl is missin
– cakephp/cakephp 3.5.13 requires ext-intl * -> the requested PHP extension intl is missin
– cakephp/cakephp 3.5.12 requires ext-intl * -> the requested PHP extension intl is missin
– cakephp/cakephp 3.5.11 requires ext-intl * -> the requested PHP extension intl is missin
– cakephp/cakephp 3.5.10 requires ext-intl * -> the requested PHP extension intl is missin
– cakephp/cakephp 3.5.1 requires ext-intl * -> the requested PHP extension intl is missing
– cakephp/cakephp 3.5.0 requires ext-intl * -> the requested PHP extension intl is missing
– Installation request for cakephp/cakephp 3.5.* -> satisfiable by cakephp/cakephp[3.5.0,
.5.3, 3.5.4, 3.5.5, 3.5.6, 3.5.7, 3.5.8, 3.5.9].

To enable extensions, verify that they are enabled in your .ini files:
– C:\xampp\php\php.ini
You can also run `php –ini` inside terminal to see which files are used by PHP in CLI mode.

php.iniのファイルの中に新たに文を追記するといっても、基本的には;をコメントアウトするだけでこのエラーを消すことができるので、追記というほどのものでもないかもしれません。以下の文字列を検索し、冒頭の;(セミコロン)をコメントアウトしてください。

;extension=intl

 

CakePHPのインストールに関する項目を見ると、この処理について以下のように説明されています。

XAMPP / WAMP のいずれでも、mcrypt 拡張も mbstring 拡張も初期インストール状態で 動きます。

XAMPP では intl 拡張は同梱されていますが、 php.ini の extension=php_intl.dll のコメントを外して XAMPP コントロールパネルからサーバーの再起動を行う必要はあります。

インストール - 3.10

XAMPPでは初めからintl拡張が同梱されているので、新たにインストールする必要はありません。そして、「 php.ini の extension=php_intl.dll のコメントを外して」という一文にでは、あたかもphp.iniの中に「extension=php_intl.dll」という項目が記述されているように思えるかもしれませんが、PHP7.2以降では表示形式が若干変わっており、「extension=php_intl.dll」というワードの検索では該当の項目は見つかりません。

 

このことはphp.iniのファイルの中にも説明されていることです。

; Note : The syntax used in previous PHP versions (‘extension=<ext>.so’ and
; ‘extension=’php_<ext>.dll’) is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new (‘extension=<ext>) syntax.

<ext>.soやphp_<ext>.dllという表示形式が昔の表示形式であるということが説明されています。この部分についてphpの公式ドキュメントの方ではこのように説明しています。

拡張モジュールの読み込み ¶
PHP の拡張モジュールを読み込む方法として最も一般的なのは、設定ファイル php.ini に書き込むことです。多くの拡張モジュールはすでに php.ini 上に存在し、 あとはセミコロンを取り除くだけで有効にできるようになっています。

Note that, on PHP version 7.2.0 and up, the extension name may be used instead of the extension’s file name. As this is OS-independent and easier, especially for newcomers, it becomes the recommended way of specifying extensions to load. File names remain supported for compatibility with prior versions.

;extension=php_extname.dll
extension=php_extname.dll
; PHP バージョン 7.2 以降では、下記が良いでしょう。
extension=extname
zend_extension=another_extension

PHP: PHP 拡張モジュールの Windows へのインストール - Manual

どうやらphp7.2以降から表示形式が変わったみたいですね。私はこの情報を知らずに、cakephpの公式サイトのインストール方法のページが書かれているとおり、「extension=php_intl.dll」という項目を探しても、全く見つからず、その事実に気づくまでに多少の時間を要してしまいました。初めからphp.iniの説明コメント部分を読んだり、公式ドキュメントを参照すればよかったと考えます。;;

;extension=intlの;セミコロンをコメントアウトしたら、サーバを再起動したら設定は完了です。

 

コメント

タイトルとURLをコピーしました