開発に携わってからまだ浅く、分かりづらい点等あるかと思いますがご承知おきください。
###前提・実現したいこと
- ・XAMPP 5.6.30
- ・CAKEPHP 3.5
現在ローカル環境で開発を進めていますが、CAKEPHP3のディレクトリ構成を変更したいです。
webrootをドキュメントルートへ移したいのです。
###手順
>>CakePHP3 をドキュメントルート外にインストールする
こちらの記事を参考に、
1. webroot下のファイルをドキュメントルートへ
- htdocs/hoge/public/[webroot] ドキュメントルート
- htdocs/hoge/app/[cake]
2. index.phpを編集
php
1// htdocs/hoge/public/index.php 2 3//cakeへのパス 4 $cakeRoot = realpath(dirname(__FILE__) . '/../app/[cake]'); 5 6 7/************************************ 8 * それぞれcakeへのパスを修正 9 * コメントアウトが元の記述 10************************************/ 11//require dirname(__DIR__) . '/config/requirements.php'; 12require $cakeRoot . '/config/requirements.php'; 13 14//require dirname(__DIR__) . '/vendor/autoload.php'; 15require $cakeRoot . '/vendor/autoload.php'; 16 17//$server = new Server(new Application(dirname(__DIR__) . '/config')); 18$server = new Server(new Application( $cakeRoot . '/config'));
php
1// htdocs/hoge/app/[cake]/index.php 2 3// require 'webroot' . DIRECTORY_SEPARATOR . 'index.php'; 4require '../../public' . DIRECTORY_SEPARATOR . 'index.php';
この手順でcake本体からwebrootを切り出してドキュメントルートへ設置しました。
が、localhost/hoge/[コントローラ名]/[アクション名]にアクセスすると下記の500エラーになり先へ進みません。
###その他試したこと
.htaccessにRewriteBaseを追記するという方法が出ていたので下記のように試しました。
plain
1/******************************* 2 * htdocs/hoge/public/.htaccess 3 *******************************/ 4<IfModule mod_rewrite.c> 5 RewriteEngine On 6 RewriteBase / //追記 7 RewriteCond %{REQUEST_FILENAME} !-f 8 RewriteRule ^ index.php [L] 9</IfModule> 10 11 12/******************************* 13 *htdocs/hoge/app/[cake]/.htaccess 14 *******************************/ 15<IfModule mod_rewrite.c> 16 RewriteEngine on 17 RewriteBase / //追記 18 RewriteRule ^(.well-known/.*)$ $1 [L] 19 RewriteRule ^$ webroot/ [L] 20 RewriteRule (.*) webroot/$1 [L] 21</IfModule> 22 23
これだと500エラーはなくなりますが、404となりやはりアクセスできません。
どのようにすれば正常にデフォルト画面が表示されますか?
また、cake3に馴染みが薄いので私の解釈、認識が間違っていますでしょうか?
###エラーメッセージ
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at postmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 Server at localhost Port 80
回答2件
あなたの回答
tips
プレビュー