macOS 中已经内置了 PHP、Python、Ruby、Perl 等常用的脚本语言,以及 Apache HTTP 服务器,所以使用起来非常方便。本文以最新的 macOS Sierra 10.12 配置 MAMP 开发环境为例,本文同样适用其它 macOS 版本的配置,macOS Sierra 10.12 中内置的 PHP 版本为 5.6。
一、配置Apache
macOS Sierra 已内置 Apache 服务器,不需要我们自己编译安装,只需开启 Apache 即可使用。
开关服务
可以通过如下命令进行开启、关闭以及重启:
$sudo apachectl start | stop | restart
开启后,打开浏览器,访问http://localhost/index.html.en如果出现It works!,则 Apache 可以正常使用。
修改配置
配置文件在 /etc/apache2/httpd.conf 文件中,如果需要配置,修改该文件重启即可。比如咱们对如下配置项进行修改:
#. 默认 Web 根目录配置项为:
DocumentRoot "/Library/WebServer/Documents"
我们修改为当前宿主目录下的webroot目录(我的账号为sean),修改后为:
DocumentRoot "/Users/sean/webroot"
还可以修改目录的相关权限:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all</