启动Apache

有两种方法:

  • 打开“系统设置偏好(System Preferences)” -> “共享(Sharing)” -> “Web共享(Web Sharing)”
  • 打开“终端(terminal)”,然后
  • 运行“sudo apachectl start”,再输入帐号密码,这样Apache就运行了。
  • 运行“sudo apachectl -v”,你会看到Mac OS X 10.6.3中的Apache版本号:
    Server version: Apache/2.2.14 (Unix)
    Server built: Feb 11 2010 14:40:31

    这样在浏览器中输入“http://localhost”,就可以看到出现一个内容为“It works!”的页面,它位于“/Library(资源库)/WebServer/Documents/”下,这是Apache的默认根目录。

    注意:开启了Apache就是开启了“Web共享”,这时联网的用户就会通过“http://[本地IP]/”来访问“/Library(资源库)/WebServer/Documents/”目录,通过“http://[本地IP]/~[用户名]”来访问“/Users/[用户名]/Sites/”目录,可以通过设置“系统偏好设置”的“安全(Security)”中的“防火墙(Firewall)”来禁止这种访问。

    设置虚拟主机

  • 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件
  • 在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,保存并退出。
  • 运行“sudo apachectl restart”,重启Apache后就开启了它的虚拟主机配置功能。
  • 运行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,这样就打开了配置虚拟主机的文件httpd-vhost.conf,配置你需要的虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机:
    <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

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

  • 增加如下配置
    <VirtualHost *:80>
    DocumentRoot "/Users/[用户名]/Sites"
    ServerName sites
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
    </VirtualHost>

    保存退出,并重启Apache。

  • 运行“sudo vi /etc/hosts”,打开hosts配置文件,加入”127.0.0.1 sites“,这样就可以配置完成sites虚拟主机了,这样就可以用“http://sites”访问了,其内容和“http://localhost/~[用户名]”完全一致。

    这是利用Mac OS X 10.6.3中原生支持的方式来实现的配置,也可以参考“”和“”。实际上,你还可以使用XAMPP或MacPorts这种第三方提供的集成方案来实现简单的安装和使用。

在Mac OS X中配置Apache的更多相关文章

  1. 在Mac OS X中配置Apache + PHP + MySQL

    在Mac OS X中配置Apache + PHP + MySQL Mac OS X 内置Apache 和 PHP,使用起来非常方便.本文以Mac OS X 10.6.3和为例.主要内容包括: 启动Ap ...

  2. 在Mac OS X中配置Apache + PHP + MySQL 很详细

    这是一篇超级详细的配置mac os下面php+mysql+apache的文章.非常详细我的大部分配置就是参考上面的内容的,比如,PHP不能连接数据库,就是改一下默认的php.ini中pdo_mysql ...

  3. Mac OS X中配置Apache

    我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境. 启动Apache 设置虚拟主机 启动Apache 打开“终端(terminal)”,输入 sudo apachectl -v ...

  4. (转)Mac OS X中配置Apache

    我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境. 启动Apache 设置虚拟主机 启动Apache 打开“终端(terminal)”,输入 sudo apachectl -v ...

  5. Mac OS X中配置Apache后提示You don't have permission to access / on this server

    根据这篇博客http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html,在mac系统中,配置的apache,配置完成后,提示 You d ...

  6. 在Mac OS X 10.8中配置Apache + PHP + MySQL

    在Mac OS X 10.8中配置Apache+PHP+MySQL的内容包括: 配置Apache 配置PHP 安装MySQL 配置PHPAdmin 设置数据库默认字符集 一. 配置Apache 1. ...

  7. 在Mac OS X 10.8中配置Apache+PHP+MySQL

    在Mac OS X 10.8中配置Apache+PHP+MySQL的内容包括: 配置Apache 配置PHP 安装MySQL 配置PHPAdmin 设置数据库默认字符集 一. 配置Apache 1. ...

  8. 【转】在Mac OS X 10.8中配置Apache + PHP + MySQL

    CHENYILONG Blog 在Mac OS X 10.8中配置Apache + PHP + MySQL 在Mac OS X 10.8中配置Apache+PHP+MySQL的内容包括: 配置Apac ...

  9. Mac OS X中,有三种方式来实现启动项的配置

    Mac OS x 启动项设置 Mac OS X的启动原理: 1,mac固件激活,初始化硬件,加载BootX引导器. 2,BootX加载内核与内核扩展(kext). 3,内核启动launchd进程. 4 ...

随机推荐

  1. 聊一下JS中的作用域scope和闭包closure

    聊一下JS中的作用域scope和闭包closure scope和closure是javascript中两个非常关键的概念,前者JS用多了还比较好理解,closure就不一样了.我就被这个概念困扰了很久 ...

  2. Android开发艺术探索读书笔记——01 Activity的生命周期

    http://www.cnblogs.com/csonezp/p/5121142.html 新买了一本书,<Android开发艺术探索>.这本书算是一本进阶书籍,适合有一定安卓开发基础,做 ...

  3. UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout

    1,UIView的setNeedsDisplay和setNeedsLayout方法 首先两个方法都是异步执行的.而setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到  UI ...

  4. linux后台进程管理工具supervisor

    Linux的后台进程运行有好几种方法,例如nohup,screen等,但是,如果是一个服务程序,要可靠地在后台运行,我们就需要把它做成daemon,最好还能监控进程状态,在意外结束时能自动重启. su ...

  5. 异步数据库查询 Z

    Introduction Microsoft .NET 4.5 introduced new "async and await" methods to provide an eas ...

  6. Django进阶篇(一)

    Form django中的Form一般有两种功能: 1.输入html 2.验证用户输入 最简易的form验证: <!DOCTYPE html> <html lang="en ...

  7. No.3__C#

    起步的迷思 周二:今天起来,天上下着小雨,气温降低了许多.从上周的二十多度又回到了七八度的样子.多穿了一件衣服,顶着寒风就出门了,确实是有点冷.到了公司,已经八点四十几了.有些小疲倦,头晕晕沉沉的,不 ...

  8. 38. Same Tree && Symmetric Tree

    Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...

  9. sql 2008 R2添加对MySql的远程服务器链接

    (1).我的sql 2008 R2所在的系统为Windows server 2008 *64 (2).MySQL所在的系统为Windows server 2003 *86 我想要实现的是在sql 20 ...

  10. jQuery实现抖动效果

    //抖动效果 //intShakes:抖动次数:intDistance:抖动左右距离:intDuration:持续时间 jQuery.fn.shake = function (intShakes, i ...