<?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>nStation &#187; PHP</title>
	<atom:link href="http://nstation.org/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://nstation.org</link>
	<description>Online existence, portfolio and journal of Nadeeshyama Talagala.</description>
	<lastBuildDate>Sun, 10 Jul 2011 07:33:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to Manage Multiple Web Projects With Subdomains</title>
		<link>http://nstation.org/articles/how-to-manage-multiple-web-projects-with-subdomains</link>
		<comments>http://nstation.org/articles/how-to-manage-multiple-web-projects-with-subdomains#comments</comments>
		<pubDate>Sat, 22 Nov 2008 20:55:28 +0000</pubDate>
		<dc:creator>Nadee</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[XAMPP]]></category>

		<guid isPermaLink="false">http://n.talagala.org/?p=331</guid>
		<description><![CDATA[Most web projects are initially done locally. When doing multiple web projects on the local computer (the ‘nstation&#8217;) you run in to the problem of managing them. This is because only one web server can run at a time on the standard web port. Well&#8230; you can run multiple instances of the same web server...]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://i46.tinypic.com/13zdeet.png" title="XAMPP Control Panel Screenshot" class="alignleft top framed" width="400" height="154" />Most web projects are initially done locally. When doing multiple web projects on the local computer (the ‘nstation&#8217;) you run in to the problem of managing them. This is because only one web server can run at a time on the standard web port. Well&#8230; you can run multiple instances of the same web server on different ports. But that&#8217;s not the way forward if you are serious about testing, etc. An alternative is to make directories and use folder names as part of the URL. This however results ugly URL names like <em>nstation/project_name</em> and framework-based projects render issues on production environments.<span id="more-331"></span></p>
<p>The best approach I have come across to manage multiple web projects is to use subdomains. Subdomains are pretty, clean and easy to manage. This how-to article is about my simple and effective method of hosting multiple web projects on nstation using subdomains. We will create two projects ‘foo&#8217; and ‘bar&#8217; with <strong>http://foo.nstation/</strong> and <strong>http://bar.nstation/</strong> as their URLs to explain the whole process. Please note that the technique described here is based on the Microsoft Windows platform. However, it is possible to do the same on other platforms with minor adjustments.</p>
<div class="clear">&nbsp;</div>
<h2>Prerequisites</h2>
<ul>
<li><a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> or a compatible web server software<br />
<small>More info: <a href="http://www.apachefriends.org/en/xampp.html">What is XAMPP</a>, <a href="http://www.apachefriends.org/en/faq-xampp-windows.html">XAMPP FAQ</a></small></li>
<li>Notepad or compatible text editor<br />
<small>Hint: drag-and-drop a file onto a Notepad window to open the file.</small></li>
</ul>
<h2>Step 1 &#8211; create folders</h2>
<p>Create the folder structure as shown below.</p>
<p><img alt="" src="http://i47.tinypic.com/kcgg07.png" title="Folders" class="alignnone" width="214" height="335" /></p>
<p>It doesn&#8217;t have to be the <strong>C: drive</strong>. But for simplicity it is always recommended that you create the <strong>Webroot</strong> folder in a drive root. Refrain from using path names with spaces like <strong>C:\Program Files\Webroot</strong>.</p>
<p>A short description on each folder is given below.</p>
<h3>Webroot\projects</h3>
<p>This folder contains individual project folders. In our case the two sub folders <strong>foo</strong> and <strong>bar </strong>reside here.</p>
<h3>Webroot\public</h3>
<p>This is where you put all the default stuff. For example, you can copy the Apache <strong>htdocs</strong> folder content here. This folder hosts the main site (<strong>http://nstation</strong>) content.</p>
<h3>Webroot\xampp</h3>
<p>Contains XAMPP files &#8211; Apache, PHP, MySql, phpMyAdmin, perl and other server related components are stored here.</p>
<h2>Step 2 &#8211; install XAMPP</h2>
<p>Install XAMPP on <strong>Webroot\xampp</strong> folder. I recommend you use the <a href="http://www.apachefriends.org/download.php?xampp-win32-1.6.8.exe">self-extracting 7-ZIP archive</a>. Run the setup and chose <strong>C:\Webroot</strong> as the <em>Extract to</em> folder as it will anyway extract the content to a folder by the name <strong>xampp</strong>.</p>
<p><img alt="" src="http://i48.tinypic.com/2vdjz4m.png" title="XAMPP Install" class="alignnone" width="348" height="159" /></p>
<p>Run <strong>setup_xampp.bat</strong> to finish the setup process. You will get a console output similar to the following screenshot.</p>
<p><img alt="" src="http://i50.tinypic.com/v63lhu.png" title="XAMPP Setup" class="alignnone" width="559" height="290" /></p>
<p>Press any key to finish the setup. To run the XAMPP Control Panel Application, double click <strong>xampp-control.exe</strong>. Click the start button in front of both <strong>Apache</strong> and <strong>MySql</strong> modules to start the server. Since we haven&#8217;t done any modifications yet, XAMPP runs on its default settings. See screenshot below.</p>
<p><img alt="" src="http://i50.tinypic.com/33xcvo0.png" title="XAMPP Control Panel" class="alignnone" width="446" height="359" /></p>
<h2>Step 3 &#8211; configure Apache</h2>
<p>Now we need to change the default Apache configuration to match the directory structure. Apache configuration is distributed among several text files. All of these files reside in the <strong>xampp\apache\conf</strong> folder. We need to edit two files: <strong>conf\httpd.conf</strong> and <strong>conf\extra\httpd-vhosts.conf</strong>.</p>
<h3>Step 3.1 &#8211; edit httpd.conf</h3>
<p>Go to <strong>xampp\apache\conf</strong> and open the <strong>httpd.conf</strong> file. Locate <strong>&lt;Directory &#8220;C:/Webroot/xampp/htdocs&#8221;&gt;</strong> and change it to <strong>&lt;Directory &#8220;C:/Webroot/public&#8221;&gt;</strong> . Scroll down a few lines and locate the closing directive <strong>&lt;/Directory&gt;</strong> and add the following at a new line.</p>
<pre class="code">
&lt;Directory "C:/Webroot/projects"&gt;
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
&lt;/Directory&gt;
</pre>
<h3>Step 3.2 &#8211; edit httpd-vhosts.conf</h3>
<p>Go to <strong>xampp\apache\conf\extra</strong> and open the <strong>httpd-vhosts.conf</strong> file. Uncomment <strong>NameVirtualHost *:80</strong> by removing all hash signs (#) at the beginning of the line. (By now you would have noticed that any line starting with a hash sign is indeed a comment.)</p>
<p>Add the following text at the end of the file on a new line.</p>
<pre class="code">
# Default site: http://nstation
&lt;VirtualHost *:80&gt;
DocumentRoot "C:/Webroot/public"
ServerName nstation
ServerAlias nstation
&lt;/VirtualHost&gt;

# Foo sub domain: http://foo.nstation
&lt;VirtualHost *:80&gt;
ServerName foo.nstation
DocumentRoot "C:/Webroot/projects/foo"
DirectoryIndex index.php index.html index.html index.htm index.shtml
&lt;/VirtualHost&gt;

# Bar sub domain: http://bar.nstation
&lt;VirtualHost *:80&gt;
ServerName bar.nstation
DocumentRoot "C:/Webroot/projects/bar"
DirectoryIndex index.php index.html index.html index.htm index.shtml
&lt;/VirtualHost&gt;
</pre>
<h2>Step 4 &#8211; edit the hosts file</h2>
<p>The host file is the system file that matches hostnames to IPs. This file resides in the system folder <strong>%SystemRoot%\system32\drivers\etc</strong> and on most computers this would be <strong>C:\WINDOWS\system32\drivers\etc</strong>. Open the <strong>hosts</strong> file (yes, the file doesn&#8217;t have an extension) and add the following two lines to the end of the file at a new line.</p>
<pre class="code">
127.0.0.1              foo.nstation
127.0.0.1              bar.nstation
</pre>
<p>This tells the system to direct requests for <strong>foo.nstation</strong> and <strong>bar.nstation</strong> to the IP address <strong>127.0.0.1</strong>.</p>
<h2>Step 5 &#8211; test the setup</h2>
<p>Restart Apache and MySql by stopping and starting them using the XAMPP Control Panel. If you did not run these in step 2, just start both modules to see whether our configuration is in effect. If everything went accordingly, you should get the green <strong>Running </strong>status on both Apache and MySql.</p>
<p>Point your web browser to <strong>http://nstation</strong> to see the content served on <strong>Webroot\public</strong> folder. If you have nothing to start with, I suggest you copy everything in <strong>xampp\apache\htdocs</strong> folder to this location. You should get the XAMPP default web site with all the bells and whistles.</p>
<p>Put your <strong>Foo</strong> project files to <strong>Webroot\projects\foo</strong> folder and <strong>Bar</strong> project files to <strong>Webroot\projects\bar</strong> folders respectively. Point your browser to <strong>http://foo.nstation</strong> and <strong>http://bar.nstation</strong> to see them in action. Put the following code in an <strong>index.php</strong> file and save the file in both locations if you have nothing to start with.</p>
<pre class="code">
&lt;h1&gt;Hello World&lt;/h1&gt;
&lt;p&gt;&lt;?php echo "My location: " . dirname(__FILE__); ?&gt;&lt;/p&gt;
</pre>
<p>You should get different location details depending on the URL.</p>
<h2>Add more projects (optional)</h2>
<p>Follow step 3.2 and step 4 to add more projects to your setup. Given below are the skeletons that can be used for this task.</p>
<h3>Step 3.2 &#8211; httpd-vhosts.conf file entry</h3>
<pre class="code">
# vhost entry for new_project sub domain: http://new_project.nstation
&lt;VirtualHost *:80&gt;
ServerName new_project.nstation
DocumentRoot "C:/Webroot/projects/new_project"
DirectoryIndex index.php index.html index.html index.htm index.shtml
&lt;/VirtualHost&gt;
</pre>
<h3>Step 4 &#8211; hosts file entry</h3>
<pre class="code">
127.0.0.1              new_project.nstation
</pre>
<h2>Done</h2>
<p>That&#8217;s it. It&#8217;s easier than you would&#8217;ve imagined it to be. Hope this article helps and makes your web development experience a fun.</p>
<p><b>Disclaimer</b>: <a href="http://www.flickr.com/photos/normanbleventhalmapcenter/2710799656/">Cover photo</a> courtesy <a href="http://www.flickr.com/photos/normanbleventhalmapcenter/2710799656/">Norman B. Leventhal Map Center at the BPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nstation.org/articles/how-to-manage-multiple-web-projects-with-subdomains/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

