//查看apache版本号
apachectl -v
//检查apache配置文件是否正确
apachectl -t
OSX yosemite 10.10.4
apache Apache/2.4.10 (Unix)
sudo vim /etc/apache2/httpd.conf
将前面的#去掉
#LoadModule deflate_module libexec/apache2/mod_deflate.so
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
#LoadModule php5_module libexec/apache2/libphp5.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
#Include /private/etc/apache2/extra/httpd-vhosts.conf
创建根目录
mkdir ~/Sites
将默认根目录下面的index.html拷贝到根目录下
cp /Library/WebServer/Documents/index.html.en ~/Sites/
修改Root文件位置
sudo vim /etc/apache2/httpd.conf
修改如下,将“/Library/WebServer/Documents”改为你的文件根目录(Mac是用户名)
#DocumentRoot "/Library/WebServer/Documents"
#<Directory "/Library/WebServer/Documents">
DocumentRoot "/Users/Mac/Sites"
<Directory "/Users/Mac/Sites">
执行
apachectl -t
如果出现错误
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Mac.local. Set the 'ServerName' directive globally to suppress this message
则将httpd.conf中的
#ServerName www.example.com:80
改为
ServerName localhost:80