今回のようなサーバー移転などの際にローカルでのテスト環境として重宝するXAMPP。
逆に言うと私の場合そういう時にしか使わないですがw
久々に使う場合、本稼働させるレンタルサーバーのPHPのバージョンなどに合わせたXAMPPを入れ直すのですが、毎回設定を忘れるので備忘録として書いておこうかなと。
ヴァーチャルホストを使って、http://localhost/のドキュメントルートを「C:\XAMPP\public_html」に、元の「C:\XAMPP\htdoc」へはポート8080でアクセスできるようにする場合。
以下、すべて「C:\XAMPP」にインストールされて前提で、
「C:\XAMPP\apache\conf\extra\httpd-vhosts.conf」を編集。
# Use name-based virtual hosting. # ##NameVirtualHost *:80
ここでヴァーチャルホストでポート80が使用できるようにコメントアウトを外す。
更に8080も使えるように追加。
# Use name-based virtual hosting. # NameVirtualHost *:80 NameVirtualHost *:8080
同じくhttpd-vhosts.confでポート毎の設定を変更。
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host.localhost
##DocumentRoot "/xampp/htdocs/dummy-host.localhost"
##ServerName dummy-host.localhost
##ServerAlias www.dummy-host.localhost
##ErrorLog "logs/dummy-host.localhost-error.log"
##CustomLog "logs/dummy-host.localhost-access.log" combined
##</VirtualHost>
##<VirtualHost *:80>
##ServerAdmin postmaster@dummy-host2.localhost
##DocumentRoot "/xampp/htdocs/dummy-host2.localhost"
##ServerName dummy-host2.localhost
##ServerAlias www.dummy-host2.localhost
##ErrorLog "logs/dummy-host2.localhost-error.log"
##CustomLog "logs/dummy-host2.localhost-access.log" combined
##</VirtualHost>
を下記のように。
<VirtualHost *:80>
DocumentRoot "/xampp/public_html/"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/xampp/htdocs/"
ServerName localhost
</VirtualHost>
これで、
- http://localhost ⇒ /xampp/public_html (80は標準ポートなので指定いらず)
- http://localhost:8080 ⇒ /xampp/htdocs
というヴァーチャルホストの設定が完了。
残念ながらまだこの状態では動作しない。
ひとつ上の階層にある「C:\XAMPP\apache\conf\httpd.conf」も編集。
# # 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 0.0.0.0:80 #Listen [::]:80 Listen 80
この部分でポート8080もアクセスできるように追加。
# # 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 0.0.0.0:80 #Listen [::]:80 Listen 80 Listen 8080
「/xampp/htdocs」の設定は最初から記述されているので、
<Directory "/xampp/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
同じ内容で「/xamp/public_html」の設定を追加する。
変更ではなく追加ねw
<Directory "/xampp/public_html">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
これでApacheを再起動させれば完了。
もちろん「C:\XAMPP\public_html\」は作成しておかないとダメですw
なお、confの抜粋は、XAMPP1.8.0(今日現在最新版)に同梱の Apache2.4.2 のものです。
XAMPP1.7.2あたりから同じ設定で使ってるので古いバージョンでも大丈夫かと。
ちなみに間違って編集中に記事を公開してしまったので、慌てて仕上げて公開し直しました。
なので、多少殴り書き気味ですが備忘録なのでご勘弁。

コメント
[…] 473;トを使って、http://localhost/のドキュメントルートを「C:XAMPP… >>XAMPPのVirtual Host設定 ポート編(備忘録) Author: […]