apache 在终端中进入apache所在目录
cd /etc/apache2
sudo 表示用管理员权限
备份apache2配置文件
sudo cp http.conf http.conf.bak
还原apache2配置文件
sudo cp http.conf.bak http.conf
# 编辑http.conf 不能使用粘贴
$ sudo vim http.conf
# 查找 DocumentRoot
/DocumentRoot
#将一下两行中的目录 ,替换成在Finder中新建的目录
#例如在 用户目录下 新建的 Sites
# mkdir ~ Sites
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/Webserver/Documents">
DocumentRoot "/Users/userName/Sites"
<Directory "/Users/userName/Sites">
#进入编辑模式
i
#向下找到
Options FollowSymLinks Multiviews
加一个单词
Options Indexes FollowSymLinks Multiviews
#进入命令模式 esc
# 查找PHP配置项
/php
去掉php前的#
$sudo cp /etc/php.ini.default /etc/php.ini
# 启动apache服务器
$ sudo apachectl -k start
#停止apache服务器
$ sudo apachectl -k stop
#重启apache服务器
$ sudo apachectl -k restart
如果 启动apache的时候提示这个错误:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
回到http.conf 文件 修改下
原始的ServerName 被#号注释着 修改成?这样的 就改成本机地址;
ServerName 127.0.0.1:80