Vagrant上のUbuntu14.04にCakePHPをインストールする(準備編)

2020年10月10日

mod_rewriteを有効にする

CakePHPの公式を見るとApache2でmod_rewriteを有効にすることが推奨されるとのことなので早速やってみる。

まずはmod_rewriteが利用可能となっているかを確認する。

cat /etc/apache2/mods-available/rewrite.load

とコマンドを打つと

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

と表示された。
モジュールは使える状態みたいです。
有効化してみよう。

sudo a2enmod rewrite

コマンドを打つと以下が表示された。

Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart

service apache2 restartしてくれと言われたので

sudo service apache2 restart

これで完了。

PHP 5.6.0 以上 (PHP 7.1 も含む)にする

前回の記事でPHPのバージョンをアップした。

mbstring PHP 拡張

PHP7用のmbstringをインストール。

sudo apt-get install php7.0-mbstring

php.iniを編集する

cd /etc/php/7.0/apache2
sudo vim php.ini

Dynamic Extensions の欄に extention=mbstring.so を追記

extention=mbstring.so

Vimで

/mbstring

と打つと検索できるので[mbstring]の欄まで移動する。

[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; http://php.net/mbstring.language
mbstring.language = Japanese ← コメント解除
; Use of this INI entry is deprecated, use global internal_encoding instead.
; internal/script encoding.
; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
; The precedence is: default_charset < internal_encoding < iconv.internal_encoding
mbstring.internal_encoding = UTF-8 ← コメント解除&UTF-8に設定
; Use of this INI entry is deprecated, use global input_encoding instead.
; http input encoding.
; mbstring.encoding_traslation = On is needed to use this setting.
; If empty, default_charset or input_encoding or mbstring.input is used.
; The precedence is: default_charset < intput_encoding < mbsting.http_input
; http://php.net/mbstring.http-input
mbstring.http_input = auto ← コメント解除&autoに設定
; Use of this INI entry is deprecated, use global output_encoding instead.
; http output encoding.
; mb_output_handler must be registered as output buffer to function.
; If empty, default_charset or output_encoding or mbstring.http_output is used.
; The precedence is: default_charset < output_encoding < mbstring.http_output
; To use an output encoding conversion, mbstring's output handler must be set
; otherwise output encoding conversion cannot be performed.
; http://php.net/mbstring.http-output
mbstring.http_output = UTF-8 ← コメント解除&UTF-8に設定
; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
;       portable libs/applications.
; http://php.net/mbstring.encoding-translation
mbstring.encoding_translation = On ← コメント解除&Onに。
; automatic encoding detection order.
; "auto" detect order is changed according to mbstring.language
; http://php.net/mbstring.detect-order
mbstring.detect_order = auto ← コメント解除
; substitute_character used when character cannot be converted
; one from another
; http://php.net/mbstring.substitute-character
;mbstring.substitute_character = none
; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
; http://php.net/mbstring.func-overload
;mbstring.func_overload = 0
; enable strict encoding detection.
; Default: Off
;mbstring.strict_detection = On
; This directive specifies the regex pattern of content types for which mb_output_handler()
; is activated.
; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml\+xml)
;mbstring.http_output_conv_mimetype=

あとの設定はよくわからないので放置。

設定が終わったら必ずapache再起動。

sudo service apache2 restart
<?php
print_r(mb_get_info());
?>

と書いただけのphp_check.phpを作成する。
ブラウザからphp_check.phpを見てみる。

Array (
[internal_encoding] => UTF-8
[http_output] => UTF-8
[http_output_conv_mimetypes] => ^(text/|application/xhtml\+xml)
[func_overload] => 0
[func_overload_list] => no overload
[mail_charset] => ISO-2022-JP
[mail_header_encoding] => BASE64
[mail_body_encoding] => 7bit
[illegal_chars] => 0
[encoding_translation] => On
[language] => Japanese
[detect_order] => Array ( [0] => ASCII [1] => JIS [2] => UTF-8 [3] => EUC-JP [4] => SJIS )
[substitute_character] => 63
[strict_detection] => Off )

このように表示された。php-mbstring の導入は完了。
ここまでやったあとに、
どうやら

sudo apt-get install php7.0-intl php7.0-mbstring

で一発解決できるみたい。

intl PHP 拡張

上に書いた一発解決のやり方でインストール。

sudo apt-get install php7.0-intl

何故かaptからインストールするとphp.iniにextension=を記述しなくても使えるらしい。
ココらへんはよくわからず。

simplexml PHP 拡張

公式サイトを見ると、デフォルトで有効になっているとのこと。

これで準備が完了した。

CakePHP, Linux, MySQL, PHP

Posted by bistro