Skip to content

[mac] 更改 apache root 資料夾位置,userdir 設置

Published: at 08:37 AM

之前寫了一篇如何在 mac 安裝 phpmyadmin, php 及 mysql

應該許多人使用預設的 apache 的根目錄( /Library/WebServer/Documents/)

會想要更改為自訂的路徑或是使用者資料夾.


更改 apache 根目錄路徑:

vim /etc/apache2/httpd.conf

將以下內容更改為自訂的資料夾路徑,如:

DocumentRoot “/Users/Camel/www”

<Directory “/Users/Camel/www”>

apachectl -k restart

這樣就可以更改 apache 的根目錄資料夾至 [camel] 使用者家目錄下的 www 資料夾.

如果你想幫每個使用者都設置一個 apache 根目錄資料夾,可以開啟 apache 的 userdir 模組

如下步驟:

vim /etc/apache2/httpd.conf

將以下這兩行開頭的 # 刪除

LoadModule userdir_module libexec/apache2/mod_userdir.so

Include /private/etc/apache2/extra/httpd-userdir.conf

vim /etc/apache2/httpd-userdir.conf

將以下這行開頭的 # 刪除

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

檢查 /private/etc/apache2/users/ 是否存在 [user].conf Directory 可以自訂

<Directory “/Users/camel/Sites/”> Options Indexes MultiViews Require all granted

重新開啟 apache

apachectl -k restart

創建範例檔

mkdir ~/Sites

echo "<h1>It works</h1>" > ~/Sites/index.html

連結網址:http://localhost/~camel

參考資料:

http://stackoverflow.com/questions/8851544/change-web-root-apache-mac-os-x