美文网首页
Mac电脑搭建自带的Apache本地服务器

Mac电脑搭建自带的Apache本地服务器

作者: 我是一根聪 | 来源:发表于2020-10-16 18:39 被阅读0次

打开浏览器,访问http://127.0.0.1/或者http://localhost,如果没有开启服务,这时候会提示无法访问,如果显示下图,说明已经开启成功。

开启本地服务器

常用命令

1. 开启服务器的命令

//开启apache: sudo apachectl start

//重启apache: sudo apachectl restart

//关闭apache: sudo apachectl stop

2. 本地服务器的地址

/Library/WebServer/Documents

使用终端打开 open/Library/WebServer/Documents, 

在Documents目录下放入目标文件,访问http://127.0.0.1/目标文件

外网需要访问,查询ip命令ifconfig,把127.0.0.1换成你电脑的IP地址即可

3. 把服务器的本地文件夹修改成自己定义的路径

终端输入 open  /etc

Apache服务器文件

找到并打开httpd.conf文件,查找:

DocumentRoot "/Library/WebServer/Documents"

<Directory "/Library/WebServer/Documents">

...

</Directory>

替换为自己自定义地址

DocumentRoot "/Users/用户名/WebServer"

<Directory "/Users/用户名/WebServer">

...

</Directory>

这两行是注释了的,需要打开

#LoadModule php7_module libexec/apache2/libphp7.so

#LoadModule userdir_module libexec/apache2/mod_userdir.so

保存并重启服务器(sudo apachectl -k restart)。

相关文章

网友评论

      本文标题:Mac电脑搭建自带的Apache本地服务器

      本文链接:https://www.haomeiwen.com/subject/fnctmktx.html