zoukankan      html  css  js  c++  java
  • Mac 中配置Apache

    使用的mac版本是10.10.1,mac自带的Apache环境

    分为两部分:

    1、启动Apache

    2、设置虚拟主机

    启动Apache

    打开终端,

    >>sudo apachectl -v,如有机器密码会需要输入密码。

    >>sudo apachectl start ,即启动Apache

    验证是否开启Apache,在浏览器中输入“http://localhost”,如页面显示“It works”,即开启成功。其位于 /Library/WebServer/Documents下。

    Apache的安装目录在/etc/apache2,etc默认是隐藏的,在终端输入open /etc即可查看。

    设置虚拟主机

    >>sudo vi /etc/apache2/httpd.conf,打开Apache的配置文件

    >>找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉“#”,保存退出。

    >>sudo apachectl restart,重启apache服务,开启虚拟主机配置功能

    >>sudo vi /etc/apache2/extra/httpd-vhosts.conf,打开配置虚拟主机文件httpd-vhosts.conf,需要注意的是:该文件中默认开启了两个作为例子的虚拟主机

    而实际上,这两个虚拟主机是不存在的,在没有配置任何其他虚拟主机时,可能会导致访问localhost时出现:Forbidden,You don't have permission to access /index.php on this server

    最简单的办法就是将它们注释掉。

    增加如下配置:

    <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/erao/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
              Require all granted
          </Directory>
    </VirtualHost>

    需要注意的是DocumentRoot里,需要写本机的主机名,也要提前新建好work文件夹。

    Require all granted,否则无论怎么访问都是403。

    保持退出,重启Apache服务

    >>sudo vi /etc/hosts,打开hosts配置文件,加入“127.0.0.1 mysites”,这样就可以配置sites虚拟主机了,访问“http://mysites”即可。

    错误日志放在/private/var/log/apache2/sites-error_log。

    参考于:http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html#;

        http://ylw6006.blog.51cto.com/470441/965119

  • 相关阅读:
    php实现拼图滑块验证的思考及部分实现
    【php设计模式】门面模式
    【php设计模式】装饰器模式
    php 如何将image图片转化为字符串(GD库操作及imagick两种实现方式)
    【php设计模式】组合模式
    【php设计模式】桥接模式
    深拷贝和浅拷贝
    【php设计模式】适配器模式
    【php设计模式】建造者模式
    Java50道经典习题-程序29 求矩阵对角线之和
  • 原文地址:https://www.cnblogs.com/fun0623/p/4709506.html
Copyright © 2011-2022 走看看