こんにちは
開発部のモリヤです。
自分はXAMPP+Eclipseを使ってローカル環境を構築し作業を行っているのですが、
先日、自分の作ったローカル環境を同じ社内LANに接続している別のPCで表示する必要があったので手法をご紹介します。
使用するPCのIPアドレスを調べる
まずは自信が使用するPCのIPアドレスを調べます。
調べ方は、
・コマンドプロンプトを立ち上げる
・「ipconfig」と入力
・表示されたIPアドレス(192.168.XXX.XXX)をメモ

各種ファイルに定義追加
以下のファイルに定義を追加していきます。
C:\xampp\apache\conf\httpd.conf
C:\xampp\apache\conf\extra\httpd-xampp.conf
C:\xampp\apache\conf\extra\httpd-vhosts.conf
C:\Windows\System32\drivers\etc\hosts
※上記は自分が使っている環境のパスの為、各々の環境で読み替えてください。
①httpd.confに、外部からリクエストを受けるポート番号を定義
Apacheが外部からリクエストを受け付けるポート番号を下記のように記述します。
ポート番号は、他の機能と競合していない番号を設定してください。
- #
- # Listen: Allows you to bind Apache to specific IP addresses and/or
- # ports, instead of the default. See also the
- # directive.
- #
- # Change this to Listen on specific IP addresses as shown below to
- # prevent Apache from glomming onto all bound IP addresses.
- #
- #Listen 12.34.56.78:80
- Listen 80
- Listen ポート番号
※ポート番号が競合しているか確認するには、コマンドプロンプトを立ち上げ、以下を入力、レスポンスが空で返ってくればOKです。
- netstat -an | find “:<ポート番号>”
②httpd.confに、ホスト名を定義
Apacheサーバが自分自身のホスト名を示す時に使われる名前を定義します。
事前に調べたIPアドレスと、①で定義したポート番号を記述してください。
- #
- # ServerName gives the name and port that the server uses to identify itself.
- # This can often be determined automatically, but we recommend you specify
- # it explicitly to prevent problems during startup.
- #
- # If your host doesn’t have a registered DNS name, enter its IP address here.
- #
- ServerName IPアドレス:ポート番号
③httpd-vhosts.confに、名前ベースの仮想ホストの設定
アクセス先のIPアドレスに対して、名前ベースの仮想ホストを設定していることを表すために定義します。
- #
- # Use name-based virtual hosting.
- #
- NameVirtualHost *:80
- NameVirtualHost *:ポート番号
④httpd-vhosts.confに、ServerName毎の個別の設定
ServerName毎に個別の設定を下記のように定義します。
“設定したいディレクトリ“はEclipseの該当プロジェクト名を、
“サーバ名“はわかりやすい名前を設定してください。
- <VirtualHost *:80>
- DocumentRoot “C:/xampp/htdocs”
- ServerName localhost
- </VirtualHost>
- <VirtualHost *:ポート番号>
- DocumentRoot C:/xampp/htdocs/設定したいディレクトリ
- ServerName サーバ名
- </VirtualHost>
- <Directory “C:/xampp/htdocs/設定したいディレクトリ”>
- order deny,allow
- allow from ALL
- </Directory>
⑤hostsに、IPアドレスに対するホスト名の定義
IPアドレスとホスト名を下記のように定義します。
- # localhost name resolution is handled within DNS itself.
- # 127.0.0.1 localhost
- # ::1 localhost
- IPアドレス サーバ名
⑤httpd-xampp.confに、ローカルネットワーク内のアクセス許可
New XAMPP security conceptを下記のように修正します。
※元々の記述は#をつけてコメントアウトしておくと、元に戻す際に簡単です。
- #
- # New XAMPP security concept
- #
- <LocationMatch “^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))”>
- #Require local
- ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
- Order deny,allow
- Deny from all
- Allow from 127.0.0.1
- Allow from IPアドレス
- </LocationMatch>
⑥アクセス確認
全ての設定が完了したら、以下のURLを入力すればアクセスできます。
- http://IPアドレス:ポート番号

注意点
アクセスできない場合は下記を確認してください。
・ポート番号80がすでにSkypeなど他で使用している。
・プロキシサーバを使用している。
また、他PCからアクセスできない場合は、ファイアウォールの設定などの可能性があります。
コメントをどうぞ