質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

解決済

2回答

7813閲覧

WSL + vscodeでPHPのデバッグがしたい。

nullbot

総合スコア910

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

1クリップ

投稿2018/03/08 04:22

編集2018/03/08 05:55

WSL上にLAMP環境を入れてwindows側のvscodeよりデバッグをしたいのですが、ブレークポイントを設定してブラウザよりアクセスしてもブレークしません。
どこか設定のミスが有ると思うのですが、お知恵を拝借願います。

###ubuntu側

  • PHP7.1を導入済み。下記にphpinfoで表示したxdebug部分を記します。
  • codeigniterのソースコードを/mnt/c/Users/nullbot/ubuntu/www/apps 以下に配置ついでに/home/nullbot/ubuntu -> /mnt/c/Users/nullbot/ubuntu とシンボリックリンク作成
  • virtualhostでapps.mydomainとしてアクセスできるように設定
  • /etc/hostsに上記をドメインを追記
DirectiveLocal ValueMaster Value
xdebug.auto_traceOffOff
xdebug.cli_color00
xdebug.collect_assignmentsOffOff
xdebug.collect_includesOnOn
xdebug.collect_params00
xdebug.collect_returnOffOff
xdebug.collect_varsOffOff
xdebug.coverage_enableOnOn
xdebug.default_enableOnOn
xdebug.dump.COOKIEno valueno value
xdebug.dump.ENVno valueno value
xdebug.dump.FILESno valueno value
xdebug.dump.GETno valueno value
xdebug.dump.POSTno valueno value
xdebug.dump.REQUESTno valueno value
xdebug.dump.SERVERno valueno value
xdebug.dump.SESSIONno valueno value
xdebug.dump_globalsOnOn
xdebug.dump_onceOnOn
xdebug.dump_undefinedOffOff
xdebug.extended_infoOnOn
xdebug.file_link_formatno valueno value
xdebug.filename_formatno valueno value
xdebug.force_display_errorsOffOff
xdebug.force_error_reporting00
xdebug.gc_stats_enableOffOff
xdebug.gc_stats_output_dir/tmp/tmp
xdebug.gc_stats_output_namegcstats.%pgcstats.%p
xdebug.halt_level00
xdebug.idekeyListen for XDebugListen for XDebug
xdebug.max_nesting_level256256
xdebug.max_stack_frames-1-1
xdebug.overload_var_dump22
xdebug.profiler_aggregateOffOff
xdebug.profiler_appendOffOff
xdebug.profiler_enableOnOn
xdebug.profiler_enable_triggerOffOff
xdebug.profiler_enable_trigger_valueno valueno value
xdebug.profiler_output_dir/var/log/xdebug/var/log/xdebug
xdebug.profiler_output_namecachegrind.out.%pcachegrind.out.%p
xdebug.remote_addr_headerno valueno value
xdebug.remote_autostartOnOn
xdebug.remote_connect_backOffOff
xdebug.remote_cookie_expire_time36003600
xdebug.remote_enableOnOn
xdebug.remote_handlerdbgpdbgp
xdebug.remote_hostapps.mydomainapps.mydomain
xdebug.remote_log/var/log/xdebug/var/log/xdebug
xdebug.remote_modereqreq
xdebug.remote_port90009000
xdebug.remote_timeout200200
xdebug.screamOffOff
xdebug.show_error_traceOffOff
xdebug.show_exception_traceOffOff
xdebug.show_local_varsOffOff
xdebug.show_mem_deltaOffOff
xdebug.trace_enable_triggerOffOff
xdebug.trace_enable_trigger_valueno valueno value
xdebug.trace_format00
xdebug.trace_options00
xdebug.trace_output_dir/tmp/tmp
xdebug.trace_output_nametrace.%ctrace.%c
xdebug.var_display_max_children128128
xdebug.var_display_max_data512512
xdebug.var_display_max_depth33

###windows側

  • c:\windows\system32\drivers\hostsを編集
  • vscodeをインストール
  • PHP debugをインストール
  • C:\Users\nullbot\ubuntu/www/appsをvscodeで開く

launch.jsonは以下の通り

{ // IntelliSense を使用して利用可能な属性を学べます。 // 既存の属性の説明をホバーして表示します。 // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9000, "serverSourceRoot": "/home/nullbot/ubuntu/www/apps", "localSourceRoot": "${workspaceRoot}", } ] }

/var/log/xdebug にはログは出力されていませんでした。9000番ポートが開いてないかと思い、9010番に変更しましたが駄目。コマンドプロンプト, WSL上でnetcatを使った疎通では通信できていました。

##追記
launch.jsonに"log":trueを加えてログを出しました。

<- launchResponse Response { seq: 0, type: 'response', request_seq: 2, command: 'launch', success: true } new connection 1 <- threadEvent ThreadEvent { seq: 0, type: 'event', event: 'thread', body: { reason: 'started', threadId: 1 } } <- initializedEvent InitializedEvent { seq: 0, type: 'event', event: 'initialized' } -> threadsRequest { command: 'threads', type: 'request', seq: 3 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 3, command: 'threads', success: true, body: { threads: [ Thread { id: 1, name: 'Request 1 (14:50:12)' } ] } } -> setBreakpointsRequest { command: 'setBreakpoints', arguments: { source: { name: 'Reserve.php', path: 'c:\Users\nullbot\ubuntu\www\apps\application\modules\admin\controllers\Reserve.php' }, lines: [ 16 ], breakpoints: [ { line: 16 } ], sourceModified: false }, type: 'request', seq: 4 } <- setBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 4, command: 'setBreakpoints', success: true, body: { breakpoints: [ { verified: true, line: 16 } ] } } -> setFunctionBreakpointsRequest { command: 'setFunctionBreakpoints', arguments: { breakpoints: [] }, type: 'request', seq: 5 } <- setFunctionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 5, command: 'setFunctionBreakpoints', success: true, body: { breakpoints: [] } } -> setExceptionBreakpointsRequest { command: 'setExceptionBreakpoints', arguments: { filters: [] }, type: 'request', seq: 6 } <- setExceptionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 6, command: 'setExceptionBreakpoints', success: true } -> configurationDoneRequest { command: 'configurationDone', type: 'request', seq: 7 } -> threadsRequest { command: 'threads', type: 'request', seq: 8 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 8, command: 'threads', success: true, body: { threads: [ Thread { id: 1, name: 'Request 1 (14:50:12)' } ] } } <- configurationDoneResponse Response { seq: 0, type: 'response', request_seq: 7, command: 'configurationDone', success: true } <- threadEvent ThreadEvent { seq: 0, type: 'event', event: 'thread', body: { reason: 'exited', threadId: 1 } } new connection 2 <- threadEvent ThreadEvent { seq: 0, type: 'event', event: 'thread', body: { reason: 'started', threadId: 2 } } <- initializedEvent InitializedEvent { seq: 0, type: 'event', event: 'initialized' } -> threadsRequest { command: 'threads', type: 'request', seq: 9 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 9, command: 'threads', success: true, body: { threads: [ Thread { id: 2, name: 'Request 2 (14:50:12)' } ] } } -> setBreakpointsRequest { command: 'setBreakpoints', arguments: { source: { name: 'Reserve.php', path: 'c:\Users\nullbot\ubuntu\www\apps\application\modules\admin\controllers\Reserve.php' }, lines: [ 16 ], breakpoints: [ { line: 16 } ], sourceModified: false }, type: 'request', seq: 10 } <- setBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 10, command: 'setBreakpoints', success: true, body: { breakpoints: [ { verified: true, line: 16 } ] } } -> setFunctionBreakpointsRequest { command: 'setFunctionBreakpoints', arguments: { breakpoints: [] }, type: 'request', seq: 11 } <- setFunctionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 11, command: 'setFunctionBreakpoints', success: true, body: { breakpoints: [] } } -> setExceptionBreakpointsRequest { command: 'setExceptionBreakpoints', arguments: { filters: [] }, type: 'request', seq: 12 } <- setExceptionBreakpointsResponse Response { seq: 0, type: 'response', request_seq: 12, command: 'setExceptionBreakpoints', success: true } -> configurationDoneRequest { command: 'configurationDone', type: 'request', seq: 13 } -> threadsRequest { command: 'threads', type: 'request', seq: 14 } <- threadsResponse Response { seq: 0, type: 'response', request_seq: 14, command: 'threads', success: true, body: { threads: [ Thread { id: 2, name: 'Request 2 (14:50:12)' } ] } } <- configurationDoneResponse Response { seq: 0, type: 'response', request_seq: 13, command: 'configurationDone', success: true } <- threadEvent ThreadEvent { seq: 0, type: 'event', event: 'thread', body: { reason: 'exited', threadId: 2 } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

unz.hori

2018/03/08 04:30

私の場合は、"serverSourceRoot"/"localSourceRoot"はコメントアウトして、"pathMappings"を設定してますがちゃんとブレークポイントで止まってくれますね。
unz.hori

2018/03/08 04:32

"pathMappings": { "/var/share/hogehoge" : "${workspaceRoot}" }てな感じです。
nullbot

2018/03/08 05:07

ありがとうございます。警告に'Property serverSourceRoot is deprecated, please use pathMappings to define a server root.'と出ていたのでpathMappingsに変更しました。ただしまだ問題は解決していません。
unz.hori

2018/03/08 07:47

初歩的な事の確認ですが、デバッグの開始は実行しているんですよね?
nullbot

2018/03/08 08:00

はい。vscode側のログを見る限りDBGPでの通信は始まってるように見えます。xdebug側のログが出力されていないのは理由がわかりません。
unz.hori

2018/03/08 08:41 編集

ちょっと私のlaunch.jsonを回答に貼ってみますね。pathは修正しますけど。
guest

回答2

0

自己解決

結論から言うとwindows側のポートが空いていないことが原因でした。(※ログでレスポンスが返ってきているように見えたのは不明)
DBGpはブラウザからリクエストされたあとにxdebug側からIDEに対してコネクションを張るのでIDE側が待ち受けている必要があります。

但しデバッグは完璧ではなくブレークがされて変数などの状態は見れますが、vscodeで以下のようなメッセージが表示されています。

'Reserve.php' を開くことができません: ファイルが見つかりません (file:///mnt/c/Users/nullbot/ubuntu/www/apps/application/modules/admin/controllers/Reserve.php)。

DrvFsが悪さをしているのかわかりませんが、これについては別途質問をさせていただきます。

ちなみにxdebugのログが出力されないと言っていた件は、 /var/log/xdebugがディレクトリがあったからでした。/var/log/xdebug/remote_logを指定することでログが取得できました。

参考
https://xdebug.org/docs/remote
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug

投稿2018/03/09 00:53

nullbot

総合スコア910

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

一応、参考に私のlaunch.jsonを貼りますので参考にしてください。
※."name": "Launch currentry open script"の方で繋がっている気がします。

json

1 "version": "0.2.0", 2 "configurations": [ 3 { 4 "name": "Listen for XDebug", 5 "type": "php", 6 "request": "launch", 7 "port": 9200, 8 "pathMappings": { 9 "/var/share/hogehoge" : "${workspaceRoot}" 10 } 11// "serverSourceRoot": "/var/nginx/hogehoge", 12// "localSourceRoot": "${workspaceRoot}" 13 }, 14 { 15 "name": "Launch currently open script", 16 "type": "php", 17 "request": "launch", 18 "program": "${file}", 19 "cwd": "${fileDirname}", 20 "port": 9000 21 } 22 ]

投稿2018/03/08 08:15

編集2018/03/08 08:40
unz.hori

総合スコア1057

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

unz.hori

2018/03/08 08:25

ちなみに私の環境について補足ですが、VirtualBoxにCentOS6をインストールしてsambaも入れてそれをWindows7(RealOS)のVisualStdio Codeからデバッグしている状態です。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問