LoginSignup
0
4

More than 3 years have passed since last update.

WindowsのVSCodeでPHPのお手軽実行環境を構築

Last updated at Posted at 2020-02-05

Windows の VSCode で PHP のお手軽実行環境を構築

Windows10 の VSCode(git bash)で PHP7 のお手軽実行環境の構築手順です。
目的は PHP の勉強など、短いコードを書いてすぐ実行できるようにするためです。

PHP の設定

PHP をダウンロード

https://windows.php.net/download/
適当なバージョンのx64 Thread Safeのzipをダウンロードし好きなところに展開
今回は展開されたディレクトリ名をphpに変更してC:\php\のようにCドライブ直下に配置

Pathの追加

  1. コントロールパネル>システムとセキュリティ>システムでシステムの詳細設定を押下
  2. システムのプロパティが表示され、詳細設定タブを選択し、環境変数ボタンを押下
  3. ~のユーザー環境変数の変数: Pathを選択し編集ボタンを押下
  4. 環境変数名の編集が表示され、新規ボタンを押下し、C:\php\の追加

vscode の設定

VSCode の TERMINAL を Git Bash に変更する

この記事が参考になりました。感謝です。
WindowsのVSCodeでGit Bashをターミナルに設定する

導入拡張機能

Extensionsから下記の拡張機能をインストールする。
- PHP Intelephense
- Code Runner

settings.json 追記

Ctrl+Shift+pPreferences: Open Settings (json)を選択し下記を追記する。

"php.validate.executablePath": "C:\\php\\php-win.exe",
"php.executablePath": "C:\\php\\php-win.exe",
"php.suggest.basic": false,
"code-runner.executorMap": {
  "php": "/c/php/php"
},
// 出力先をTERMINALにする
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": true,

Code Runner で PHP のコードを実行

任意の PHP ファイルを開きCtrl+Alt+nで実行!
TERMINAL に結果が表示されたら完了です。

実行でエラーが出たとき

  • C:/php/php.exe: error while loading shared libraries: api-ms-win-crt-locale-l1-1-0.dll: cannot open shared object file: No such file or directory
    https://www.microsoft.com/ja-jp/download/confirmation.aspx?id=48145
    ダウンロードしたものを実行してインストール

  • PHP Warning: 'vcruntime140.dll' 14.0 is not compatible with this PHP build linked with 14.16 in Unknown on line 0
    https://visualstudio.microsoft.com/ja/downloads/
    「Visual Studio 2019 の Microsoft Visual C++ 再頒布可能パッケージ」のx64を選択しダウンロード
    ダウンロードしたものを実行してインストール

0
4
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
4