この記事はだいたい 4 分ほどで読めます。
VSCode で PHP をいじりたくて XAMPP のインストールと初期設定を行った際の備忘録です。
![programing](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/code-1076536_1920-1024x575.jpg)
目次
環境
- PC:Windows10
- XAMPP:7.4.6
XAMPP セットアップ
ダウンロード
![XAMPP download](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/a2b2c087228ce32acd641172d9928de5.png)
ブラウザで[XAMPP]で検索してダウンロードサイトからインストーラをダウンロード。
インストール
ダウンロードしたインストーラを起動します。
Warning
![XAMPP install1](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28.png)
Yesをクリック。
Warning
![XAMPP install2](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-1.png)
OKをクリック。
Setup – XAMPP
![XAMPP install3](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-2.png)
Nextをクリック。
Select Components
![XAMPP install4](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-3.png)
Nextをクリック。
Installation folder
![XAMPP install5](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-4.png)
インストール先を選択する画面です。
デフォルトはCドライブでした。
変更する場合はフォルダを選択します。
今回はDドライブに変更してNextをクリック。
Language
![XAMPP install6](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-5.png)
言語の選択画面です。
日本語とかなさそうなのでそのままNextをクリック。
Bitnami for XAMPP
![XAMPP install7](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-6.png)
Nextをクリックします。
ブラウザが開くけどとりあえずすぐ閉じる。
Installing
![XAMPP install8](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-8.png)
インストールが始まりました。
Completing the XAMPP Setup Wizard
![XAMPP install9](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-9.png)
インストール完了です。
チェックボックスを付けたままFinishをクリックするとコントロールパネルが起動します。
起動
インストールディレクトリ(今回の場合は D:\xampp\ )の[xampp-control.exe]をダブルクリックします。
※インストール時に立ち上げるかどうか聞いてくるので立ち上げるを選択すると勝手に立ち上がる。
XAMPP Control Panel
![XAMPP Contrl Panel](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/2020-05-28-11.png)
ApacheとMySQLを起動します。
StartボタンをクリックしてModule部分が緑になってPIDとPortに値が入ればOK。。かな
動作確認
Apache,PHP,MySQL がそれぞれ動いてるか phpMyAdmin を動かしてみます。
![browser](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/715101428e0faf6370f0884056d50165.png)
ブラウザのurlに localhost/phpmyadmin と入力。
phpMyAdmin が起動するのでデータベースを作成してみます。
![phpmyadmin1](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/dcaf446422f2f8ff38af19f8e91d29e7.png)
[データベース]タブをクリックしてテキストボックスに適当な名前を入力して作成をクリック。
![phpmyadmin2](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/d24b90b2177adaa2a8f5d732a1d84656.png)
新しいテーブルができました。
Apache,PHP,MySQLがそれぞれ動いているようです。
ルートディレクトリに適当なファイルを作成して動かしてみます。
![vscode1](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/d558fd1e860bd9340d2cdbc6bacafe46-1024x766.png)
D:\xampp\htdocsに phplessons というフォルダを作成し index.php ファイルを作成
ブラウザで確認。
![browser2](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/9dc8838c6e33ebb07f2ceb70cd6bfbd5.png)
表示されました。
次はHTMLファイルで確認してみます。
先ほど作成した index.php を削除します。
![vscode2](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/3cb95fd49293d012960aceb1d5da1d8f.png)
index.html を作成。
ブラウザで確認。
![browser3](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/b3ac1afded3db82fbbee49e6489d30d6-1024x364.png)
。。。表示されない。
PHP部分がコメントアウトされちゃってる。
htmlファイルでもPHP埋め込んで動くように設定を変更してみます。
httpd.confを編集
XAMPP Control Panelを開きます。
![](https://beanhouse.org/wordpress/wp-content/uploads/2020/07/f694f57b7de00b40f7f9883c646df555.png)
Apacheの[Config]ボタンをクリック。
さらに[Apache(httpd.conf)]をクリックします。
最終行に下記を追加して保存します。
AddType application/x-httpd-php .php .html
Apacheを再起動してもう一度確認します。
![browser4](https://beanhouse.org/wordpress/wp-content/uploads/2020/05/b92d14e0e341eab4bdf75d4822cb393f-1024x353.png)
表示されました。
htmlファイルにPHPを埋め込んで処理がされました。
感想
VSCode の PHP の拡張機能を試したくてローカル環境に XAMPP をセットアップしました。
インストーラ一発でローカル環境の構築がほぼほぼ完了できるってのは感動的です。
その昔、PHPを動かすのにIISと戦ったのはいい思い出です。
おわり。