標籤:
mac中內建了apache伺服器, 如果需要在mac上使用apache伺服器, 只需要配置並啟動伺服器即可。
mac 10.10 中內建的apache版本是 2.4
mac 10.9 中內建的apache版本是2.2
1. 啟動伺服器
開啟Terminal, 輸入 sudo apachectl start 即可。
啟動後, 在瀏覽器中輸入http://localhost 就能看到 "It works!"
常用命令:
啟動伺服器:sudo apachectl start
關閉伺服器:sudo apachectl stop
重啟伺服器:sudo apachectl restart
2. 配置個人網站
mac內建的apache設定檔放在 /etc/apache2/目錄下
- 開啟/etc/apache2/httpd.conf,找到下面幾行,去掉開頭的#號
LoadModule userdir_module libexec/apache2/mod_userdir.soInclude /private/etc/apache2/extra/httpd-userdir.conf
- 開啟/etc/apache2/extra/httpd-userdir.conf,找到下面的內容,去掉開頭的#號
Include /private/etc/apache2/users/*.conf
- 在/etc/apache2/users檔案夾下,建立一個 fengquan.conf 設定檔(你的使用者名稱是什麼, 紅色的部分就寫什麼)。在檔案中寫入以下內容:(下面的fengquan, 改為你的使用者名稱)
<Directory "/Users/fengquan/Sites/"> Options Indexes MultiViews AllowOverride None require all granted</Directory>
- 建立~/Sites檔案夾, 並在檔案夾下建立一個index.html, 在裡面隨便寫點內容。
- 重啟apache伺服器。 sudo apachectl restart
3. 支援php
開啟/etc/apache2/httpd.conf,找到下面的內容, 去掉前面的#號
LoadModule php5_module libexec/apache2/libphp5.so
重啟伺服器
4. 許可權問題
mac 10.9, apache2.2中, 控制許可權是用的
<Directory "/Users/fengquan/Sites/"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all</Directory>
mac 10.10, apache2.4中, 控制許可權改為
<Directory "/Users/fengquan/Sites/"> Options Indexes MultiViews AllowOverride None require all granted</Directory>
enjoy yourself!
MAC 10.10 apache 伺服器配置