# yum list \*xdebug\* # yum install php-pecl-xdebug.i386
# dnf install php php-devel php-pear # pecl install xdebug PHP 7.2-7.4 の場合 # pecl install xdebug-3.1.6 # vi /etc/php.d/user.ini +zend_extension=/usr/lib64/php/modules/xdebug.so
# mkdir /php-xdebug # chown apache /php-xdebug
Linux の例
php_flag xdebug.profiler_enable 1 php_value xdebug.profiler_output_dir "/php-xdebug" php_flag xdebug.profiler_append 0 php_value xdebug.profiler_output_name "cachegrind.out.%u_%R"
Windows の場合、xdebug.profiler_output_dir を以下要領で変える。
php_value xdebug.profiler_output_dir "C:\app\php-52-ts\xdebug"
実際に動作した設定。
xdebug.remote_enable = on xdebug.remote_autostart = on xdebug.remote_port = 9003
Context: server config, virtual host
なので、.htaccess では設定できないと考えられる。(他の回避方法があるか不明。)実際に動作した設定。
php_flag xdebug.remote_enable on php_flag xdebug.remote_autostart on xdebug.remote_port = 9003
「PHP 5.4 (Xdebug 2.2.7) (FCGI)」同様の設定で動作した。(/etc/php.d/*.ini に記述した。)
実際に動作した設定。
# xdebug.client_host = "localhost" # xdebug.client_port=9003 xdebug.mode=develop,debug
xdebug.client_host
と xdebug.client_port
は、デフォルト値なので不要そう。xdebug.start_with_request=yes
php_value xdebug.start_with_request yes
xdebug.mode
xdebug.start_with_request
通常との差異。
php.ini
xdebug.client_host = host.docker.internal
.vscode/launch.json
{ "configurations": [ { "pathMappings": { "/var/www/app": "${workspaceRoot}", }, }, ], }
xdebug.remote_autostart や xdebug.start_with_request を使わずデバッグする方法。その方が、多分安全。
例
$ XDEBUG_SESSION=1 ./foo.php # sudo -u apache XDEBUG_SESSION=1 ./foo.php $ docker compose exec -T -e XDEBUG_SESSION=1 <サービス名> php
.user.ini ; for xdebug 2 xdebug.remote_enable = ${PHPFPM_xdebug_remote_enable} xdebug.remote_autostart = ${PHPFPM_xdebug_remote_autostart} ; for xdebug 3 xdebug.start_with_request = ${PHPFPM_xdebug_start_with_request} .htaccess # 開発サイト # - 別名によるブレを回避するため HTTP_HOST を使わず、SERVER_NAME を使っている。(効果未検証) <If "%{SERVER_NAME} =~ /^dev\./"> SetEnv PHPFPM_xdebug_remote_enable on SetEnv PHPFPM_xdebug_remote_autostart on SetEnv PHPFPM_xdebug_start_with_request yes </If> # 本番サイト <Else> SetEnv PHPFPM_xdebug_remote_enable off SetEnv PHPFPM_xdebug_remote_autostart off SetEnv PHPFPM_xdebug_start_with_request no </Else>