0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPでHTTP ERROR 500にハマった時の解決策

0
Posted at

この記事について

CakePHPでHTTP ERROR 500 This page isn't workingのエラーにハマり苦しんだので、自分が見つけた解決策をここに記述しています。
解決策を調べると、.htaccessの記述が違うだとか、File Permissionがおかしい等の指摘ばかりですが、CakePHPやその他のフレームワークを使用している場合、そもそも違ったところに原因があるかもしれません。
以下に、解消原因とその解決策の一例を示します。

image.png

原因

自分の場合、CakePHPを見に行く際にロードされるApplication.phpが原因でした。
もう少し言うと、以前にCakePHPに追加したPluginのaddPluginの記述をbootstrap()メゾットの頭に記述していたものの、そこでエラーが発生していたのが原因。

    public function bootstrap()
    {
        // ここにaddPluginを記述するとHTTP ERROR 500に落ちる
        $this->addPlugin('SoftDelete');

        // Call parent to load bootstrap from files.
        parent::bootstrap();

        if (PHP_SAPI === 'cli') {
            $this->bootstrapCli();
        }

        /*
         * Only try to load DebugKit in development mode
         * Debug Kit should not be installed on a production system
         */
        if (Configure::read('debug')) {
            $this->addPlugin(\DebugKit\Plugin::class);
        }
    }

修正

    public function bootstrap()
    {

        // Call parent to load bootstrap from files.
        parent::bootstrap();

        if (PHP_SAPI === 'cli') {
            $this->bootstrapCli();
        }

        /*
         * Only try to load DebugKit in development mode
         * Debug Kit should not be installed on a production system
         */
        if (Configure::read('debug')) {
            $this->addPlugin(\DebugKit\Plugin::class);
        }
        // addPluginをメゾットの最後に書く
        $this->addPlugin('SoftDelete');
    }

結果

以下のスクショのように、CakePHPのDebugモードが起動されていることがわかる。
あとはメッセージに沿って問題を解消すればいい。
image.png

最後に

ネットにある情報は日英両方とも探して試しましたが、解決できませんでした。
OSの設定やAppacheがおかしいのかと疑っていましたが、自分でまずデフォルトのDBに繋がっていないCakePHPを作成したところ、普通に見れたので一気に解決に繋がりました。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?