1. 打開終端,開啟Apache:
//開啟apache:? sudo apachectl start
//重啟apache:? sudo apachectl restart
//關(guān)閉apache:? sudo apachectl stop
回車會提示輸入密碼,也就是你電腦的密碼,http://127.0.0.1/測試一下,成功則如
下圖:

成功開啟Apache
2. 點擊Finder,然后Command+Shift+G,前往Apache服務(wù)器的文件路徑(/Library/WebServer/Documents),如圖:

Apache服務(wù)器文件路徑
在步驟1中只輸入一個http://127.0.0.1其實默認(rèn)打開的是index.html.en(html是一個網(wǎng)頁文件),該文件的內(nèi)容就是在步驟1中測試時瀏覽器所顯示的內(nèi)容。此時如果我在瀏覽器的網(wǎng)址框輸入的是http://127.0.0.1/PoweredByMacOSX.gif, 瀏覽器就便會顯示PoweredByMacOSX.gif圖片,如果沒有正常顯示,提示說沒有權(quán)限時,單擊該文件,然后Command+I在末尾設(shè)置權(quán)限即可。
3. 測試
創(chuàng)建一個文件,如test.html(名字能夠隨意起),
接下來用瀏覽器訪問http://127.0.0.1/test.html
IP(127.0.0.1)也可以換成你電腦的IP地址,這樣在同一局域網(wǎng)的設(shè)備也可以訪問服務(wù)器的內(nèi)容。
配置文件路徑為
/etc/apache2/httpd.conf
PS:使用過后,記得關(guān)閉服務(wù)器,要不然會一直消耗你電腦內(nèi)存,后果你懂的。
地址:https://www.cnblogs.com/wanxudong/p/5846907.html
地址:https://jingyan.baidu.com/article/922554467d763b851648f4dc.html
地址:https://www.cnblogs.com/silence-wzx/p/5137766.html
二.用JSON-server模擬數(shù)據(jù)
1.安裝
? sudo npm install json-server -g
安裝完成后可以用 json-server -h 命令檢查是否安裝成功,成功后會出現(xiàn)
json-server [options] <source>
選項:
--config, -c Path to config file [默認(rèn)值: "json-server.json"]
--port, -p Set port [默認(rèn)值: 3000]
--host, -H Set host [默認(rèn)值: "0.0.0.0"]
--watch, -w Watch file(s) [布爾] --routes,
-r Path to routes file --static,
-s Set static files directory --read-only,
--ro Allow only GET requests [布爾] --no-cors,
--nc Disable Cross-Origin Resource Sharing [布爾]
--no-gzip, --ng Disable GZIP Content-Encoding [布爾]
--snapshots, -S Set snapshots directory [默認(rèn)值: "."]
--delay, -d Add delay to responses (ms) --id,
-i Set database id property (e.g. _id) [默認(rèn)值: "id"]
--quiet, -q Suppress log messages from output [布爾]
--help, -h 顯示幫助信息 [布爾] --version,
-v 顯示版本號 [布爾]
示例: json-server db.json
json-server file.js
json-server http://example.com/db.json
https://github.com/typicode/json-server
2.運行
安裝完成后,可以在任一目錄下建立一個 xxx.json文件,例如在 mock/ 文件夾下,建立一個 db.json 文件,并寫入以下內(nèi)容,并在 mock/ 文件夾下執(zhí)行
json-server db.json -p 3003
{"news":[ {"id":1,"title":"曹縣宣布昨日晚間登日成功","date":"2016-08-12","likes":55,"views":100086}, {"id":2,"title":"長江流域首次發(fā)現(xiàn)海豚","date":"2016-08-12","likes":505,"views":9800} ],"comments":[ {"id":1,"news_id":1,"data": [? ? {"id":1,"content":"支持黨中央決定"},? ? {"id":2,"content":"抄寫黨章勢在必行!"} ] }]}
3.操作數(shù)據(jù)
使用【GET 接口】查詢數(shù)據(jù)這個時候訪問http://localhost:3003/db,可以查看 db.json文件中所定義的全部數(shù)據(jù)。使用瀏覽器地址欄,jQuery.get 或 fecth({method: "get"}) 訪問http://localhost:3003/news則可以看到 news
對象下的數(shù)據(jù),以Array格式返回:
[ {"id":1,"title":"曹縣宣布昨日晚間登日成功","date":"2016-08-12","likes":55,"views":100086}, {"id":2,"title":"長江流域首次發(fā)現(xiàn)海豚","date":"2016-08-12","likes":505,"views":9800}]