Mac 自帶Apache和PHP
默認(rèn)路勁
- Apache服務(wù)器默認(rèn)的web根目錄在:
/Library/WebServer/Documents - Apache的配置文件在:
/etc/apache2
常用命令
- 開啟Apache:
sudo apachectl start - 關(guān)閉Apache:
sudo apachectl stop - 重啟Apache:
sudo apachectl restart - 查看Apache版本:
sudo apachectl -v
在terminal運(yùn)行Apache啟動(dòng)命令
sudo apachectl start
啟動(dòng)瀏覽器,輸入http://localhost
發(fā)現(xiàn) It works!
Apache 啟動(dòng)成功,這時(shí)候使用的是默認(rèn)服務(wù)器位置
配置實(shí)現(xiàn)個(gè)人服務(wù)器
創(chuàng)建個(gè)人服務(wù)器目錄
在自己用戶名下創(chuàng)建一個(gè)sites文件夾-
找到配置文件給原來
httpd.conf備份
進(jìn)入Apache的配置文件:cd /etc/apache2
備份Apache的配置文件:sudo cp httpd.conf httpd.conf.bak如果遇到錯(cuò)誤想恢復(fù)配置文件:
sudo cp httpd.conf.bak httpd.conf -
修改配置文件
進(jìn)入/etc/apache2目錄下:sudo vim httpd.conf- 修改服務(wù)器默認(rèn)路徑
查找DocumentRoot 將圖片中紅框路徑 替換為sites文件路徑
添加黃顏色框的Indexes
- 修改服務(wù)器默認(rèn)路徑
-
加載php模塊
查找php 將#刪除
保存后退出:wq 不保存退出q!
備份php配置文件
進(jìn)入/etc目錄下:cd /etc
備份php配置文件:sudo cp php.ini.default php.ini重啟Apache
sudo apachectl -k restart
1、警告
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MitakedeMacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
將#ServerName www.example.com:80
改為ServerName localhost:80

