生活随笔
收集整理的這篇文章主要介紹了
Mac OS X中配置Apache
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
啟動(dòng)Apache 打開“終端(terminal)”,輸入 sudo apachectl -v,(可能需要輸入機(jī)器秘密)。如下顯示Apache的版本
?
接著輸入 sudo apachectl start,這樣Apache就啟動(dòng)了。打開Safari瀏覽器地址欄輸入 “http://localhost”,可以看到內(nèi)容為“It works!”的頁面。其位于“/Library(資源庫)/WebServer/Documents/”下,這就是Apache的默認(rèn)根目錄。
Apache的安裝目錄在:/etc/apache2/,etc默認(rèn)是隱藏的。有三種方式查看:
dock下右鍵Finder,選擇"前往文件夾",輸入"/etc" 在finder下----》前往---》前往文件夾,然后輸入/etc 可以在terminal 輸入 "open /etc" ?
設(shè)置虛擬主機(jī) 在終端運(yùn)行“sudo vi /etc/apache2/httpd.conf”,打開Apche的配置文件 在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,保存并退出。 運(yùn)行“sudo apachectl restart”,重啟Apache后就開啟了虛擬主機(jī)配置功能。 運(yùn)行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,就打開了配置虛擬主機(jī)文件httpd-vhost.conf,配置虛擬主機(jī)了。需要注意的是該文件默認(rèn)開啟了兩個(gè)作為例子的虛擬主機(jī): <VirtualHost *:80>ServerAdmin webmaster@dummy-host.example.comDocumentRoot "/usr/docs/dummy-host.example.com"ServerName dummy-host.example.comErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost><VirtualHost *:80>ServerAdmin webmaster@dummy-host2.example.comDocumentRoot "/usr/docs/dummy-host2.example.com"ServerName dummy-host2.example.comErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost> 而實(shí)際上,這兩個(gè)虛擬主機(jī)是不存在的,在沒有配置任何其他虛擬主機(jī)時(shí),可能會(huì)導(dǎo)致訪問localhost時(shí)出現(xiàn)如下提示:
Forbidden
You don't have permission to access /index.php on this server 最簡單的辦法就是在它們每行前面加上#,注釋掉就好了,這樣既能參考又不導(dǎo)致其他問題。
增加如下配置 <VirtualHost *:80>DocumentRoot "/Library/WebServer/Documents"ServerName localhostErrorLog "/private/var/log/apache2/localhost-error_log"CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost> <VirtualHost *:80>DocumentRoot "/Users/snandy/work"ServerName mysitesErrorLog "/private/var/log/apache2/sites-error_log"CustomLog "/private/var/log/apache2/sites-access_log" common<Directory />Options Indexes FollowSymLinks MultiViewsAllowOverride NoneOrder deny,allowAllow from all</Directory>
</VirtualHost> 保存退出,并重啟Apache。
運(yùn)行“sudo vi /etc/hosts”,打開hosts配置文件,加入"127.0.0.1 mysites",這樣就可以配置完成sites虛擬主機(jī)了,可以訪問“http://mysites”了,在10.8之前Mac OS X版本其內(nèi)容和“http://localhost/~[用戶名]”完全一致。 注意,記錄log的“ErrorLog "/private/var/log/apache2/sites-error_log"”也可以刪掉,但記錄日志其實(shí)是一個(gè)好習(xí)慣,在出現(xiàn)問題時(shí)可以幫助我們判斷。如果保留這些log代碼,一定log文件路徑都是存在的,如果隨便修改一個(gè)不存在的,會(huì)導(dǎo)致Apache無法服務(wù)而沒有錯(cuò)誤提示,這個(gè)比較惡心。
轉(zhuǎn)載于:https://www.cnblogs.com/chenshuo/p/3856114.html
總結(jié)
以上是生活随笔 為你收集整理的Mac OS X中配置Apache 的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔 推薦給好友。