1. 程式人生 > >Mac電腦配置Apache伺服器用於做網路資料測試

Mac電腦配置Apache伺服器用於做網路資料測試

Mac電腦伺服器配置過程,無論是個人學習,還是公司測試都非常實用,流程精簡易懂,用於讓Mac電腦做伺服器方便做網路資料請求的測試。

 

第一步:定位到 Apache2 目錄

$ cd /etc/Apache2/       

 

第二步:在 Finder 新建 sites資料夾,開啟讀與寫許可權.

 

第三步:顯示目錄列表

$ ls  

 

第四步:用管理員許可權開啟vim 編輯器,並進入httpd.con伺服器配置檔案,輸入開機密碼

$ sudo vim httpd.conf

 

第五步:查詢伺服器預設根路徑, vim編輯裡輸入

/DocumentRoot 

 

第六步:定位到 DocumentRoot "/Library/WebServer/Documents" 這一行點鍵盤的出現 —INSERT— (編輯修改)

 

第七步:在這兩行前加#號註釋 

DocumentRoot"/Library/WebServer/Documents"   這是生臺電腦的伺服器

<Directory"/Library/WebServer/Documents">

 

第八步:點選Esc  退出編輯模式

#DocumentRoot"/Library/WebServer/Documents"

#<Directory"/Library/WebServer/Documents">

游標定位這兩行上,複製這兩行

shift + v 選中行    ,再按 y 複製選中行p 貼上選中的一行

 

第九步:把複製的行找開註釋Mac電腦中的伺服器資料夾拖來替換以前的兩個路徑

#DocumentRoot"/Library/WebServer/Documents"

DocumentRoot"/Users/apple/Sites"

#<Directory"/Library/WebServer/Documents">

<Directory"/Users/apple/Sites">>

 

第十步:按Esc退出編輯模式,查詢php

/php 

查詢到php i 編輯刪除前面的註釋 #  Esc退出,開啟註釋就意味差Mac支援 php程式碼

#LoadModulephp5_module libexec/apache2/libphp5.so

 

第十一步:查詢 Options Follow

/OptionsFollow

定位到   Options FollowSymLinksMultiviews 

i 編輯

Options 後面加上 Indexes

Esc 退出編輯

 

第十二步:點選 :wq  儲存退出

 

第十三步:$ sudo apachectl -k restart  (重啟伺服器)

出現:httpd not running, trying to start  代表伺服器啟動成功

 

第十步:在瀏覽器輸入 127.0.0.1     localhost出現下面說明服務已經配好了

 

Index of /

           Name           Last modified      Size   Description