美文网首页我爱编程
Mac OS X 配置 Apache

Mac OS X 配置 Apache

作者: 静水流深_0321 | 来源:发表于2017-04-06 23:42 被阅读0次

启动

启动 Apache: sudo apachectl start

关闭 Apache: sudo apachectl stop

重启 Apache:sudo apachectl restart

查看 Apache 版本:httpd -v

2.启用 Apache 之后,在浏览器中访问 http://localhost 或 http://127.0.0.1,如果出现“It works!”就表示运行正常。

目录

OS X 中默认有两个目录可以直接运行你的 Web 程序,一个是系统级的 Web 根目录,一个是用户级的根目录,大家记下即可。

注:以下 levbf 为用户名,需要按实际修改。

Apache系统级的根目录及对应网址是:

/Library/WebServer/Documents/ http://localhost

用户级的根目录及对应网址是:

~/Sites http://localhost/~levbf/

~/Sites 也就是你用户目录下面的”站点”目录,在 OS X 中,这个目录可能没有,所以你需要手动建立一个同名目录。

建立方式很简单,直接在终端中运行:

sudo mkdir ~/Sites

站点:/etc/apache2/users/levbf.conf

权限:sudo chmod 755 /etc/apache2/users/levbf.conf

重启:sudo apachectl restart

访问:http://localhost/~levbf/

e.g:

http://192.168.6.207/~levbf/index.html

192.168.6.207为本机IP

更改根目录

文件夹需要有执行权限x,设置了755:

mkdir /Users/user/workspace 

chmod 755 /User/user/workspace

把/etc/apache2/httpd.conf文件里的 /Library/WebServer/Documents/ 都替换成自己的路径,比如 /User/user/workspace

重启Apache:apachectl restart,再次访问localhost即显示的是更改后的文件里的内容了。

参考资料:

Mac OS X 配置 Apache+Mysql+PHP 详细教程    http://jingyan.baidu.com/article/0aa22375b553a488cc0d64b5.html

相关文章

网友评论

    本文标题:Mac OS X 配置 Apache

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