<?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'm a user focused mobile developer, here is where I publish advice and thoughts on building great mobile apps</description>
	<lastBuildDate>Thu, 29 Jul 2010 10:18:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up virtual hosts on OS X Leopard</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[A couple of months ago I explained how to set up PHP 5 on OS X Leopard &#8211; it was very easy! We also configured PHP so that the default folder was your Users/home folder, instead of Library/Webserver.
If you have lots of sites to test, you might want to be able to type a url [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago I explained how to set up PHP 5 on OS X Leopard &#8211; it was very easy! We also configured PHP so that the default folder was your Users/home folder, instead of Library/Webserver.</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>
<h2>1 &#8211; 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>
<h2>2 &#8211; Edit the hosts file</h2>
<p>Open the file</p>
<pre>[code lang="apache"]/private/etc/hosts[/code]</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>[code lang="apache"]mate /private/etc/hosts[/code]</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>[code lang="apache"]##
# 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[/code]</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>[code lang="apache"]127.0.0.1 mark-kirby.dev[/code]</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>2 &#8211; 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>[code lang="apache"]/private/etc/apache2/extra/httpd-vhosts.conf[/code]</pre>
<p>using the methods described above.</p>
<p>You will see this first -</p>
<pre>[code lang="apache"]#
# Use name-based virtual hosting.
#
NameVirtualHost *:80[/code]</pre>
<p>Don&#8217;t touch it!</p>
<p>Then you will see this -</p>
<pre>[code lang="apache"]
<virtualhost *:80 >
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/www/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.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>[/code]</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>[code lang="apache"]<virtualhost *:80 >
DocumentRoot "/Users/username/Sites"
ServerName localhost
</virtualhost>[/code]</pre>
<p>Finally, add your entry, e.g.</p>
<pre>[code lang="apache"]<virtualhost *:80 >
DocumentRoot "/Users/username/Sites/mark-kirby"
ServerName mark-kirby.dev
</virtualhost>[/code]</pre>
<p>Save this, you&#8217;ll need to authenticate.</p>
<h2>3 &#8211; 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>[code lang="apache"]# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf[/code]</pre>
<p>And uncomment the include so it looks like this:</p>
<pre>[code lang="apache"]# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf[/code]</pre>
<p>Save the file &#8211; you may need to authenticate.</p>
<h2>4 &#8211; 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>Test your site &#8211; you should be in luck!</p>
<h2>5 &#8211; Permission problems</h2>
<p>If you have any problems with permissions on your new site, you could try <a href="http://adactio.com/journal/1395">Jeremy Keiths solution</a> &#8211; he adds a directive to his httpd-vhosts.conf file which allows everything, it looks like this:</p>
<p>[code lang="apache"]<br />
<directory /Users/*/Sites/><br />
Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews<br />
AllowOverride All<br />
Order allow,deny<br />
Allow from all<br />
</directory><br />
[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://mark-kirby.co.uk/2008/setting-up-virtual-hosts-on-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
	</channel>
</rss>
