Mac OS 系統(tǒng)已經(jīng)集成了 Apache 環(huán)境,只需要配置啟用就可以了。
啟用 Apache
- 查看 Apache 版本
$ httpd -v
版本信息:
Server version: Apache/2.4.23 (Unix)
Server built: Aug 8 2016 18:10:45
- 啟動 Apache
$ sudo apachectl start
在瀏覽器中輸入 http://127.0.0.1 或 http://localhost 如果看到 It Works! 那么 Apache 就啟動成功了。
- 關(guān)閉 Apache
$ sudo apachectl stop
- 重啟 Apache
$ sudo apachectl restart
配置 Apache 目錄
- Apache系統(tǒng)級根目錄及對應(yīng)網(wǎng)址
/Library/WebServer/Documents
http://127.0.0.1 或 http://localhost
- 用戶級的根目錄及對應(yīng)網(wǎng)址
~/Sites
http://localhost/~haibor/
- 用戶級站點(diǎn)根目錄需要手動創(chuàng)建
1、建立站點(diǎn)文件夾
$ sudo mkdir ~/Sites
2、$ cd /etc/apache2/users檢查目錄下是否存在Wmy.conf文件,Wmy為當(dāng)前用戶名,如果沒有則創(chuàng)建一個$ sudo touch Wmy.conf,并修改文件權(quán)限$ sudo chmod 644 Wmy.conf。
3、創(chuàng)建之后,打開 Guest.conf 文件,$ sudo vi Wmy.conf將下面的配置信息寫入文件。
<Directory "/Users/Wmy/Sites/">
Options Indexes MultiViews
Require all granted
Allow Override all
Order allow,deny
allow from all
</Directory>
4、編輯 httpd.conf文件$ sudo vi /etc/apache2/httpd.conf,將下面兩行代碼前面的注釋符號#刪掉。內(nèi)容比較多,可以使用 ctrl+w 搜索關(guān)鍵詞找到對應(yīng)位置。
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule userdir_module libexec/apache2/mod_userdir.so
5、編輯 httpd-userdir.conf 文件$ sudo vi /etc/apache2/extra/httpd-userdir.conf,找到下列代碼,并將前面的注釋符號 # 刪除
6、重啟 Apache:$ sudo apachectl restart
在瀏覽器中輸入 http://127.0.0.1/~Wmy 或 http://localhost/~Wmy ,即可測試用戶目錄是否工作。