MAC::ApacheのVirtual Hostを設定

(1) ターミナルを起動してviでApacheの設定ファイルを開く。

sudo vi /etc/apache2/httpd.conf

 

(2) ファイルの最後のほうにこの記述があることを確認して設定ファイルを閉じる。

Include /private/etc/apache2/other/*.conf

 

(3) /etc/apache2/otherに今回設定したいバーチャルホスト用の設定ファイルを作成。

sudo vi /etc/apache2/other/example.localhost.conf

 

内容は下記のような感じ。

 

# example.localhost

<VirtualHost *:80>

    DocumentRoot "/Users/username/Sites/example"

    ServerName example.localhost

<Directory "/Users/username/Sites/example">

order allow,deny

allow from All

</Directory>

</VirtualHost>

 

(4) hostsファイルの設定をする。

sudo vi /private/etc/hosts

ファイルの最後に下記のように今回設定したいバーチャルホストを追記。

 

127.0.0.1       example.localhost

 

(5) Apacheを再起動。

sudo apachectl restart

 

これで/Users/username/Sites/exampleに作成したサイトを

ブラウザからhttp://example.localhost/にアクセスすることで確認できる。

 

実際に設定してから間があいちゃって思い出しながら書いてるから抜けがあるかも…

多分間違ってないはず。