{"id":167336,"date":"2018-11-16T14:37:56","date_gmt":"2018-11-16T07:37:56","guid":{"rendered":"https:\/\/www.icez.net\/blog\/?p=167336"},"modified":"2018-11-16T14:37:56","modified_gmt":"2018-11-16T07:37:56","slug":"0235-use-php-on-wsl-in-vscode","status":"publish","type":"post","link":"https:\/\/www.icez.net\/blog\/167336\/0235-use-php-on-wsl-in-vscode","title":{"rendered":"0235 | \u0e43\u0e0a\u0e49 php \u0e1a\u0e19 WSL \u0e01\u0e31\u0e1a VSCode"},"content":{"rendered":"<p>1) \u0e40\u0e1b\u0e34\u0e14 wsl \u0e02\u0e36\u0e49\u0e19\u0e21\u0e32 \u0e2a\u0e31\u0e48\u0e07 sudo vi \/usr\/local\/bin\/windows-php \u0e43\u0e2a\u0e48\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49<\/p>\n<pre lang=\"bash\">\n# Pass all the arguments to PHP.\noutput=$(php \"$@\")\n# Perform UNIX->WINDOWS syntax replacements.\noutput=\"${output\/\/$'\\n'\/$'\\r'$'\\n'}\"\noutput=\"${output\/\/\\\/mnt\\\/c\/C:}\"\noutput=\"${output\/\/\\\/\/\\\\}\"\n# Echo corrected output.\necho $output\n<\/pre>\n<p>2) \u0e2a\u0e31\u0e48\u0e07 sudo chmod +x \/usr\/local\/bin\/windows-php<br \/>\n3) \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c php.bat \u0e40\u0e01\u0e47\u0e1a\u0e44\u0e27\u0e49\u0e0b\u0e31\u0e01\u0e17\u0e35\u0e48\u0e43\u0e19\u0e1d\u0e31\u0e48\u0e07 windows (\u0e2a\u0e21\u0e21\u0e15\u0e34 c:\\apps\\php.bat) \u0e43\u0e2a\u0e48\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49<\/p>\n<pre lang=\"bat\">\n@echo off\n\nsetlocal ENABLEDELAYEDEXPANSION\n\nrem Collect the arguments and replace:\nrem  '\\' with '\/'\nrem  'c:' with 'mnt\/c'\nrem  '\"' with '\\\"'\nset v_params=%*\nset v_params=%v_params:\\=\/%\nset v_params=%v_params:C:=\/mnt\/c%\nset v_params=%v_params%\nset v_params=%v_params:\"=\\\"%\n\nrem Call the windows-php inside WSL.\nrem windows-php is just a script which passes the arguments onto\nrem the original php executable and converts its output from UNIX\nrem syntax to Windows syntax.\nC:\\Windows\\system32\\bash.exe -l -c \"windows-php %v_params%\"\n<\/pre>\n<p>4) \u0e43\u0e19 vscode \u0e15\u0e31\u0e49\u0e07 setting \u0e15\u0e32\u0e21\u0e19\u0e35\u0e49<\/p>\n<pre lang=\"javascript\">\n    \"php.validate.executablePath\": \"C:\\\\apps\\\\php.bat\"\n<\/pre>\n<p>reference: https:\/\/github.com\/Microsoft\/vscode\/issues\/22391<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1) \u0e40\u0e1b\u0e34\u0e14 wsl \u0e02\u0e36\u0e49\u0e19\u0e21\u0e32 \u0e2a\u0e31\u0e48\u0e07 sudo vi \/usr\/local\/bin\/windows-php \u0e43\u0e2a\u0e48\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49 # Pass all the arguments to PHP. output=$(php &#8220;$@&#8221;) # Perform UNIX->WINDOWS syntax replacements. output=&#8221;${output\/\/$&#8217;\\n&#8217;\/$&#8217;\\r&#8217;$&#8217;\\n&#8217;}&#8221; output=&#8221;${output\/\/\\\/mnt\\\/c\/C:}&#8221; output=&#8221;${output\/\/\\\/\/\\\\}&#8221; # Echo corrected output. echo $output 2) \u0e2a\u0e31\u0e48\u0e07 sudo chmod +x \/usr\/local\/bin\/windows-php 3) \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c php.bat \u0e40\u0e01\u0e47\u0e1a\u0e44\u0e27\u0e49\u0e0b\u0e31\u0e01\u0e17\u0e35\u0e48\u0e43\u0e19\u0e1d\u0e31\u0e48\u0e07 windows (\u0e2a\u0e21\u0e21\u0e15\u0e34 c:\\apps\\php.bat) \u0e43\u0e2a\u0e48\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49 @echo off setlocal ENABLEDELAYEDEXPANSION rem Collect the arguments and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,5,8],"tags":[],"class_list":["post-167336","post","type-post","status-publish","format-standard","hentry","category-linux","category-php","category-programming"],"_links":{"self":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/167336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/comments?post=167336"}],"version-history":[{"count":7,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/167336\/revisions"}],"predecessor-version":[{"id":167343,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/167336\/revisions\/167343"}],"wp:attachment":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/media?parent=167336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/categories?post=167336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/tags?post=167336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}