--->配置Apache伺服器:
(提示:$開頭的,可以拷貝,但是不要拷貝$)
1.在使用者檔案夾下建立檔案夾Sites,後面将把測試資料放入這個檔案夾
2.切換到工作目錄
$cd /etc/apache2
3.備份檔案,以防不測,隻需要執行一次就可以了
$sudo cp httpd.conf httpd.conf.bak
// 如果後續操作出現錯誤!可以使用以下指令,恢複備份過的 httpd.conf 檔案
$ sudo cp httpd.conf.bak httpd.conf
4.vim裡面隻能用鍵盤,不能用滑鼠, 用vim編輯httpd.conf
$sudo vim httpd.conf
5.查找DocumentRoot
/DocumentRoot
6.用鍵盤 i 進入編輯模式
7.把下面的根路徑修改為自己在使用者下建立的Sites的路徑
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
8.找到Options FollowSymLinks 修改為
*Options Indexes FollowSymLinks
ESC退出編輯模式
9.查找php
/php
"将光标移動到首行"
// 删除行首注釋#
按x
10.儲存并退出
:wq
如果配置錯誤需要重新配置用 :q!(不儲存退出)
11.切換工作目錄
$cd /etc
// 拷貝php.ini檔案
$sudo cp php.ini.default php.ini
// 重新啟動apache伺服器
$sudo apachectl -k restart
如果出現這種錯誤:
AH00526: Syntax error on line 20 of /private/etc/apache2/extra/httpd-mpm.conf:
Invalid command 'LockFile', perhaps misspelled or defined by a module not included in the server configuration
解決方法:
第一步進入以下目錄找到httpd-mpm.conf這個檔案
/private/etc/apache2/extra/httpd-mpm.conf
第二步在檔案中找到LockFile "/private/var/log/apache2/accept.lock",顯示簡介,把權限改為讀與寫
第三步在檔案中找到LockFile "/private/var/log/apache2/accept.lock",用#注釋掉如下
#LockFile "/private/var/log/apache2/accept.lock"
第四步重新啟動apache伺服器
sudo apachectl -k restart