LoginSignup
2
2

More than 5 years have passed since last update.

VMFusionを使用しているWindowsからMacのMAMPに設定したVirtualHostにアクセスする方法

Posted at

はじめに

初投稿となります、よろしくお願いします。
私がMacで開発を行っている中で、どうしてもWindowsで確認する必要があったため、色々と調べたことを備忘録として書いています。
探せば情報はそれなりに出てくるのですが、色々と情報をつなぎあわせて試行錯誤していたので、どなたかのお役に立てればと思っています。

MacのMAMPでVirualHostを設定

httpd.confを編集します。

#Virtual hosts
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

# ↓ 「#」を外す

#Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

#Portの追加
Listen 88 #既存のPort
Listen 8000 #VMからアクセスするPort

httpd-vhosts.confを編集します。

# NameVirtualHostを追加
NameVirtualHost *:88
NameVirtualHost *:8000

#VirtualHostDirectiveの追加
<VirtualHost *:88>
    DocumentRoot "/Applications/MAMP/htdocs/example"
    ServerName example.com
</VirtualHost>
<VirtualHost *:8000>
    DocumentRoot "/Applications/MAMP/htdocs/example"
    ServerName example.com
</VirtualHost>

hostsを編集します。
hostsをTerminalで編集するのが面倒だったらhosterを使ってもいいかも。。
hostsの編集を行うにはターミナルから行う必要があります。

$ sudo vi /etc/hosts

新しい行に下記を追加

127.0.0.1 example.com

これでMac側の設定は完了です。

VMwareFusionの設定

ネットワークアダプタの設定をNATモードに変更します。
コマンドプロンプトを開いて、ipconfigコマンドで自分のIPv4アドレスを確認しておきます。

hostsファイルを編集します。
ファイルの場所は、C:\Windows\system32\drivers\etc\hostsとなります。
ファイルの最後に、

127.0.0.1 example.com

を追加します。
IPの部分は先ほど調べたIPを記載して下さい。

これで、すべての設定が終わりました。
Fusion側からブラウザを開いて、
example.com:88
とURLを入力すると、MAMPで設定したVirtualHostに接続されます。

2
2
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
2
2