2018-04-10 mac开启原生服务器

mac开启原生服务器

  1. 命令行 开启appache
    //开启 apache: sudo apachectl start
    //重启 apache: sudo apachectl restart
    //关闭 apache: sudo apachectl stop

注意⚠️:回车会提示输入电脑的密码,然后访问http://127.0.0.1/测试一下,成功则显示it works!

  1. 访问的文件路径是
    点击Finder,然后Command+Shift+G,前往如下路径 (mac下Apache服务器的文件路径 /Library/WebServer/Documents
    将文件放在该目录即可访问

不使用的时候记得关闭,消耗内存

  1. 注意访问目录下文件的时候有可能提示没有权限(状态码403)
    访问地址http://127.0.0.1/webroot/login.html

错误提示❌:Forbidden
You don't have permission to access /webroot/login.html on this server.
Server unable to read htaccess file, denying access to be safe

解决方案:

  • 更改httpd.conf配置文件
  • 给文件添加777权限执行命令 chmod 777 webroot
  1. 变更默认文件路径/Library/WebServer/Documents为自定义路径/Users/xueersi/workspace/Sites/
    更改步骤:
  • A 打开文件 /private/etc/apache2/httpd.conf
# LoadModule userdir_module libexec/apache2/mod_userdir.so

对该行解注释 (去掉#)

  • B 在用户名下创建文件夹Sites(要变更到的目录)路径/Users/xueersi/workspace/Sites/
  • C 修改/private/etc/apache2/httpd.conf文件中的DocumentRoot
DocumentRoot "/Users/xueersi/workspace/Sites/"
<Directory "/Users/xueersi/workspace/Sites/">
  • D 创建 用户名.conf 配置文件 /private/etc/apache2/users/xueersi.conf
    输入代码
<Directory "/Users/tangjr/Sites/">
 Options Indexes MultiViews
 AllowOverride All
 Require all granted # OSX 10.10 / Apache 2.4
</Directory>
  • E 找到/private/etc/apache2/httpd.conf文件中
Options FollowSymLinks Multiviews

修改为

Options FollowSymLinks Multiviews Indexes
  • F 重新启动appache服务器
    sudo apachectl restart

注意⚠️: 如果restart后不生效,则执行stop后start

参考链接mac原生服务器文件地址变更

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我们经常性的需要使用局域网搭建 Web 服务器测试环境,如部署局域网无线安装企业应用等,Mac OS X 自带了 ...
    大诗兄_zl阅读 1,701评论 0 2
  • 我们经常性的需要使用局域网搭建 Web 服务器测试环境,如部署局域网无线安装企业应用等,Mac OS X 自带了 ...
    小白不是总阅读 55,512评论 24 134
  • 如果你使用的是mac 系统,很荣幸的告诉你的系统自带Apache服务器,查看自己当前系统下是否安装好了该服务器,输...
    gogoingmonkey阅读 1,914评论 0 1
  • 手残升级了mac系统,结果php环境不能用了:sudo apachectl start访问 localhost ...
    abs1004阅读 4,870评论 0 4
  • 处于温饱线以下的人多是没有理想的,每天都在为生活而忙碌奔波,从早到晚工作不停,累到回家倒头就睡,就算有梦想,也...
    话多不语阅读 765评论 0 1