Androidはワンツーパンチ 三歩進んで二歩下がる

プログラミングやどうでもいい話

Mac OS X 10.10.4 Yosemiteのlocalhost設定

PCを買い替えたけど、設定は昔のMacを引き継ぎませんでした。
久々にローカルサーバーを使う必要があり、http://localhost/~user/に接続を試みたら
404 Not Found
The requested URL /~user/ was not found on this server.
のエラーになってしまいました。

何回も似たようなことをググっているので、今回は接続するまでの手順のメモを取って残しておきました。
参考サイト様をほとんど踏襲させていただきました。自分用メモです。
Maclocalhost設定qiita.com


使用OS

OS X 10.10.4 Yosemite

1.デフォルトのApacheの確認する

$ httpd -v
Server version: Apache/2.4.10 (Unix)
Server built:   May 19 2015 09:36:36

2.Apacheを自動実行されるようにする

$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

↑のコマンドを実行すると
/System/Library/LaunchDaemons/org.apache.httpd.plist: Operation already in progress
と表示されたのですでに稼働中でした。
この時点でhttp://localhost/ にアクセスすると「It works!」が表示されます。

3.user.confの確認

{user}.confがあるかどうかは当ブログの過去記事で確認しました。
Mac OS X Mountain Lionにシステム環境設定の「共有」パネルに Web 共有のオプションが入っていない件について - Androidはワンツーパンチ 三歩進んで二歩下がる
この時点ではhttp://localhost/~user/へアクセスしても404になってしまいました。

4./etc/apache2/httpd.confの設定の見直し

以下の項目のコメントアウトを外す

LoadModule include_module libexec/apache2/mod_include.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf


Directoryの設定を変更する

<Directory />
    AllowOverride none
    Require all denied
</Directory>
↓
<Directory />
    AllowOverride all
    Require all granted
</Directory>


OptionsにIndexes、Includesを追加する

Options FollowSymLinks Multiviews
↓
Options FollowSymLinks Multiviews Indexes Includes

AddOutputFilter INCLUDES .shtmlに.htmlを追加する

AddOutputFilter INCLUDES .shtml
↓
AddOutputFilter INCLUDES .shtml .html

5./etc/apache2/extra/httpd-userdir.conf を編集する

以下のコメントアウトを外す

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

6. /etc/apache2/extra/httpd-vhosts.confを編集する

<VirtualHost *:80>
    DocumentRoot "/Users/{username}/Sites/{yourdocs}"
    ServerName {yourservername}
    <Directory "/Users/{username}/Sites/{yourdocs}">
        Require all granted
        DirectoryIndex index.html
        Options Includes
    </Directory>
</VirtualHost>

自分の環境ではhttpd-vhosts.confにデフォルトでサンプルが2つ記述されているのでとりあえずその下に↓を加えてみました。

<VirtualHost *:80>
    DocumentRoot "/Users/sakura/Sites/sakura"
    ServerName sakura
    <Directory "/Users/sakura/Sites/sakura">
        Require all granted
        DirectoryIndex index.html
        Options Includes
    </Directory>
</VirtualHost>

7.Appacheを再起動

$ sudo apachectl restart

これでうまく表示できました。

f:id:sakura_bird1:20150808143210p:plain

以上です。