<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mark Kirby - Mobile Developer &#187; PHP</title>
	<atom:link href="http://mark-kirby.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mark-kirby.co.uk</link>
	<description>I&#039;m a user focused mobile developer, here is where I publish advice and thoughts on building great mobile apps</description>
	<lastBuildDate>Thu, 01 Mar 2012 16:56:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting up virtual hosts on OS X Leopard to Lion</title>
		<link>http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/</link>
		<comments>http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 18:51:07 +0000</pubDate>
		<dc:creator>kirby.mark</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/</guid>
		<description><![CDATA[Here is a definitive guide to setting up virtual hosts on OS X, the instructions work on all versions from Leopard to Lion/Mountain Lion. If you have lots of sites to test, you might want to be able to type a url into the browser, and see the site directly. To do that you need...]]></description>
			<content:encoded><![CDATA[<p>Here is a definitive guide to setting up virtual hosts on OS X, the instructions work on all versions from Leopard to Lion/Mountain Lion.</p>
<p>If you have lots of sites to test, you might want to be able to type a url into the browser, and see the site directly. To do that you need to modify your Mac&#8217;s hosts file, and set up a Virtual Server.</p>
<p><em>Updated Feb 2012</em></p>
<h2>Preparation</h2>
<p>Decide upon the URL you want to use, I&#8217;m going for mark-kirby.dev in this example.</p>
<p>Decide where you want the files to go that will appear for this url, and place them there on your computer. I&#8217;m using /Users/username/Sites/mark-kirby for this example.</p>
<p>Start apache:</p>
<ol>
<li>Go to system preferences</li>
<li>Select &#8220;sharing&#8221;</li>
<li>Check the box &#8220;Web Sharing&#8221; &#8211; apache will start</li>
</ol>
<h2>2 &#8211; Edit the hosts file</h2>
<p>Open the file</p>
<pre class="brush: bash; title: ; notranslate">
/private/etc/hosts
</pre>
<p>Since this file is hidden, you will need to need to check the option &#8220;open hidden files&#8221; if your text editor has one, or use the terminal to open the file directly.</p>
<pre class="brush: bash; title: ; notranslate">
mate /private/etc/hosts
</pre>
<p>Alternatively, you could:</p>
<ol>
<li>Open finder</li>
<li>click on go</li>
<li>select &#8220;Go to folder&#8221;</li>
<li>enter in /private/etc/</li>
</ol>
<p>You will see the following:</p>
<pre class="brush: bash; title: ; notranslate">
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost
255.255.255.255    broadcasthost
::1             localhost
</pre>
<p>Underneath this, enter your local IP address (127.0.0.1) and the name of the site you want to set up, e.g.</p>
<pre class="brush: bash; title: ; notranslate">
127.0.0.1 mark-kirby.dev
</pre>
<p>Save the file &#8211; you will have to authenticate &#8211; and now when ever you type http://mark-kirby.dev into a browser it will give you your local folders &#8211; EVEN if mark-kirby.dev is an actual website on the internet. Browsers always check the hosts file first.</p>
<h2>Add the virtual host in apache</h2>
<p>If you type mark-kirby.dev into your browser now, you will still see your default folders, you need do some more work.</p>
<p>Open the file</p>
<pre class="brush: bash; title: ; notranslate">
/private/etc/apache2/extra/httpd-vhosts.conf
</pre>
<p>using the methods described above.</p>
<p>You will see this first -</p>
<pre class="brush: bash; title: ; notranslate">
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
</pre>
<p>Don&#8217;t touch it!</p>
<p>Then you will see this -</p>
<pre class="brush: bash; title: ; notranslate">
&lt;VirtualHost *:80&gt;
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot &quot;/usr/docs/dummy-host.example.com&quot;
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog &quot;/private/var/log/apache2/dummy-host.example.com-error_log&quot;
    CustomLog &quot;/private/var/log/apache2/dummy-host.example.com-access_log&quot; common
&lt;/VirtualHost&gt;
</pre>
<p>First I&#8217;ll quickly explain what each line means:</p>
<ul>
<li>ServerAdmin &#8211; the email address of the server admapachestrator e.g. mark-kirby@mark-kirby.dev, this will show up on error pages</li>
<li>DocumentRoot &#8211; the location of the files to show e.g. /User/username/Sites/mark-kirby</li>
<li>ServerName &#8211; the domain name you want to use e.g mark-kirby.dev</li>
<li>ServerAlias &#8211; an alternative name which will point to the same place e.g. www.mark-kirby.dev</li>
<li>ErrorLog &#8211; the location of a log file to output errors to, e.g. &#8220;/User/username/Sites/logs/mark-kirby-error-log&#8221;</li>
<li>CustomLog &#8211; the location of a file where all other logs should be written, followed by a format &#8211; just stick with common &#8211; e.g. &#8220;/User/username/Sites/logs/mark-kirby-access-log common&#8221;</li>
</ul>
<p>So really, you only need DocumentRoot and ServerName if this is a test server only you will access.</p>
<p>Firstly comment out the examples &#8211; very important, don&#8217;t miss this step!</p>
<p>Then add a default entry so localhost will still take you to the root of your Sites folder:</p>
<pre class="brush: bash; title: ; notranslate">
&lt;VirtualHost *:80&gt;
	DocumentRoot &quot;/Users/username/Sites&quot;
	ServerName localhost
&lt;/VirtualHost&gt;
</pre>
<p>Finally, add your entry, e.g.</p>
<pre class="brush: bash; title: ; notranslate">
&lt;VirtualHost *:80&gt;
	DocumentRoot &quot;/Users/username/Sites/mark-kirby&quot;
	ServerName mark-kirby.dev
&lt;/VirtualHost&gt;
</pre>
<p>Save this, you&#8217;ll need to authenticate.</p>
<h2>Set Permissions on your sites folder</h2>
<p>Thanks to <a href="http://adactio.com/journal/1395">Jeremy Keiths solution</a> &#8211; we can ensure permissions are set to allow all sites to be viewed without setting them on each one. This is great for our purposes, but would never be used on a live server.</p>
<p>Add this to your vhosts file:</p>
<pre class="brush: bash; title: ; notranslate">
&lt;Directory /Users/*/Sites/&gt;
    Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
&lt;/Directory&gt;
</pre>
<h2>Activate virtual hosts in apache</h2>
<p>If you haven&#8217;t done so, by default the file you just edited, won&#8217;t be enabled in Apache.</p>
<p>To change this open up another hidden file &#8211; /private/etc/apache2/httpd.conf</p>
<p>Find the line</p>
<pre class="brush: bash; title: ; notranslate">
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
</pre>
<p>And uncomment the include so it looks like this:</p>
<pre class="brush: bash; title: ; notranslate">
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
</pre>
<p>Save the file &#8211; you may need to authenticate.</p>
<h2>Restart Apache</h2>
<p>This still won&#8217;t work, until you restart apache.</p>
<p>To restart apache:</p>
<ol>
<li>Go to system preferences</li>
<li>Select &#8220;sharing&#8221;</li>
<li>Uncheck the box &#8220;Web Sharing&#8221; &#8211; apache will stop</li>
<li>Check it again &#8211; apache will start</li>
</ol>
<p>or&#8230;</p>
<pre class="brush: bash; title: ; notranslate">
sudo apachectl restart
</pre>
<p>Test your site &#8211; you should be in luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
	</channel>
</rss>

