#author("2017-03-06T17:33:04+09:00","default:wikiwriter","wikiwriter")
&tag(Homebrew/apache);
*目次 [#k3bbf3df]
#contents
*参考情報 [#v5a49fd8]
-[[Homebrew]]
-[[./古い情報20140426]]
#author("2017-03-08T21:22:07+09:00","default:wikiwriter","wikiwriter")

*インストール [#yb2943dd]

**バージョン2.2のインストール [#v90c8087]
-tap実行
 brew tap homebrew/apache
-バージョン2.2をインストール
 brew install httpd22
-次のような指示が表示される。
#pre{{
To have launchd start httpd22 at login:
    ln -sfv /usr/local/opt/httpd22/*.plist ~/Library/LaunchAgents
Then to load httpd22 now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd22.plist
}}

**古い方法 [#w9352f71]
-tapが必要
#pre{{
$ brew tap homebrew/dupes
$ brew install httpd
}}
-次のような指示が表示される。
#pre{{
To have launchd start httpd at login:
    ln -sfv /usr/local/opt/httpd/*.plist ~/Library/LaunchAgents
Then to load httpd now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist
}}

*設定 [#s9b8fc7a]

**自動起動設定 [#e8aa8be3]

-デフォルトのapacheを無効にしておく
 sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
***ポート80で自動起動する(実効ユーザーは自分 or www) [#p7ccf0c0]
-rootユーザーで動かしたい場合、plistを/Library/LaunchDaemons以下にコピーする必要がある
 sudo cp /usr/local/opt/httpd22/homebrew.mxcl.httpd22.plist /Library/LaunchDaemons
-設定ファイル/usr/local/etc/apache2/httpd.confを編集する。
-ポート番号を80に変更
-ユーザーの変更
--自分の場合
#pre{{
User sora
Group staff
}}
--実効ユーザーをwwwにする場合は以下。
#pre{{
User www
Group www
}}
-launchctlで設定する。
 sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.httpd22.plist


※ちなみに「sudo brew services start httpd」でいけそうに思えるがうまくいかない。
-brew services start httpdは、homebrew.mxcl.httpd.plistを改変してから /Library/LaunchDaemons/homebrew.mxcl.httpd.plistへコピーする。
-このときUserNameにsoraという値が設定されてしまい、rootで起動する設定にもかかわらず一般ユーザー起動扱いになり、ポート80で動かなくなる。
-brew-services.rbを読む限り仕様っぽいがとにかくこのままでは使えない。
** ユーザーディレクトリを有効化 [#p1310a99]
-httpd.confで以下をコメントアウト
#pre{{
# User home directories
Include /usr/local/etc/apache2/2.2/extra/httpd-userdir.conf
}}
-httpd-userdir.confを編集。
#pre{{
UserDir Sites

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
<Directory "/Users/*/Sites">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
}}

*トラブルシューティング [#cab86675]
**知らないhttpdが動いていた? [#hff9bb22]
-パスの関係で、デフォルトのapachectrlを動かしてしまったのかも。/usr/local/binがパスの戦闘にあることを確認する。


**DocumentRootを変更すると403エラーでアクセスできない [#haf53d4d]
-例えばDocumentRootを/User/sora/wwwに変更してindex.htmlを作成しても、403エラーでhttp://localhost/index.htmlにアクセスできない。
-一見/Users/sora/www等のパーミッション関連の問題のように思えるが、実際はDirectoryで「deny from all」が指定されているため。
-httpd.confで以下のように変更する。
#pre{{
<Directory />
    Options FollowSymLinks
#    AllowOverride None
#    Order deny,allow
#    Deny from all
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
}}


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS