環境
- XSERVER
- PHP 7.4.28 / cakephp4.2.8(XSERVERの環境)
実現したいこと
ローカルで開発したサービスをXSERVERで表示したい
エラー内容
画面に「An Internal Server Error Occurred」だけが表示される
経緯
-
リリース手順としてこちらの通りに、ディレクトリ構成とパスを変更しました
-
「Parse error: syntax error, unexpected 'require' (T_REQUIRE)」エラーが出ましたが、解消できず、一旦こちらを参考に「dirname(DIR) . $cakeDir」の記述を「/home/{xserverのID}/{ドメイン}/cakephp」に置き換えました
-
画面に「An Internal Server Error Occurred」だけが表示されました
試したこと
DBの設定を確認しました。
DBの設定が正しいか確認するため、このドメインのpublic_html下にcakephp4をインストールし、DB情報を編集し、初期画面でDBが正常に接続されていることを確認しました。
その他に、検索で出てくるいくつかのやりかやでディレクトリ構成を変えてサービスをアップしてみましたが同じように最後には「An Internal Server Error Occurred」でつまずき先に進めませんでした。。
ググってもあまり情報がヒットせず全くわからなくなってしまいました。。
ディレクトリ構成
ドメイン名のフォルダ ├ public_html/ ・・・webrootの中身 │ ├index.php │ ├ img │ ├ css/ │ ... │ └ .htaccess ├cakephp/ ・・・webroot以外のcakephp4ファイル群 │ ├ bin/ │ ├ config/ │ ├ src/ │ ... │ └ vender ├xserver_php/ │ └
cakephp/config/app.php
'App' => [ 'namespace' => 'App', 'encoding' => env('APP_ENCODING', 'UTF-8'), 'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'), 'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'), 'base' => false, 'dir' => 'src', //'webroot' => 'webroot', 'webroot' => 'public_html', // エックスサーバーの公開ディレクトリに修正 'wwwRoot' => WWW_ROOT, ..... 'Datasources' => [ 'default' => [ 'className' => Connection::class, 'driver' => Mysql::class, 'persistent' => false, 'host' => 'mysql****.xserver.jp', 'username' => 'xs****_ユーザー名', 'password' => 'ユーザー名に対するユーザーパスワード', 'database' => 'xs****_DB名', 'encoding' => 'utf8', 'timezone' => 'UTC', .....
cakephp/config/paths.php
//define('WWW_ROOT', ROOT . DS . 'webroot' . DS); define('WWW_ROOT', 'home/xs*****/ドメイン' . DS . 'public_html' . DS); //エックスサーバーの公開 ディレクトリに修正
public_html/index.php
// Check platform requirements //require dirname(__DIR__) . '/config/requirements.php'; require '/home/xs*****/ドメイン/cakephp/config/requirements.php'; // 修正 // For built-in server if (PHP_SAPI === 'cli-server') { $_SERVER['PHP_SELF'] = '/' . basename(__FILE__); $url = parse_url(urldecode($_SERVER['REQUEST_URI'])); $file = __DIR__ . $url['path']; if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) { return false; } } //require dirname(__DIR__) . '/vendor/autoload.php'; require '/home/xs*****/ドメイン/cakephp/vendor/autoload.php'; // 修正 use App\Application; use Cake\Http\Server; // Bind your application to the server. //$server = new Server(new Application(dirname(__DIR__) . '/config')); $server = new Server(new Application('/home/xs*****/ドメイン/cakephp/config')); // 修正 // Run the request/response through the application and emit the response. $server->emit($server->run());
public_html/.htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
cakephp/.htaccess
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ ../public_html/ [L] RewriteRule (.*) ../public_html/$1 [L] </IfModule>
XSERVERの管理画面からダウンロードしたerror_log
[Sun Jul 10 19:33:00.468068 2022] [proxy_fcgi:error] [pid 3836:tid 3919] [client 153.214.78.6:34470] AH01071: Got error 'PHP message: PHP Warning: file_put_contents(/home/xs*****/ドメイン/cakephp/logs/error.log) [<a href='https://secure.php.net/function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/xs*****/ドメイン/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 131PHP message: PHP Warning: file_put_contents(/home/xs*****/ドメイン/cakephp/logs/error.log) [<a href='https://secure.php.net/function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in /home/xs*****/ドメイン/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 131'
エラーログも見ましたが分からず、ブラウザに表示されているエラーとは別問題かと思い、DB周りの方を確認してました(もしかしたらここが原因かもしれないですがすみません、わかりませんでした。。)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/11 08:15