tkm_71のブログ

自分のための備考録みたいなものです。

MacのApacheでドキュメント以下にindex.phpを設置

Apacheで任意の場所に作業フォルダを設置したい。

index.htmlやindex.phpをDocument以下の任意のフォルダにおいて作業したい時。
Macには元からApacheが入っていた気がした。

環境

作業フォルダを任意の場所に変更する

「/etc/apache2/httpd.conf」で以下の二箇所を変更する。
今回は、"/Library/WebServer/Documents" → ”/Users/takuma/Documents/study”
に変更してみます。

$ sudo emacs /etc/apache2/httpd.conf

//以下の変更。
237: DocumentRoot "/Users/takuma/Documents/study"
239: <Directory "/Users/takuma/Documents/study">

これでlocalhostにアクセスしたらいけると思ったけど、エラーがでる場合がある。

Forbiddenエラー

「You don't have permission to access / on this server.」
てな感じのエラーが出たので、以下で対応

対処法

フォルダに対するアクセス権がないらしいので、以下でパーミッションを変更。

$ chmod 701 ~/Documents

PHPを利用できるように

再度httpd.confを編集。

$ sudo emacs /etc/apache2/httpd.conf

//以下のコメントを外す。
169: LoadModule php5_module libexec/apache2/libphp5.so