`
uu4u
  • 浏览: 39081 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Virtual Host in Mountain Lion With Apache

 
阅读更多

Virtual Host in Mountain Lion With Apache

If you’re using Mountain Lion and have the need to setup a vhost it can be a little tricky to get the ball rolling. I’m going to do my best to detail the process that I use to set everything up. Hopefully you can use these same steps to square aware your system.

Command Line Fu!

Ok we’re going to pretty much do everything in Terminal so if that scares you now might be a good time to install MAMP instead ;)

Step 1: Enable httpd-vhosts.conf

OK first thing to do is navigate to your apache installation and open it up in your text editor of choice.

cd /etc/apache2
mate httpd.conf // you can use anything to open it up: vim, nano, etc.

You’re looking for the line:

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Remove the # to uncomment it.

It might be wrapped in a block that looks like this:

<IfDefine WEBSHARING_ON>
...
</IfDefine>

Comment out those lines using #. We want our httpd-vhosts file to always be loaded. It should look kind of like this:

#<IfDefine WEBSHARING_ON>

... a bunch of stuff ...

Include /private/etc/apache2/extra/httpd-vhosts.conf

... a buncha other stuff ...

#</IfDefine>

Step 2: Enable PHP

In the httpd.conf file search for this line:

#LoadModule php5_module libexec/apache2/libphp5.so

Remove the # so PHP will be enabled.

Step 3: Add a vhost

OK let’s add our first vhost.

mate /etc/apache2/extra/httpd-vhosts.conf

This is your list of virtual hosts. There should be some example vhosts in here. Let’s create a new one:

<VirtualHost *:80>
    ServerName mysite.dev
    DocumentRoot "/Users/Rob/Developer/mysite"
    <Directory "/Users/Rob/Developer/mysite">
        DirectoryIndex index.php index.html
        AllowOverride all
        Options -MultiViews
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

There are a few other options you can use but I’m ignoring them for now.ServerName is what we’ll be typing into our browser address bar.DocumentRoot and Directory point to the location of the project files on our hard drive. Note that DirectoryIndex will check for index.php first and then check for index.html. If you want to just use .html you can remove the bit about index.php

Step 4: Add the vhost to your hosts file

Next let’s add our new host to our hosts file.

mate /etc/hosts

You should see a line that looks like this:

127.0.0.1 localhost

Add this line underneath so it looks like this:

127.0.0.1 localhost
127.0.0.1 mysite.dev

Step 5: Restart Apache

OK let’s reboot apache!

sudo apachectl restart

Step 6: Cross your fingers!

Head over to your browser and try it out. Make sure you use http:// at the beginning or it will just try to google your hostname.

http://mysite.dev

With any luck you should see your site! If everything worked go back to terminal and paste in this line:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

That will tell apache to start whenever the system starts. A word of warning: Whenever you change anything in httpd.conf, httpd-vhosts.conf or your hosts file you’ll have to restart apache with sudo apachectl restart otherwise your changes won’t show up in the browser.

Good Luck!

分享到:
评论

相关推荐

    Apache VirtualHost配置

    NULL 博文链接:https://sandy902724921-163-com.iteye.com/blog/1808232

    MultiBeast - Mountain Lion Edition 5.5.2

    【标题】"MultiBeast - Mountain Lion Edition 5.5.2" 是一款专为苹果操作系统Mac OS X Mountain Lion 10.8.5设计的驱动工具,它主要用于解决在虚拟机环境中,如Virtual Box安装Mac OS X Mountain Lion时遇到的各种...

    Nginx 虚拟主机 VirtualHost 配置

    Nginx 虚拟主机 VirtualHost 配置

    apache2-create-virtualhost:为其他网站添加虚拟主机

    apache2-create-virtualhost 该脚本为apache2 Web服务器创建了附加的virtualhost配置。 接受2个参数,网站目录,网站域名。 只需将这两个参数添加到下面的代码片段的末尾即可。在下面运行此代码以执行脚本以启动...

    apache2-virtualhost

    apache2-virtualhost 将虚拟主机文件添加到apache2 sudo curl -o apache2-virtualhost.sh ...

    Apache中Virtual Host虚拟主机配置及rewrite参数说明

    ### Apache中Virtual Host虚拟主机配置及Rewrite参数详解 #### 一、Virtual Host虚拟主机配置 **1.1 概念介绍** 在Apache服务器中,Virtual Host(虚拟主机)技术允许在同一台物理服务器上托管多个不同的网站或Web...

    Apache VirtualHost Python:简单,快速且功能强大-开源

    Apache2 VirtualHost Python是一个非常简单且功能强大的应用程序,用于在Apache Server上创建Virtuals Host。 Apache VirtualHost Python是使用Python3创建的,与您的操作系统非常兼容。

    Frank Kane's Taming Big Data with Apache Spark and Python 【含代码】

    Frank Kane's Taming Big Data with Apache Spark and Python is your companion to learning Apache Spark in a hands-on manner. Frank will start you off by teaching you how to set up Spark on a single ...

    单台服务器中利用Apache的VirtualHost如何搭建多个Web站点详解

    本文将详细记录一下如何在单台服务器上,利用apache的virtualhost(虚拟主机)来搭建多个不同的web站点,并且每个站点独立管理自己的session,下面话不多说了,来一起看看详细的介绍吧。 开发环境 先说下我各项开发...

    VirtualHost 用IIS架构虚拟主机

    VirtualHost说明文档 一、运行环境 操作系统Window XP/Window Server 2000/Window Server 2003/Window Server 2008 IIS 版本:IIS 5.0 / IIS 6.0 二、功能说明 本程序的功能是,在一台服务器、一个IP地址的...

    apache 设置主机头,同一端口绑定多个域名和网站

    该指令告诉Apache服务器监听哪些端口或IP地址上的请求,并将其与后续的`&lt;VirtualHost&gt;`指令关联起来。 2. **VirtualHost**: 这是一个容器,在其中可以定义特定于网站的配置信息。例如,文档根目录、服务器名等。 ...

    CentOS配置虚拟主机virtualhost使服务器支持多网站多域名的方法

    这通常通过使用Apache的虚拟主机(VirtualHost)功能实现。虚拟主机允许在一个单一的服务器上运行多个独立的网站,每个网站对应一个不同的域名或子域名。以下是详细的配置步骤和注意事项: 1. **启用VirtualHost...

    基于C的Nginx Virtual Host A/B Testing设计源码

    本源码是基于C开发的Nginx Virtual Host A/B Testing设计,包含91个文件,其中包括29个.json文件,19个.h文件,以及19个.c文件。此外,还包括4个.md文件,3个.yml文件,以及3个.py文件。此外,还包括2个.gitignore...

    virtualhost:Bash脚本可轻松在ubuntu上创建或删除apache虚拟主机

    $ sudo cp /path/to/virtualhost.sh /usr/local/bin/virtualhost 对于全球快捷方式 $ cd /usr/local/bin $ wget -O virtualhost https://raw.githubusercontent.com/RoverWire/virtualhost/master/virtualhost.sh $ ...

    VirtualHost.sh

    使用域名访问网页的非交互式sh脚本文件(下载后,将文件放入Linux环境中,sh VirtualHost.sh命令即可运行成功,验证结果:将IP设为192.168.37.X网段,DNS设为192.168.37.100,通过浏览器输入域名即可访问成功)

    CentOS下Apache配置多域名或者多端口映射

    与多域名映射类似,我们需要为每个端口创建 `&lt;VirtualHost&gt;` 条目。例如,我们可以使用 8080 端口来访问 `website3.com`: ```apache &lt;VirtualHost *:8080&gt; DocumentRoot /var/www/html/website3 ServerName ...

    apache配置虚拟主机

    要避免这种情况,需要保留一个默认的`VirtualHost`配置,不指定任何IP地址和端口,这样Apache会将所有未匹配的请求转发给这个默认的虚拟主机。例如: ```apacheconf &lt;VirtualHost *:80&gt; DocumentRoot /var/...

    Complete Virtual Reality and Augmented Reality Development with Unity-2019.epub

    Complete Virtual Reality and Augmented Reality Development with Unity by Jesse Glover Jonathan Linowes Packt Publishing English 2019-04-17 668 pages Details Title: Complete Virtual Reality and ...

    Apache NameVirtualHost *:80 has no VirtualHosts问题解决办法

    这个错误是由于Apache无法找到任何与NameVirtualHost指令匹配的VirtualHost配置。 首先,让我们深入理解一下`NameVirtualHost`和`VirtualHost`这两个概念: 1. **NameVirtualHost**: 这个指令告诉Apache启用基于...

Global site tag (gtag.js) - Google Analytics