同じLAN内の他PCやスマートフォンから、 ローカルで公開している画面にアクセスできるよう設定する方法です。
環境 | 環境名 |
---|---|
OS | Windows 7 Professional SP1 64-bit |
XAMPP | XAMPP Version 5.6.8 |
手順としては下記項目となります。
Apacheが外部からリクエストを受け付けるポート番号を下記のように記述します。
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# 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 ポート番号
Apacheサーバが自分自身のホスト名を示す時に使われる名前を下記のように記述します。
#
# 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アドレス:ポート番号
アクセス先のIPアドレスに対して、名前ベースの仮想ホストを設定していることを表すために、NameVirtualHostを下記のように設定します。
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
NameVirtualHost *:ポート番号
ServerName毎に個別の設定を下記のようにします。
<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>
IPアドレスとホスト名を下記のように記述します。
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
IPアドレス サーバ名
hostsファイルはC:\Windows\System32\drivers\etc
直下に存在します。
このファイルは管理者権限でないと開くことが出来ないので、注意する必要があります。
開く際は全てのファイル(*.*)
として探す必要があります。
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>
Allow fromの箇所にはアクセス許可をしたいIPアドレスを記述します。
ローカルからアクセスできない場合は下記が問題かもしれません。
- ポート番号80がすでに使用されている。Skypeなど他で使用している可能性があります。
- プロキシサーバを使用している。
他PCからアクセスできない場合は、下記が問題かもしれません。
- ファイアウォールを使用している。
##アクセス方法
URLにhttp://IPアドレス:ポート番号
を入力すればアクセスできます。
【xampp】LAN内の他のPCからページが見れない場合の対処法
XAMPP にイントラネット内 (LAN 内) のPC から接続する設定