轉自:https://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/
編輯你的 apache 配置文件:
vim /etc/apache2/httpd.conf
去掉這一行的注釋:
Include /peivate/etc/apache2/extra/httpd-vhosts.conf
這時,apache 將會加載 httpd-vhosts.conf 這個配置文件
編輯httpd-vhost.conf 配置文件:
vim /etc/apache2/extra/http-vhosts.conf
這里給一個例子:
<VirtualHost *:80> DocumentRoot "/Users/Jason/Documents/workspace/dev" ServerName jason.local ErrorLog "/private/var/log/apache2/jason.local-error_log" CustomLog "/private/var/log/apache2/jason.local-access_log" common <Directory "/Users/Jason/Documents/workspace/dev"> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>上面的配置表明,我可以通過訪問http://jason.local 訪問到本地的/User/Json/Documemts/workspace/dev 下的文件,
重啟apache:apachectl restart
最后一步,編輯hosts文件:
vim /etc/hosts
添加:127.0.0.1 json.local
運行以下命令清除DNS緩存:dscacheutil -flushcache
如果你想驗證配置文件是否有錯誤,運行:apachectl configtest
