それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

LaravelのPHPStorm/IntelliJ IDEA でphpのデバッグ(xdebug)をビルトインサーバーで行う

#

LaravelのPHPStorm/IntelliJ IDEA でphpデバッグ(xdebug)をビルトインサーバーで行う

laravel をxdebugデバッグする、やり方はいっぱいある。

いっぱいあるのに、ネットに情報が殆どないので。さすがphper といったところか

Xdebugデバッグをする。

alias server='php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 \
-dxdebug.remote_host=localhost -dxdebug.remote_port=9000 \
-dxdebug.remote_log=/tmp/xdebug.log -S localhost:8080 -t  public/'

いろいろ調べてみたら

artisan serve

このサーバー起動で用いられているコマンドの中身を見てみたら次のようになっていた。

SeverCommand.php ( 一部抜粋

<?php
class ServeCommand extends Command
{
    protected $name = 'serve';

    public function handle()
    {
        chdir(public_path());
        $this->line("<info>Laravel development server started:</info> <http://{$this->host()}:{$this->port()}>");

        passthru($this->serverCommand());
    }
    protected function serverCommand()
    {
        return sprintf('%s -S %s:%s %s/server.php',
            ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)),
            $this->host(),
            $this->port(),
            ProcessUtils::escapeArgument(base_path())
        );
    }
}

サーバー起動にpassthru って嫌な予感しか無い。

artisan サーバーには ini を渡せない。

php php -d name=value で設定を渡す機能があるが、 artisan serve は何を血迷った実装なのか、内部的に'/usr/bin/php server.php'を直接起動するラッパーに過ぎない。所詮 PHPer ってことですよね・・・

そこで解決策として、このページの最初に記載したとおり、 自分で php を 叩くしか無いのです。