参考にさせて頂いたページ
Vagrantで設定を進める、CakePHP編 - Qiita
VagrantでCakePHPを動かそうとした際に躓いたこと - Qiita
まずはcakephpのzipをダウンロード
CakePHP: 高速開発 php フレームワーク。 Homeからcakephp-2.5.6.zip
をダウンロードした。
zipファイルを解凍して配置する
解凍するとcakephp-2.5.6
というフォルダになる。
それをcakephp
にフォルダ名を変更する。
次にそのcakephp
フォルダを仮想環境に同期してるディレクトリに配置する。
./example/cakephp/*
みたいなディレクトリ構造にした。
http://192.168.33.10/cakephp/index.phpにブラウザでアクセスしてみる
Warning: _cake_core_ cache was unable to write 'cake_dev_ja' to File cache in /vagrant/lib/Cake/Cache/Cache.php on line 323
Warning: /vagrant/app/tmp/cache/persistent/ is not writable in /vagrant/lib/Cake/Cache/Engine/FileEngine.php on line 385
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /vagrant/lib/Cake/Cache/Cache.php:181
Stack trace:
#0 /vagrant/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')
#1 /vagrant/app/Config/core.php(374): Cache::config('_cake_core_', Array)
#2 /vagrant/lib/Cake/Core/Configure.php(72): include('/vagrant/app/Co...')
#3 /vagrant/lib/Cake/bootstrap.php(175): Configure::bootstrap(true)
#4 /vagrant/app/webroot/index.php(94): include('/vagrant/lib/Ca...')
#5 /vagrant/index.php(41): require('/vagrant/app/we...')
#6 {main} thrown in /vagrant/lib/Cake/Cache/Cache.php on line 181
みたいな感じで表示された。
Fatal errorを先に解消する
VagrantでCakePHPを動かそうとした際に躓いたこと - Qiitaによるとapp/tmp
のパーミッション設定が原因らしい。
Vagrantfileの
config.vm.synced_folder "./example", "/vagrant"
となっている行に、
, owner: 'vagrant', group: 'apache', mount_options: ['dmode=777', 'fmode=666']
と追記して、
config.vm.synced_folder "./example", "/vagrant", owner: 'vagrant', group: 'apache', mount_options: ['dmode=777', 'fmode=666']
として保存。
vagrant reload
を実行して、Vagrantfileの設定を反映する。
次にhttp://192.168.33.10/cakephp/index.phpにアクセスすると、ちょっとcakephpらしいエラー画面になった。
vagrantは仮想環境内にログインして、コマンドでパーミッション変更しても上手くいかないらしい。
実際のサーバーでは、コマンドでパーミッション変更しましょう。
cssが読み込めていないようなので直す(apacheの設定変更)
Vagrantで設定を進める、CakePHP編 - Qiitaを参考に進めていく
とりあえず
vagrant ssh
su
vagrant(パスワード)
でログイン
vim /etc/httpd/conf/httpd.conf
でhttpd.confを開く。
30%あたりの位置に、
<Directory "/var/www/html">
となっている行が既にあるのでその内側を編集する。
具体的には
AllowOverride None
となっているところを
AllowOverride All
とした
DocumentRoot "/var/www/html"
という記述は28%あたりにあるけど、編集の必要は無いのでそのままにしておく。
httpd.confを保存して終了。
httpd.confの編集を反映するために、apacheを再起動
/etc/init.d/httpd restart
を実行すると
httpd を停止中: [ OK ]
httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
みたいに表示されて、再起動完了。
ブラウザで再度確認
http://192.168.33.10/cakephp/index.phpをブラウザで確認すると、cssが読み込まれるようになっている。
これでようやくcakephpが使えそうな感じになってきた。
AllowOverrideについて
Apacheによると、
今回の場合/var/www/html
ディレクトリ以下に配置した設定ファイルによる、設定の上書きがNone(許可しない)
だったのをAll(全て許可する)
に変更したみたい。
今の段階での表示
以下の画像のようになっているので、赤と黄色の部分を次回解決していこうと思う。
今回はここまで。