http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html

用自带的

sudo apachectl -v

sudo apachectl start

sudo apachectl stop

sudo apachectl restart

web默认目录在/Library/WebServer/Documents/

设置虚拟主机

  1. 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件
  2. 在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“”,保存并退出。
  3. 运行“sudo apachectl restart”,重启Apache后就开启了虚拟主机配置功能。
  4. 运行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,就打开了配置虚拟主机文件httpd-vhost.conf,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "/usr/docs/dummy-host.example.com"
        ServerName dummy-host.example.com
        ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
        CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
    </VirtualHost>
     
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host2.example.com
        DocumentRoot "/usr/docs/dummy-host2.example.com"
        ServerName dummy-host2.example.com
        ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
        CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    </VirtualHost>

    而实际上,这两个虚拟主机是不存在的,在没有配置任何其他虚拟主机时,可能会导致访问localhost时出现如下提示:

    Forbidden
    You don't have permission to access /index.php on this server

    最简单的办法就是在它们每行前面加上#,注释掉就好了,这样既能参考又不导致其他问题。

  5. 增加如下配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <VirtualHost *:80>
        DocumentRoot "/Library/WebServer/Documents"
        ServerName localhost
        ErrorLog "/private/var/log/apache2/localhost-error_log"
        CustomLog "/private/var/log/apache2/localhost-access_log" common
    </VirtualHost>
     
    <VirtualHost *:80>
        DocumentRoot "/Users/snandy/work"
        ServerName mysites
        ErrorLog "/private/var/log/apache2/sites-error_log"
        CustomLog "/private/var/log/apache2/sites-access_log" common
        <Directory />
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride None
                    Order deny,allow
                    Allow from all
          </Directory>
    </VirtualHost>

    保存退出,并重启Apache。

最新文章

  1. c#延迟加载
  2. 基于Ruby的watir-webdriver自动化测试方案与实施(三)
  3. 格式化用户输入的金额(处理RMB的时候适合)
  4. tomcat 多开设置 需要需改的3个端口
  5. 从零开始学习jQuery (十) jQueryUI常用功能实战
  6. linux tar 压缩解压缩
  7. Unity3D 获得GameObject组件的方法
  8. jQuery Colorbox是一款弹出层
  9. python专题-函数式编程
  10. HTML5基础篇章1
  11. PhpStorm中报 “Cannot run program git.exe, 系统找不到指定的文件” 
  12. U8g2库I2C总线再次突破性调试成功
  13. 一个特殊的List去重问题的解决方案
  14. 深入剖析Kubernetes学习笔记:开篇词(00)
  15. 结合源码浅谈Spring容器与其子容器Spring MVC 冲突问题
  16. Sqlserver 数据库定时自动备份
  17. Dockerfile 收集
  18. Component 组件props 属性设置
  19. Linux软中断、tasklet和工作队列
  20. linux虚拟机更改时区

热门文章

  1. SQLite的sqlite_sequence表
  2. ie下li标签中span加float:right不换行问题解决方案
  3. Java调用Python程序
  4. Engine中如何实现鼠标滚轮缩放反置?
  5. OpenGL - Tessellation Shader 【转】
  6. python 工具mouse_find 鼠标定位
  7. sql的一些知识_通配符
  8. Android自己定义控件
  9. 学会读懂 MySql 的慢查询日志
  10. HDU ACM 1073 Online Judge -&amp;gt;字符串水题