HOW TO:设置一个虚拟主机上的Apache 2.4.4 [MAC / * NIX] [英] HOW TO: Set up a Virtual Host on Apache 2.4.4 [ MAC / *NIX ]

查看:173
本文介绍了HOW TO:设置一个虚拟主机上的Apache 2.4.4 [MAC / * NIX]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我张贴这一点,因为我最近有很多麻烦建立一个虚拟主机与MAMP栈,由于在Mac OS 10.8的默认的Apache2安装可用的PHP版本苹果公司的限制。

这是什么做的非常快速指南,我欠的解决方案堆栈溢出这样的问题:

您可以认为这是什么工作对我来说,作为公认的答案,都没有效果,但是汇编,而那些有显著得分越低。

同样,我每次看到导游未能提一些要点,回答用户使用上了源代码的问题。


解决方案

第1步:安装和配置Apache

请确保您指定要监听的端口,对于我来说我指定的 8080 。这将是对于这一系列的指令的情况下

收听8080 - 默认为80

第二步:修改 / etc / hosts中文件欺骗你的环回地址127.0.0.1

  127.0.0.1本地主机
127.0.0.1 some.example#域name.domain-TLD
127.0.0.1 www.some.example#同为上面的行,但以www。 prefixed

你真的应该在Web服务器上添加子域一个手柄,Apache或Nginx的(或者你使用任何其他。东西路线WWW到非www。

第三步:启用虚拟主机导入在Apache


  1. 打开位于的Apache2的子目录中的的httpd.conf 文件。 一般于 / conf目录

  2. 取消注释类似的行:包含的conf /额外/的httpd-vhosts.conf

  3. 还要取消该模块导入:的LoadModule log_config_module模块/ mod_log_config.so

第四步:配置您的虚拟主机文件

<醇开始=4>
  • 找到您的虚拟主机的配置,的httpd-vhosts.conf ,您可以在文件中注释掉两个示例虚拟主机。 通常 / conf目录内/外

  • 您自己的虚拟主机从该模板复制到该文件:


  •  &LT;虚拟主机*:80&GT; #修改80 Apache2的听S上的号码。以我为例,8080
        服务器名称服务器的地址#例如mywebsite.local
        ServerAlias​​ 92展览-ADDRESS#例如www.mywebsite.local
        DocumentRoot的服务器的文件-ROOT#例如用户/用户名/网站
            &LT;目录/&GT; #这应该是一个完整的路径,但
                要求所必需的权限错误授予所有#
                选择指数包括了FollowSymLinks ExecCGI
                没有的AllowOverride
            &LT; /目录&GT;
    &LT; /虚拟主机&GT;


    您就大功告成了!

    一旦你的虚拟主机已被编辑根据自己的喜好设置完成后,只是重新启动Apache和享受。

    本指南已经包括实施的解决方法,但在情况下,你仍然可以得到权限错误:


    • 您必须确保你的的DocumentRoot 不是你的用户明确地拥有任何文件里面。如果它需要,给Mac上的只读进入所有人该特定文件夹,例如文档或电影等...

    I am posting this because I recently had a lot of trouble setting up a Virtual Host with a MAMP stack, due to Apple's throttling of the useable PHP version on Mac OS 10.8's default Apache2 installation.

    This is a very quick guide on what to do and I owe the solution to this question on Stack Overflow:

    You can think of this as a compilation of what worked for me, as the accepted answers had no effect, but rather those with a significantly lower score.

    Similarly, every guide I have seen fails to mention some points which users answered with on the sourced question.

    解决方案

    Step 1: Install and configure Apache.

    Make sure you specify what port you want to listen on, for me I specified 8080. This will be the case for this series of instructions.

    Listen 8080 - Default is 80

    Step 2: Edit your /etc/hosts file to spoof your loopback address, 127.0.0.1

    127.0.0.1   localhost
    127.0.0.1   some.example         # domain-name.domain-TLD
    127.0.0.1   www.some.example     # The same as the above line, but with www. prefixed
    

    You should really add a handle for subdomains on your web server, Apache or Nginx (or whatever else you use. Something that routes www to non-www.

    Step 3: Enable the Virtual Hosts import on Apache.

    1. Open your httpd.conf file located within Apache2's subdirectories. Usually within /conf
    2. Uncomment the line that resembles this: Include conf/extra/httpd-vhosts.conf
    3. Also uncomment this module import: LoadModule log_config_module modules/mod_log_config.so

    Step 4: Configure your Virtual Hosts file

    1. Find your Virtual Hosts config, httpd-vhosts.conf, you can comment out the two example Virtual Hosts in the file. Usually within /conf/extra
    2. Copy your own Virtual Host into the file from this template:

    <VirtualHost *:80>                           # Change the 80 to the number Apache2 "Listen"s on. In my case, 8080
        ServerName SERVER-ADDRESS                # E.g. mywebsite.local
        ServerAlias WWW.SERVER-ADDRESS           # E.g. www.mywebsite.local
        DocumentRoot " SERVER-FILE-ROOT "        # E.g. "Users/user-name/Sites"
            <Directory />                        # This should be a full path, though
                Require all granted              # Required for permission errors
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride none
            </Directory>
    </VirtualHost>
    

    You're Done!

    Once your Virtual Host has been edited to your liking you are done, just restart Apache and enjoy.

    This guide already includes the fixes implemented, but in-case you still get permission errors:

    • You MUST make sure that your DocumentRoot is not inside any documents your user explicitly owns. If it needs to be, give "Read Only" access to "Everyone" on Mac for that particular folder, E.g. "Documents" or "Movies" etc....

    这篇关于HOW TO:设置一个虚拟主机上的Apache 2.4.4 [MAC / * NIX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆