<?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>Peter Stagg dot com - the blog &#187; website</title>
	<atom:link href="http://www.peterstagg.com/tag/website/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peterstagg.com</link>
	<description>Cumulus humilis &#38; cirrus musings: ponderings in the cloud…</description>
	<lastBuildDate>Tue, 01 Jun 2010 00:39:09 +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>Install subversion on OS X Leopard as a revision control server for a Website</title>
		<link>http://www.peterstagg.com/2009/05/installing-subversion-on-os-x-leopard-server-as-a-revision-control-server-for-a-website-project/</link>
		<comments>http://www.peterstagg.com/2009/05/installing-subversion-on-os-x-leopard-server-as-a-revision-control-server-for-a-website-project/#comments</comments>
		<pubDate>Fri, 29 May 2009 04:29:23 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[revision]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.peterstagg.com/?p=368</guid>
		<description><![CDATA[When we start to get a reasonable size team together working on a large web project we can run into problems like; one team member has the latest copy of the production code on their computer and they&#8217;ve gone on leave for a week or they, with the best of intentions, clean up the test [...]]]></description>
			<content:encoded><![CDATA[<p>When we start to get a reasonable size team together working on a large web project we can run into problems like; one team member has the latest copy of the production code on their computer and they&#8217;ve gone on leave for a week or they, with the best of intentions, clean up the test server and accidentally remove someone else&#8217;s latest updates. Its at this point we need to consider using revision control software. In very simple terms revision control software provides a central repository for all the files in a project and keeps track of all the changes made to the files (see <a href="http://en.wikipedia.org/wiki/Revision_control">http://en.wikipedia.org/wiki/Revision_control</a> for more detail). This kind of software has more traditionally been used by software developers but as web development teams and web projects have become bigger and more complicated revision control systems have become invaluable for web developers.<span id="more-368"></span></p>
<p>Getting revision control software installed and running for a small team can be an onerous task but finding information on how to do it can be more so, so I&#8217;ve put together the following end-to-end guide of how we have set up our own revision control server. We chose subversion as our revision control server software as we are a mostly Mac team with a few token WinTel users for system balance. We&#8217;re all mad <a href="http://www.adobe.com/products/dreamweaver/">Dreamweaver</a> users (Dreamweaver has subversion client tools in CS4) as does one of our favorite text editors (<a href="http://macromates.com/">TextMate</a>) and the box we have to run the system from is an OS X Leopard server. One other reason for choosing subversion is that it came at the right price &#8211; free.</p>
<p>So here is the process we went through (minus the back-tracks and stuff-ups) to set-up subversion on OS X Leopard server for revision control of a Website project.</p>
<p><!--more--></p>
<h3>1. Instal subversion</h3>
<p>There are a number of methods you can use to install subversion. You can take the geeky route and use MacPorts or Fink but by far the simplest most painless way to do it is to download the binary install from openCollabNet.</p>
<p>Universal Subversion 1.6.2 Binaries for MAC OS X (32 and 64 bit) from openCollabNet  (Universal)</p>
<ul>
<li><a href="http://www.open.collab.net/downloads/community/">http://www.open.collab.net/downloads/community/</a></li>
<li><a href="http://subversion.tigris.org/getting.html#osx">http://subversion.tigris.org/getting.html#osx</a></li>
</ul>
<p>N.B. Whilst leopard reportedly comes with subversion (Ver 1.4.4 &#8211; ?) I think if you are serious about using it you&#8217;ll want to get the latest stable release.</p>
<h3>2. Test subversion installation</h3>
<p>The simple way to test whether or not your install was successful is to open the terminal and type…</p>
<pre style="padding-left:30px;">$ svn</pre>
<p>The response should be…</p>
<pre style="padding-left:30px;">Type 'svn help' for usage.</pre>
<h3>3. Create <em>*a*</em> Subversion repository and give the web server user access</h3>
<p>The first thing we need to do once we&#8217;ve installed subversion is to create a repository where subversion can keep control of your files for us. We&#8217;re going to give users access to the repository via a web service so the httpd user, usually www, will need to be able to access the repository.</p>
<p>Create the repository</p>
<pre style="padding-left:30px;">$ sudo svnadmin create /usr/local/svn_repository</pre>
<p>Give the httpd user (www) access / ownership</p>
<pre style="padding-left:30px;">$ sudo chown -R www /usr/local/svn_repository</pre>
<h4>Notes</h4>
<ul style="padding-left:30px;">
<li>As in the example above you may need to use superuser i.e. sudo</li>
<li>Give the repository a meaningful name. Whilst names like &#8216;repo&#8217; often appear in documents like this &#8216;svn_repository&#8217; is much more meaningful.</li>
</ul>
<h3>4. Create the basic structure and commit the changes to the repository</h3>
<p>Recommended practice prescribes the use of a folder structure that at the minimum, for a single project repository, includes the  folders tags, branches and trunk. This style of repository layout may not be suitable/necessary for all projects but it&#8217;s good practice to start this way.</p>
<p>Were going to be creating some folders then committing them to the repository to create its initial structure so its best to cd to temp space to do this.</p>
<pre style="padding-left:30px;">$ cd /tmp</pre>
<p>Checkout the repository: Checking out the repository creates a working copy and forges a link between the working copy and the repository. FYI &#8216;co&#8217; is short-hand for checkout.</p>
<pre style="padding-left:30px;">$ svn co file:///usr/local/svn_repository</pre>
<pre style="padding-left:30px;">Checked out revision 0.</pre>
<p>cd into the working copy</p>
<pre style="padding-left:30px;">$ cd svn_repository</pre>
<p>Create the basic structure in working copy</p>
<pre style="padding-left:30px;">$ svn mkdir tags branches trunk</pre>
<pre style="padding-left:30px;">A     tags</pre>
<pre style="padding-left:30px;">A     branches</pre>
<pre style="padding-left:30px;">A     trunk</pre>
<p>Commit the content of the working copy to the repository: FYI ci is shorthand for check in.</p>
<pre style="padding-left:30px;">$ sudo svn ci -m "initial structure"</pre>
<pre style="padding-left:30px;">Password:</pre>
<pre style="padding-left:30px;">Adding    branches</pre>
<pre style="padding-left:30px;">Adding    tags</pre>
<pre style="padding-left:30px;">Adding    trunk</pre>
<pre style="padding-left:30px;">Committed revision 1.</pre>
<p>Having created an initial repository we have made it easier to create and test a HTTP connection to the repository.</p>
<h3>5. Configure HTTP access via the built-in Apache 2.0 web server</h3>
<h4>5.1. Activate the required Apache modules</h4>
<p>Open server admin and select the web service on the server you want to configure.</p>
<p>Select Settings then Modules and check the box next to the following modules…</p>
<ul>
<li> dav_module</li>
<li>dav_fs_module</li>
<li> dav_svn_module</li>
<li>authz_svn_module</li>
</ul>
<p><img title="Activate Modules" src="http://www.peterstagg.com/gallery/d/912-1/instal-svn001.png" alt="Activate Modules" /></p>
<p>Click the <strong>save</strong> button</p>
<h3>5.2. Enable WebDAV on your site*</h3>
<p>Switch to Sites and select the site you want to host the service (if you have more than one).</p>
<p>Select Options and check the box next to WebDAV.</p>
<p><img title="Activate WebDAV" src="http://www.peterstagg.com/gallery/d/916-1/instal-svn002.png" alt="Activate WebDAV" /></p>
<p>Click the <strong>save</strong> button.</p>
<p>* This may not be necessary?</p>
<h4>5.3. Create a Realm</h4>
<p>Access to the subversion repository will be controlled by the Apache web service not through subversion itself. This make life a lot simpler and if you have a third party access control mechanism such as an LDAP server it makes it very easy to configure this.</p>
<p>Whilst you are in Sites with the host service selected switch to Realms.</p>
<p>Click the plus button under the Realms list and enter the following into the enter information for the realm dialogue…</p>
<ul>
<li> Realm Name: <em>svn_realm</em></li>
<li>Authentication: <em>Basic</em></li>
<li> (Change the dropdown from Folder to) Location: <em>/svn</em></li>
</ul>
<p><img title="Add Realm" src="http://www.peterstagg.com/gallery/d/919-1/instal-svn003.png" alt="Add Realm" /></p>
<p>Click the <strong>OK</strong> button.</p>
<p>Click the plus button under the User &amp; Groups list then drag and drop users to the list and modify there permissions accordingly. Most svn users will need &#8216;Browse and Read/Write WebDAV.&#8217;</p>
<p><img title="Add Users" src="http://www.peterstagg.com/gallery/d/921-1/instal-svn004.png" alt="Add Users" /></p>
<p>Click the <strong>save</strong> button.</p>
<h4>5.4. Edit the Apache site config file</h4>
<p>Locate the site config file related to the site hosting the svn repository. The usual location is &#8216;/etc/apache2/sites&#8217; and the file name should start with &#8217;000x&#8217; followed by the site name and then the extension .conf.</p>
<p>Find the section of the config file that begins with the line &#8216;&lt;Location &#8220;/svn&#8221;&gt;&#8217; and add the following lines at the end of that section…</p>
<pre style="padding-left:30px;"> DAV svn</pre>
<pre style="padding-left:30px;"> SVNPath /usr/local/svn_repository</pre>
<p>Save and close the config file and then restart the Web server by stopping and starting it again in Server Admin or using apachectl restart in the termainal.</p>
<p>N.B. If you add users to the realm after making these configuration changes the server will rewrite the line &#8216;DAV svn&#8217; to &#8216;DAV off&#8217;. A fix for this is to put the two lines above in a file called &#8216;svn.conf&#8217; in the &#8216;/etc/apache2&#8242; folder and replace them in the site config file with an include statement.</p>
<h3>6. Create a working copy on the server and give httpd (www) access to it</h3>
<p>We can&#8217;t use the repository directly as a web site because it is in reality a database and as a pile of files makes no sense. The solution to this is to have subversion output the files to a directory which the web sever can use a site root. The best way I&#8217;ve found so far to do this is to create a working copy of the repository and have subversion update it when content is committed. The fist step in this process is to create a working copy of the repository and then give httpd access to it.</p>
<p>Create a folder for your web site. We&#8217;ll use &#8216;htdocs&#8217; in this example.</p>
<p>In the terminal cd into the htdocs folder…</p>
<pre style="padding-left:30px;">$ cd /htdocs</pre>
<p>Checkout the repository into the htdocs folder…</p>
<pre style="padding-left:30px;">$ svn co file:///usr/local/svn_repository/trunk .</pre>
<pre style="padding-left:30px;">Checked out revision 0.</pre>
<h4>Notes</h4>
<ul>
<li>We checked-out the trunk and not the root of the repository. Trunk usually contains the most up-to-date content of the project.</li>
<li>The period on the end of the checkout command, for those of you who don&#8217;t know, simply means &#8216;here&#8217; in terms of the servers file path. In this case it means &#8216;/htdocs&#8217;.</li>
</ul>
<p>cd out of the htdocs folder and change the ownership of the files to give access to the httpd user (www). If you remember earlier we set the server up to give users of subversion access via http so when users interact with service httpd will be doing the work for them.</p>
<pre style="padding-left:30px;">$ cd /</pre>
<pre style="padding-left:30px;">$ sudo chown -R www /htdocs</pre>
<p>Next we need to configure our subversion repository to update the htdocs folder when users commit content to the repository.</p>
<h3>7. Edit the post-commit file to update the working copy when users commit content to the store</h3>
<p>Locate the &#8216;post-commit.tmpl&#8217; which usually lives in the &#8216;hooks&#8217; folder in your repository in this example set-up you will find at &#8216;/usr/local/svn_repository/hooks/post-commit.tmpl&#8217;.  Open it with your favorite text editor (one that can handle editing files as superuser e.g. BBedit or TextMate) and save the file as &#8216;post-commit&#8217; (no extension) in the same folder. This file is a shell script that subversion will run after content is submitted to the repository.</p>
<p>Add the following lines to the script after the line &#8216;REV=&#8221;$2&#8243;&#8216;…</p>
<pre style="padding-left:30px;">/usr/bin/svn up --non-interactive /htdocs</pre>
<p>N.B. The full path to svn may not be necessary but its a good safeguard.</p>
<p>Save the post-commit file and make it excitable.</p>
<p>e.g. from the terminal…</p>
<pre style="padding-left:30px;"> $ chmod a+x post-commit</pre>
<p>Now when ever a user commits a file to the repository the working copy in htdocs will be updated. All that remains to be done now is for the web service to be pointed at this folder as its Web Folder.</p>
<h3>References</h3>
<ul>
<li><a href="http://www.sonzea.com/articles/subversion-trac.html">http://www.sonzea.com/articles/subversion-trac.html</a></li>
<li><a href="http://agileshrugged.com/blog/?p=14">http://agileshrugged.com/blog/?p=14</a></li>
<li><a href="http://svnbook.red-bean.com/en/1.2/svn.branchmerge.maint.html">http://svnbook.red-bean.com/en/1.2/svn.branchmerge.maint.html</a></li>
<li><a href="http://svnbook.red-bean.com/en/1.2/svn.reposadmin.projects.html#svn.reposadmin.projects.chooselayout">http://svnbook.red-bean.com/en/1.2/svn.reposadmin.projects.html#svn.reposadmin.projects.chooselayout</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.peterstagg.com/2009/05/installing-subversion-on-os-x-leopard-server-as-a-revision-control-server-for-a-website-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
