<?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>themattharris.com &#187; Web Development</title>
	<atom:link href="http://themattharris.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://themattharris.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 01 Jun 2010 17:30:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using local mail (/var/mail/user)</title>
		<link>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Fusing-local-mail-varmailuser%2F&amp;seed_title=Using+local+mail+%28%2Fvar%2Fmail%2Fuser%29</link>
		<comments>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Fusing-local-mail-varmailuser%2F&amp;seed_title=Using+local+mail+%28%2Fvar%2Fmail%2Fuser%29#comments</comments>
		<pubDate>Tue, 16 Jun 2009 13:06:37 +0000</pubDate>
		<dc:creator>themattharris</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[movemail]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://themattharris.com/?p=325</guid>
		<description><![CDATA[When developing websites it is quite common for there to be some kind of contact form or other mailing function. The problem is that should you, like me, have your email being forwarded through Google Mail you will find those emails never get to your Google address. The reason for this is simple, your computer [...]]]></description>
			<content:encoded><![CDATA[<p>When developing websites it is quite common for there to be some kind of contact form or other mailing function.  The problem is that should you, like me, have your email being forwarded through Google Mail you will find those emails never get to your Google address.  The reason for this is simple, your computer is not recognised as a legitimate SMTP server so Google rejects the mail.  The good news is you can instead tell your Website to send the emails to your local computer instead.<span id="more-325"></span></p>

<p>Very simply you just need to give the website you are testing the email address <code>username@computername.local</code>. For example my username is <code>matt</code> and my computer is called <code>tribble-mbp</code> so my email would be <code>matt@tribble-mbp.local</code>. Alternatively you can instead use the computer name as <code>localhost</code> making the email<code>matt@localhost</code>.</p>

<p>Once you have the email set to your local machine you can use the built in <strong>mail</strong> program in MacOS.</p>

<h2>Using command line mail</h2>

<p>To use mail you need to fire up the Terminal.app (Finder > Go > Utilities > Terminal) and type <code>mail</code>. Most of the time you will be presented with a very boring response similar to this:</p>

<p><pre class="brush: plain;">No mail for matt</pre></p>

<p>If you do have mail you will instead see an interactive prompt similar to this:</p>

<p><pre class="brush: plain;">&gt;N  1 matt@tribble-mbp.loc  Tue Jun 16 10:40  14/493   &quot;Test&quot;
? </pre></p>

<p>This is your mailbox, and in my case shows I have 1 new message from matt@tribble-mbp.loc(al) which was sent on Tuesday June 16 at 10:20. The subject of the message is &#8220;Test&#8221;. This is helpful but how do I view the message?</p>

<h2>Handy mail commands</h2>

<table>
<tr>
<th>Command</th>
<th>Purpose</th>
</tr>
<tr>
<td><code>1</code> (or any other number)</td>
<td>Display the message with the ID equal to 1</td>
</tr>
<tr>
<td><code>help</code></td>
<td>Display the help screen</td>
</tr>
<tr>
<td>h</td>
<td>List the headers of the emails </td>
</tr>
<tr>
<td>d1</td>
<td>Delete message 1 (warning this is instant, there is no confirmation step)</td>
</tr>
<tr>
<td>d1-10</td>
<td>Delete messages 1 through 10</td>
</tr>
<tr>
<td>q</td>
<td>Quit mail</td>
</tr>
</table>

<h2>Sending mail</h2>

<p>The easiest way to send mail is to use the website you are developing but, should you wish to, you can use the command line tool. The best way to understand this is an example. We&#8217;re going to send an email to ourselves with the subject &#8220;Test&#8221; and the message &#8220;What&#8217;s up doc?&#8221;. To do this fire up Terminal.app and do the following:</p>

<ul>
<li>Enter <code>mail matt@tribble-mbp.local</code> replacing <code>matt@tribble-mbp.local</code> with the correct address for you.</li>
<li>You will be prompted for the <code>Subject:</code> so enter <code>Test</code> and press enter/return.</li>
<li>It now looks like nothing is happening but in reality mail is waiting for you to enter the body of the message. On the line that has just started type <code>What's up doc?</code> but do not press enter.</li>
<li>To finish the message we have to &#8216;interrupt&#8217; the program. We do this by holding down <code>ctrl</code> on the keyboard and pressing &#8220; (sometimes you need to press it a couple of times).</li>
<li>You should find the letters <code>EOT</code> appear and the program exits. If not, release any keys you have and try pressing <code>ctrl</code> and <code>d</code> again until it does.</li>
</ul>

<p>When all is done the screen should look similar to this:</p>

<p><pre class="brush: plain;">mail matt@tribble-mbp.local
Subject: Test
What's up doc?EOT</pre></p>

<p>Great! you&#8217;ve sent your first mail. Lets take a look at it by entering <code>mail</code> in the terminal. You should find something similar to this:</p>

<p><pre class="brush: plain;">&gt;N  1 matt@tribble-mbp.loc  Tue Jun 16 10:44  14/486   &quot;Test&quot;
? 1
Message 1:
From matt@tribble-mbp.local  Tue Jun 16 10:44:10 2009
X-Original-To: matt@tribble-mbp.local
Delivered-To: matt@tribble-mbp.local
To: matt@tribble-mbp.local
Subject: Test
Date: Tue, 16 Jun 2009 10:44:10 +0100 (BST)
From: matt@tribble-mbp.local (Matt Harris)
What's up doc?</pre></p>

<p>To delete the message type <code>d1</code>, replacing the 1 with the correct ID of the message.</p>

<h2>Sending attachments</h2>

<p>Sending attachments is again something you would probably want to do using your web application however it is quite straight forward. The method here does have it&#8217;s problems with encoding but works out of the box &ndash; as this is only for development and on the local machine it&#8217;s something I&#8217;m happy living with. To send an attachment use the following command:</p>

<p><pre class="brush: plain;">uuencode /path/to/file.jpg filename-for-recipient.jpg | mail matt@tribble-mbp.local</pre></p>

<p>This will send a single message with the @file.jpg@ attached to the message. Helpful but what about sending some text with the message as well? Well, this is achieved using <code>echo</code> and the <code>|</code> technique, like this:</p>

<p><pre class="brush: plain;">(echo &quot;My message test&quot;; uuencode /path/to/file.jpg filename-for-recipient.jpg) | mail matt@localhost</pre></p>

<p>Alternatively you can send a text file as message text using the <code>cat</code> command like this:</p>

<p><pre class="brush: plain;">(cat mytextfile.txt; uuencode /path/to/file.jpg filename-for-recipient.jpg) | mail matt@localhost</pre></p>

<h2>Summary</h2>

<p>Hopefully this has been useful for you. I found it partifularly helpful for debugging this. Knowing how mail works also means you can setup automated mailings from your MacOS to yourself, such as log files or alerts.</p>

<p>When you start using mail a lot, managing messages in the command line can become quite laboured so in my next post I&#8217;ll show you how to read the command line mail using Thunderbird.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Fusing-local-mail-varmailuser%2F&amp;seed_title=Using+local+mail+%28%2Fvar%2Fmail%2Fuser%29/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Websites on Google Android</title>
		<link>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Ftesting-websites-on-google-android%2F&amp;seed_title=Testing+Websites+on+Google+Android</link>
		<comments>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Ftesting-websites-on-google-android%2F&amp;seed_title=Testing+Websites+on+Google+Android#comments</comments>
		<pubDate>Wed, 03 Jun 2009 01:14:36 +0000</pubDate>
		<dc:creator>themattharris</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[browsertesting]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://themattharris.com/?p=303</guid>
		<description><![CDATA[The other day I was developing a site for a client who wanted to be sure their new site would work on the Android platform. I don&#8217;t own a phone which runs Android so I started looking around for an emulator instead. If you do the same you&#8217;ll quickly find the Android Development website which [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was developing a site for a client who wanted to be sure their new site would work on the Android platform. I don&#8217;t own a phone which runs Android so I started looking around for an emulator instead. If you do the same you&#8217;ll quickly find the <a href="http://developer.android.com/index.html" rel="external">Android Development</a> website which holds a wealth of Android development information aswell as the <acronym title="Software Development Kit">SDK</acronym>. This is helpful but I found it wasn&#8217;t clear whether this would let me test websites or not. For this reason I&#8217;ve put together this quick how-to on getting the Android emulator running on your computer.<span id="more-303"></span></p>

<h2>What you will need</h2>

<ul>
<li>The latest <a href="http://developer.android.com/sdk/" rel="external">Android SDK</a></li>
<li>At least version 1.5 of the <a href="http://java.sun.com/javase/downloads/index.jsp" rel="external">Java Developer Kit</a>. (type @java -version@ into your terminal or command prompt to find out the version you have).</li>
<li>About 10 minutes of time</li>
</ul>

<h2>Setting Up</h2>

<ol>
<li>Follow the instructions on the Android <a href="http://developer.android.com/sdk/1.5_r2/installing.html" rel="external">SDK installation page</a> making sure you follow the steps for adding the tools directory to your path. In my case I put the SDK into <code>~/Code/Android</code> (where <code>~/</code> is my home directory).</li>
<li>Restart your command prompt or terminal and type <code>android</code>. You should be presented with the android help information. If not check you set the path correctly.</li>
</ol>

<h2>Target Platforms and Android Virtual Devices (AVDs)</h2>

<p>It is possible to create emulators (AVDs) for each version (or target) of Android. To do this we need to check which hardware targets are available and what their target ID is. If you type <code>android list targets</code> into your terminal you will be presented with something similar to the code below.
<pre class="brush: plain;">Available Android targets:
id: 1
     Name: Android 1.1
     Type: Platform
     API level: 2
     Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
id: 2
     Name: Android 1.5
     Type: Platform
     API level: 3
     Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
id: 3
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Description: Android + Google APIs
     Based on Android 1.5 (API level 3)
     Libraries:
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: HVGA (default), HVGA-L, QVGA-P, HVGA-P, QVGA-L
</pre></p>

<p>From this information we can see the SDK supports Android 1.1 and 1.5 and their target IDs are 1 and 2 respectively. Knowing this information we can now create our Android Virtual Device. To create an AVD for Android 1.1 (target ID 1) with the name <strong>android1.1</strong> we type:</p>

<p><pre class="brush: plain;">android create avd -n android1.1 -t 1</pre></p>

<p>Similarly for Android 1.5 we type:</p>

<p><pre class="brush: plain;">android create avd -n android1.5 -t 2</pre></p>

<p>A few things to know about AVDs.
* When creating AVDs you can use any name you like. I choose <strong>android1.1</strong> and <strong>android1.5</strong> as they were easier to remember.
* When prompted about hardware settings just press <code>enter</code> as there should be no need to customise the hardware when testing websites.
* AVDs are created in a hidden folder in the root of your home directory. On Linux and MacOS this is <code>~/.android/avd</code>.
* You can find out what AVDs you have by typing <code>android list avd</code> in the terminal.</p>

<h2>Running the Emulator</h2>

<p>Having created the AVDs we can now run the emulator by typing <code>emulator -avd avdname</code>. This command is the one you will need to use from now on if you want to test websites in Android. For example, if we want to emulate Android 1.1 we would type:</p>

<p><pre class="brush: plain;">emulator -avd android1.1</pre></p>

<p>The first time you run the emulator you will be asked if you are happy for Emulator to send usage statistics to Google.
<img src="/content/uploads/2010/01/android-firstrun-300x209.png" alt="The Android SDK Permission to send usage statistics prompt" title="Android First Run" width="300" height="209" class="align-left size-medium wp-image-309" /></p>

<p>It can take about 10-30 seconds for the Android Emulator to boot up. During this time you will see the Android boot screen.
<img src="/content/uploads/2010/01/android-loading-300x250.png" alt="Android Emulator Boot Screen" title="Android Loading" width="300" height="250" class="size-medium wp-image-311" /> <img src="/content/uploads/2010/01/android-loaded-300x250.png" alt="Android Emulator Home Screen" title="Android Home Screen" width="300" height="250" class="size-medium wp-image-310" /></p>

<p>That&#8217;s it! To test your websites just load the Browser from the home screen. To enter a URL click Menu and then select <strong>Go</strong> or <strong>Go to URL</strong> depending on the version of Android you are running.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F06%2Ftesting-websites-on-google-android%2F&amp;seed_title=Testing+Websites+on+Google+Android/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How To: MacOS, Apache and Virtual Hosts</title>
		<link>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F02%2Fhowto-macos-apache-and-virtual-hosts%2F&amp;seed_title=How+To%3A+MacOS%2C+Apache+and+Virtual+Hosts</link>
		<comments>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F02%2Fhowto-macos-apache-and-virtual-hosts%2F&amp;seed_title=How+To%3A+MacOS%2C+Apache+and+Virtual+Hosts#comments</comments>
		<pubDate>Wed, 25 Feb 2009 22:49:46 +0000</pubDate>
		<dc:creator>themattharris</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macos]]></category>
		<category><![CDATA[vhost]]></category>
		<category><![CDATA[virtual host]]></category>
		<category><![CDATA[vitualhost]]></category>

		<guid isPermaLink="false">http://themattharris.com/?p=209</guid>
		<description><![CDATA[When developing a website I&#8217;m sure many of you are checking the pages work and look the way they should. If you&#8217;re only working on one site this isn&#8217;t too much of problem as you can place the site into your ~/Sites folder, turn on web sharing in Preferences and run the site from your [...]]]></description>
			<content:encoded><![CDATA[<p>When developing a website I&#8217;m sure many of you are checking the pages work and look the way they should.  If you&#8217;re only working on one site this isn&#8217;t too much of problem as you can place the site into your <code>~/Sites</code> folder, turn on web sharing in Preferences and run the site from your local machine.  If you&#8217;re like me though, and work on multiple sites at once, this isn&#8217;t a good idea.  It&#8217;s an inefficient workflow and there is a hugh risk of data loss resulting from the need to move and copy files in and out of the folder.</p>

<p>A better way, which many of my professional colleagues and friends do, is to use MAMP or headdress.  These two products provide a graphical interface to allow you to set up hosts on your computer and point the host to a folder on your computer.  This is great except when you want to start developing with multiple languages, or wish to test SSL or external libraries.  It also costs money as the virtual hosts ability is part of MAMP Pro, not the free MAMP edition.</p>

<p>So, although each of these products has their own strengths, is there a way to do what they do without using them.  Luckily enough there is, and i&#8217;ll talk you through it now.</p>

<h2>Assumptions</h2>

<p>First off, i&#8217;m going to make some assumptions:</p>

<ol>
<li>You&#8217;re using a Mac</li>
<li>You&#8217;re using Mac OS Leopard version 10.5.2 or higher</li>
<li>You know what the terminal is and</li>
<li>You know what the file paths are in MacOS</li>
<li>You&#8217;ve turned MAMP off and reset anything setup by Headdress</li>
</ol>

<h2>What you&#8217;ll need</h2>

<ul>
<li>About 30 minutes of time (although you can do this in 2 minutes if you know your way around the shell)</li>
<li>4 files

<ol>
<li>/etc/hosts</li>
<li>/etc/apache2/extra/httpd-vhosts.conf</li>
<li>/etc/apache2/users/USERNAME.conf (where username is the short username for your logon to your computer)</li>
<li>/etc/apache2/httpd.conf</li>
</ol></li>
<li>A text editor. I use TextMate which means I can go into the terminal and type <code>mate /path/to/file</code> to edit the files. I&#8217;m going to use this notation throughout so remember to substitute <code>mate</code> with your favoured text editor.</li>
</ul>

<h2>Step 1: Allowing Overrides and Options</h2>

<p>Open terminal and navigate to /etc/apache2/users and then list the contents of the folder.</p>

<p><pre class="brush: plain;">cd /etc/apache2/users
ls -l</pre></p>

<p>You will see a <code>.conf</code> file for each account on your computer. The one you want is the one which matches your short username for MacOS. In my case it is <code>matt.conf</code></p>

<p>Edit this file in your favourite editor</p>

<p><pre class="brush: plain;">mate /etc/apache2/users/matt.conf</pre></p>

<p>By default this file will look like this:</p>

<p><pre class="brush: plain;">&lt;Directory &quot;/Users/matt/Sites/&quot;&gt;
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
&lt;/Directory&gt;</pre></p>

<p>You need to change the <code>Options</code> and <code>AllowOverride</code> lines to <code>All</code>, so the file should now look like:</p>

<p><pre class="brush: plain;">&lt;Directory &quot;/Users/matt/Sites/&quot;&gt;
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all
&lt;/Directory&gt;</pre></p>

<p>Save the file.</p>

<h2>Step 2: Configuring Apache</h2>

<p>Open <code>/etc/apache2/httpd.conf</code> and make the following changes (the line numbers are correct for a fresh install but could be slightly different on your machine. The content remains the same though):</p>

<table>
<tr>
<th>Line</th>
<th>Before</th>
<th>After</th>
<th>Change</th>
</tr>
<tr>
<td>114</td>
<td><code>#LoadModule php5_module libexec/apache2/libphp5.so</code></td>
<td><code>LoadModule php5_module libexec/apache2/libphp5.so</code></td>
<td>ensure the # is not present</td>
</tr>
<tr>
<td>461</td>
<td><code>#Include /private/etc/apache2/ extra/httpd-vhosts.conf</code></td>
<td><code>Include /private/etc/apache2/ extra/httpd-vhosts.conf</code></td>
<td>ensure the # is not present</td>
</tr>
</table>

<p>Save the file.</p>

<h2>Step 3: Configuring your virtual hosts</h2>

<p>Open <code>/etc/apache2/extra/httpd-vhosts.conf</code>. Everything after line 26 is an example of what needs to go in the file and can safely be removed.  Alternatively you can comment the lines out with <code>#</code> if you prefer.</p>

<p>Here&#8217;s an example of what to put here, assuming:</p>

<ul>
<li>My website files are kept in <code>/Users/matt/Sites/themattharris.com</code> (remember this is case sensitive)</li>
<li>I want to test the server with the DNS name <code>www.themattharris.com</code></li>
</ul>

<p>In this case I would put the following entry into the <code>httpd-vhosts.conf</code> file:</p>

<p><pre class="brush: plain;">&lt;VirtualHost *:80&gt;
   DocumentRoot &quot;/Users/matt/Sites/themattharris.com&quot;
   ServerName www.themattharris.com
&lt;/VirtualHost *:80&gt;
</pre></p>

<h2>Step 4: Make the computer think the domain is on the localhost</h2>

<p>Open <code>/etc/hosts</code>. You&#8217;ll see something like:</p>

<p><pre class="brush: plain;">&#35;#
&#35; Host Database
&#35;
&#35; localhost is used to configure the loopback interface
&#35; when the system is booting.  Do not change this entry.
&#35;#
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0 localhost</pre></p>

<p><strong>DO NOT</strong> change any of those lines, they&#8217;re critical to the workings of your computer. What you want to do is instead add lines to the end of the file, like the following for each of your virtual hosts:</p>

<p><pre class="brush: plain;">127.0.0.1      www.themattharris.com</pre></p>

<ul>
<li>127.0.0.1 means my computer even when it&#8217;s not connected a network</li>
<li>The domain name should match the one you used for the ServerName (or ServerAlias if you used that) in <code>/etc/apache2/extra/httpd-vhosts.conf</code></li>
</ul>

<h2>h3. Step 5: Restart Apache</h2>

<p>This can be done through System Preferences by turning Web Sharing off then on again.  Alternatively, a quicker way is to use terminal and type:</p>

<p><pre class="brush: plain;">sudo apachectl graceful</pre></p>

<p>and enter you password when prompted.</p>

<p>All being well if you now point to the domain you setup in hosts you will see the web pages on your local machine. To add more virtual hosts just repeat step 3, 4 and 5.</p>

<h2>Turning a virtual host off</h2>

<p>When you want to visit the live site again you don&#8217;t need to change anything apart from edit <code>/etc/hosts</code> and place a <code>#</code> at the start of the line for the domain you want to turn off.</p>

<p><pre class="brush: plain;">#127.0.0.1      www.themattharris.com</pre></p>

<h2>Troubleshooting</h2>

<p>If you are having problems and the domains are not working open the apache error log (<code>/private/var/log/apache2/error_log</code>) and see what it says.  Quite often you&#8217;ll find you&#8217;ve got the path in the wrong case and Apache couldn&#8217;t find the file.</p>

<p>Let me know how you do with this. In a couple of days I&#8217;ll show how to enable SSL on the virtual hosts and also how to compile the GD graphics library to work with MacOS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2009%2F02%2Fhowto-macos-apache-and-virtual-hosts%2F&amp;seed_title=How+To%3A+MacOS%2C+Apache+and+Virtual+Hosts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Locally hosted websites and virtual machines</title>
		<link>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2008%2F08%2Flocally-hosted-websites-and-virtual-machines%2F&amp;seed_title=Locally+hosted+websites+and+virtual+machines</link>
		<comments>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2008%2F08%2Flocally-hosted-websites-and-virtual-machines%2F&amp;seed_title=Locally+hosted+websites+and+virtual+machines#comments</comments>
		<pubDate>Sat, 09 Aug 2008 09:08:11 +0000</pubDate>
		<dc:creator>themattharris</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[browsertesting]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[hosts]]></category>
		<category><![CDATA[parallels]]></category>
		<category><![CDATA[vmware]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.themattharris.com/?p=51</guid>
		<description><![CDATA[So here&#8217;s the situation. You&#8217;ve got a development copy of a website on your local Macbook and you&#8217;ve been making some changes to it. Everything looks great but you want to make sure you haven&#8217;t made changes that stop the site rendering the way you expect in Internet Explorer or Firefox 2. Usually you&#8217;d make [...]]]></description>
			<content:encoded><![CDATA[<p>So here&#8217;s the situation. You&#8217;ve got a development copy of a website on your local Macbook and you&#8217;ve been making some changes to it. Everything looks great but you want to make sure you haven&#8217;t made changes that stop the site rendering the way you expect in Internet Explorer or Firefox 2.  Usually you&#8217;d make use of your corporate network computers to test the site but your working remotely so don&#8217;t have that luxury. You do, however, have a couple of virtual machines running Windows XP and different versions of browsers.  The question is, how do you test the changes without committing them to the live site?<span id="more-51"></span></p>

<p>The answer is remarkably simple and allows you to test any site hosted on your local machine with browsers installed on your virtual machines. In all of this I am assuming your running Mac OS X and Windows XP in the virtual machine.  That being said, as long as your know your hosts IP address and the virtual machine is running Windows 95 upwards this will work. By host I mean the machine which you run VMWare or Parallels on.</p>

<h2>What you need</h2>

<ul>
<li>A virtual machine application such as <a href="http://www.vmware.com/products/desktop_virtualization.html">VMWare</a> or <a href="http://www.parallels.com/en/desktop/">Parallels</a></li>
<li>A website hosted on your local machine</li>
</ul>

<h2>What to do</h2>

<p>With your virtual machine turned off, edit it&#8217;s settings to ensure it is running the Network card in &#8220;Bridged&#8221; mode.  What this does is allow your virtual machine to appear on your network as if it was another computer, rather that the default NAT mode that hides the virtual machine behind the hosts IP address.</p>

<p>Next start up your virtual machine and whilst it&#8217;s loading, make a note of the hosts IP address. You can find your IP address in the network preferences or through the command <code>ipconfig</code> (Windows) or <code>ifconfig</code> (Linux and Mac).</p>

<p>With the virtual machine now loaded go to Start > Run and type <code>notepad "c:\windows\system32\drivers\etc\hosts"</code>. This will load up the file Windows uses to alias IP addresses to host names.</p>

<p><img src="/content/uploads/2010/01/hosts.jpg" alt="The default Windows hosts file" width="661" height="419" class="alignnone size-full wp-image-202" /></p>

<p>The file is very well explained but in a nutshell, you put the IP address of the host at the beginning of the line, and the domain name that should point to it. So, lets assume my host IP is 10.0.1.97 and the domain I am developing is www.themattharris.com. In the hosts file I would enter a new line as</p>

<p><pre class="brush: plain;">10.0.1.97       www.themattharris.com</pre></p>

<p>Now lets assume i&#8217;m also developing another domain on the host called www.tokofu.com. All I need to do is add another line to the hosts file <pre class="brush: plain;">10.0.1.97       www.tokofu.com</pre></p>

<p><img src="/content/uploads/2010/01/filledin.jpg" alt="Hosts file filled" width="661" height="419" class="alignnone size-full wp-image-201" /></p>

<p>Save the file and test in your virtual machine. The domains you entered into the Windows hosts file will have caused your web browser to request the site from your host and not the Internet.</p>

<p>We can also validate this by running two commands in the Windows Command Prompt. If we run <code>nslookup</code> the computer will lookup the domain name using a DNS server.  If we run the command <code>ping</code> Windows instead uses the address it knows from the hosts file. You can see this by loading a command prompt (Start &gt; Run and type <code>cmd</code> ) and entering <code>nslookup your-domain.com</code> and <code>ping your-domain.com</code></p>

<p><img src="/content/uploads/2010/01/addresscompare.jpg" alt="addresscompare" width="674" height="344" class="alignnone size-full wp-image-200" /></p>

<p>To restore the default behaviour you edit the &#8220;c:\windows\system32\drivers\etc\hosts&#8221; file and either delete the lines you entered, or start the line with a &#35; (this marks the line as a comment).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.themattharris.com/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fthemattharris.com%2F2008%2F08%2Flocally-hosted-websites-and-virtual-machines%2F&amp;seed_title=Locally+hosted+websites+and+virtual+machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
