macOS使用Apache启动本地服务
2021-06-23 本文已影响0人
chenjundi
很多时候我们移动端开发需要在手机预览效果,macOS
自带的Apache
服务非常方便。
首先在终端输入命令开启服务(此时会提示输入电脑密码):
sudo apachectl start
然后在浏览输入http://127.0.0.1
,如果正确访问的话会看到:
![](https://img.haomeiwen.com/i15901193/02597d267c333535.png)
接着可以在终端输入open /Library/WebServer/Documents
打开文件夹:
![](https://img.haomeiwen.com/i15901193/519a0de82a6247b3.png)
以后把自己的资源test.html
放进去就能预览了:
![](https://img.haomeiwen.com/i15901193/ac8bdff91eb865b3.png)
可以把/WebServer/Document
目录直接拖到访达方便以后使用:
![](https://img.haomeiwen.com/i15901193/a0ebe9eefdfc035b.png)
最后关闭Apache
服务:
sudo apachectl stop