<?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>Phase Shift &#187; Guides</title>
	<atom:link href="http://phaseshiftllc.com/archives/categories/guides/feed" rel="self" type="application/rss+xml" />
	<link>http://phaseshiftllc.com</link>
	<description>Official Site of Phase Shift, LLC an IT Consulting Group from Baton Rouge, LA</description>
	<lastBuildDate>Fri, 26 Feb 2010 01:45:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Setting up a custom Weave 0.5 server</title>
		<link>http://phaseshiftllc.com/archives/2009/10/09/setting-up-a-custom-weave-0-5-server</link>
		<comments>http://phaseshiftllc.com/archives/2009/10/09/setting-up-a-custom-weave-0-5-server#comments</comments>
		<pubDate>Fri, 09 Oct 2009 20:37:53 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Weave]]></category>
		<category><![CDATA[Weave 0.5]]></category>
		<category><![CDATA[Weave Server]]></category>

		<guid isPermaLink="false">http://phaseshiftllc.com/?p=463</guid>
		<description><![CDATA[Weave is a synchronization engine from Mozilla Labs for all your browser information (settings, history, bookmarks, etc, etc).  It is a free add-on for Firefox and you can freely use Mozilla&#8217;s servers  to store your information.  This guide, however, is for anyone interested in setting up their own secure Weave server. There are instructions on [...]]]></description>
			<content:encoded><![CDATA[<p>Weave is a synchronization engine from Mozilla Labs for all your browser information (settings, history, bookmarks, etc, etc).  It is a free add-on for Firefox and you can freely use Mozilla&#8217;s servers  to store your information.  This guide, however, is for anyone interested in setting up their own secure Weave server.</p>
<p>There are instructions on the Mozilla Labs places, but they are a bit scattered and it took some digging before I could get things working.  Hopefully this guide will give a simple single locations for anyone interested.</p>
<h3><strong>Assumptions</strong></h3>
<p>For this guide I will assume PHP 5.1+,  a working Apache 2 server with SSL, and MySQL (SQLite can easily be substituted here, it should be obvious where.  As Mozilla notes, whatever web server you use, WebDAV can&#8217;t be enabled on that server.</p>
<h3>Server Configuration</h3>
<p>First things, grab the latest version of the Weave Server from Mozilla Labs at <a href="http://hg.mozilla.org/labs/weaveserver" target="_blank">http://hg.mozilla.org/labs/weaveserver</a> in whichever format you prefer.  Extract the files into a folder accessible by your web server.  The &#8220;server&#8221; folder will be the web root, so we can go ahead an setup a virtual server configuration similar to the following example (replace the paths accordingly):</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> weave.my.domain:<span style="color: #ff0000;">443</span>&gt;
&nbsp;
<span style="color: #00007f;">ServerName</span> weave.my.domain
<span style="color: #00007f;">DocumentRoot</span> /var/www/weaveserver/server/
&nbsp;
<span style="color: #00007f;">ErrorLog</span> /var/log/apache2/weave-error.log
<span style="color: #00007f;">CustomLog</span> /var/log/apache2/weave-access.log combined
&nbsp;
SSLEngine <span style="color: #0000ff;">on</span>
SSLCertificateFile /path/to/server.cert.crt
SSLCertificateKeyFile /path/to/server.cert.key
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/var/www/weaveserver/server/&quot;</span>&gt;
&nbsp;
<span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span>
<span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">none</span>
<span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
<span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
<span style="color: #00007f;">AuthType</span> Basic
<span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Weave Server&quot;</span>
<span style="color: #00007f;">AuthUserFile</span> /path/to/auth/file
<span style="color: #00007f;">require</span> valid-<span style="color: #00007f;">user</span>
&nbsp;
&lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&nbsp;
<span style="color: #00007f;">Alias</span> /<span style="color: #ff0000;">0.5</span> /var/www/weaveserver/server/<span style="color: #ff0000;">0.5</span>/index.php
<span style="color: #00007f;">Alias</span> /<span style="color: #00007f;">user</span>/<span style="color: #ff0000;">1</span> /var/www/weaveserver/server/<span style="color: #00007f;">user</span>/<span style="color: #ff0000;">1</span>/index.php
&nbsp;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>As you can see from this Apache config, there are some file that need to be generated.  Specifically, an SSL Certificate and key, and a basic authentication file.  I will run through these briefly below, if you are good with generating these, just skip down a bit.</p>
<h3>Generating a Self-Signed SSL Certificate</h3>
<p>First, generate a key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-des3</span> <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">1024</span></pre></div></div>

<p>Generate a certificate signing request (CSR):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> server.key <span style="color: #660033;">-out</span> server.csr</pre></div></div>

<p>Optional &#8211; At this point you can remove the password from the key if you wish&#8230; please be aware of the security risks before doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> server.key server.key.pass
openssl rsa <span style="color: #660033;">-in</span> server.key.pass <span style="color: #660033;">-out</span> server.key</pre></div></div>

<p>Finally, generate the certificate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl x509 <span style="color: #660033;">-req</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">365</span> <span style="color: #660033;">-in</span> server.csr <span style="color: #660033;">-signkey</span> server.key <span style="color: #660033;">-out</span> server.crt</pre></div></div>

<p>Make sure the Apache Virtual Host configuration paths match the locations of the key and certificate files.</p>
<h3>Creating a Password File</h3>
<p>Generate an htpasswd file using the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">htpasswd <span style="color: #660033;">-c</span> weaveserver.pwd</pre></div></div>

<p>You will be prompted to enter a password for the user you created.  Make sure to update the AuthUserFile path in the Apache Virtual Server config to point to this file.</p>
<p><strong>Note:</strong> You need to have the same user name(s) and password(s) in the htpasswd file as you plan on having setup in the Weave user database table (covered later).</p>
<h3>Database Setup</h3>
<p>Create a new database and create the two tables as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DATABASE</span> WEAVE<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">USE</span> WEAVE<span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`wbo`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`username`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`collection`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">''</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`parentid`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`predecessorid`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`modified`</span> <span style="color: #999900; font-weight: bold;">decimal</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">12</span><span style="color: #000033;">,</span><span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`sortindex`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`depth`</span> <span style="color: #999900; font-weight: bold;">tinyint</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">4</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`payload`</span> <span style="color: #999900; font-weight: bold;">longtext</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`payload<span style="color: #008080; font-weight: bold;">_</span>size`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">11</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`collection`</span><span style="color: #000033;">,</span><span style="color: #008000;">`id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`parentindex`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`collection`</span><span style="color: #000033;">,</span><span style="color: #008000;">`parentid`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`modified`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`collection`</span><span style="color: #000033;">,</span><span style="color: #008000;">`modified`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`weightindex`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`collection`</span><span style="color: #000033;">,</span><span style="color: #008000;">`sortindex`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`predecessorindex`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`collection`</span><span style="color: #000033;">,</span><span style="color: #008000;">`predecessorid`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`size<span style="color: #008080; font-weight: bold;">_</span>index`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #000033;">,</span><span style="color: #008000;">`payload<span style="color: #008080; font-weight: bold;">_</span>size`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span><span style="color: #990099; font-weight: bold;">InnoDB</span><span style="color: #000033;">;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`users`</span>
<span style="color: #FF00FF;">&#40;</span>
 <span style="color: #008000;">`username`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span><span style="color: #000033;">,</span>
 <span style="color: #008000;">`md5`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">32</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
 <span style="color: #008000;">`email`</span> <span style="color: #999900; font-weight: bold;">varbinary</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">64</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
 <span style="color: #008000;">`status`</span> <span style="color: #999900; font-weight: bold;">tinyint</span><span style="color: #000033;">,</span>
 <span style="color: #008000;">`location`</span> <span style="color: #999900; font-weight: bold;">text</span><span style="color: #000033;">,</span>
 <span style="color: #008000;">`alert`</span> <span style="color: #999900; font-weight: bold;">text</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span><span style="color: #990099; font-weight: bold;">InnoDB</span><span style="color: #000033;">;</span></pre></div></div>

<p>That should be it for the database!  Feel free to adjust the database name to your own liking, and be sure to grant select, select, insert, delete, and update permissions to whichever MySQL user you plan on accessing this with from weave.  In case anyone forgot the grant sytax:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">SELECT</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">INSERT</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">UPDATE</span><span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">DELETE</span> <span style="color: #990099; font-weight: bold;">ON</span> weave.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'myuser'</span>@<span style="color: #008000;">'localhost'</span><span style="color: #000033;">;</span></pre></div></div>

<p>If you are creating this user, be sure to set the password by adding &#8221; IDENTIFIED BY &#8216;mypassword&#8217; &#8221; on the end of the above statement.</p>
<h3>Weave Server Configuration</h3>
<p>Navigate to the weaverserver/server/user/1 folder.  Copy weave_user_constants.php.dist to weave_user_constants.php and set the following items:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_STORAGE_ENGINE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_STORE_READ_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_STORE_READ_DB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_STORE_READ_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_STORE_READ_PASS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_AUTH_ENGINE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_AUTH_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_AUTH_DB'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_AUTH_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_MYSQL_AUTH_PASS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_REGISTER_STORAGE_LOCATION'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'weave.my.domain'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>These settings are pretty obvious once you read over the comments.  The first group of settings is for the database that stores the synchronized data, and just sets the type and connection information.  The second is basically the same thing, but points to the database that has the table of users to authenticate against.  The final setting above only needs to be set if you are using the same database to house both the storage and authentication data.</p>
<p>Now do essentially the exact same steps for weaveserver/server/0.5/default_constants.php.dist.  That is, copy it over to default_constants.php and then edit the similar sections to set the connection strings for the authentication and storage database(s).  The only difference is that instead of specifying the &#8216;WEAVE_REGISTER_STORAGE_LOCATION&#8217;, which will not exist, set the following line if both the authentication and store tables are in the same database:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_SHARE_DBH'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you are using different databases, just leave this one alone.  Also, you can easily use Sqlite as well by setting the various &#8216;engine&#8217; variables to &#8216;sqlite&#8217; and configuring the path to the stores (this is pretty self explanatory once you read through the constants files).</p>
<h3>CAPTCHA</h3>
<p>If you want to use captcha when creating an account, you will need to grab a public and private key from <a href="http://recaptcha.net">http://recaptcha.net</a> and make some changes to the Apache and Weaver Server configs.  This is completely optional (just ignore the captcha field if you don&#8217;t set this up when creating a new user).<br />
Back in weaveserver/server/user/1/weave_user_constants.php set the following to 1:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WEAVE_REGISTER_USE_CAPTCHA'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now copy weaveserver/server/misc/1/weave_misc_constants.php.dist to weave_misc_constants.php and add in your public and private keys.  Finally, add an alias to your Apache config as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Alias</span> /misc/<span style="color: #ff0000;">1</span>/captcha_html /server/misc/<span style="color: #ff0000;">1</span>/captcha.php</pre></div></div>

<h3>Test it!</h3>
<p>Now everything should be configured, so install the Weave add-on for Firefox if you haven&#8217;t already (<a href="http://labs.mozilla.com/weave/">http://labs.mozilla.com/weave/</a>).  At the time of writing this, the latest was 0.7.</p>
<p>Open a new tab in Firefox and type about:config and search for extensions.weave.clusterURL.  Set this to your Weave Server URL (i.e.  &#8220;https://weave.my.domain/&#8221;).  Make sure to include the trailing slash.<br />
Now open weave and go to the user creation screen.  At the bottom of the form box there is an option that says &#8220;Create my account with:,&#8221; select &#8220;A custom Weave server&#8221; and input your server into the textbox below (i.e. &#8211; &#8220;https://weave.my.domain/&#8221;).  Again here, make sure you include a trailing slash as the underlying code doesn&#8217;t check and append if needed.</p>
<p>If all goes well, you should be able to put in a username and have it tell you that it is available (if it says it is not available, and its not already in the database, check the log in the top right of the page under tools -&gt; debug log to see what the problem is).  If you didn&#8217;t setup captcha, just leave it blank and create your user once you filled in an email and password.  Now enter your pass phrase and you should be set!  Select what you would like to sync and how, then either wait or manually kick off a sync by going to &#8220;Signed in as &#8221; -&gt; &#8220;Sync now&#8221; in the upper right.  If everything went correctly, your data should be sent over SSL and encrypted into your server&#8217;s database.</p>
<h3>References</h3>
<p><a href="https://wiki.mozilla.org/Labs/Weave/0.5/Setup/Storage">Weave Storage / Server Setup</a><br />
<a href="https://wiki.mozilla.org/Labs/Weave/User/1/Setup">Weave User Setup</a><br />
<a href="http://labs.mozilla.com/weave/">Weave Page on Mozilla Labs</a><br />
<a href="http://www.akadia.com/services/ssh_test_certificate.html">Creating a Self Signed SSL Certificate</a><br />
<a href="http://httpd.apache.org/docs/2.0/programs/htpasswd.html">htpasswd Apache Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://phaseshiftllc.com/archives/2009/10/09/setting-up-a-custom-weave-0-5-server/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multiple Secure Subdomains with a Wildcard SSL Certificate</title>
		<link>http://phaseshiftllc.com/archives/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate</link>
		<comments>http://phaseshiftllc.com/archives/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate#comments</comments>
		<pubDate>Mon, 27 Oct 2008 17:01:10 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linode]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[subdomains]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://phaseshiftllc.com/?p=131</guid>
		<description><![CDATA[This guide is a walk through for configuring multiple secure subdomains using a wildcard SSL certificate and Apache2 on Ubuntu 8.04. For those not familiar with the problems for this setup, a little background is in order (if you want to get to the meat of things, just skip down). If you have your domain, [...]]]></description>
			<content:encoded><![CDATA[<p>This guide is a walk through for configuring multiple secure subdomains using a wildcard SSL certificate and Apache2 on Ubuntu 8.04.</p>
<p>For those not familiar with the problems for this setup, a little background is in order (if you want to get to the meat of things, just skip down).  If you have your domain, <em>mydomain.com</em>, it is convenient to organize things into subdomains.  For example, maybe you have code repositories at <em>code.mydomain.com</em> or a development environment for testing at <em>test.mydomain.com</em>.  But what if you want both of these subdomains to be secure?  A standard SSL certificate for <em>mydomain.com</em> does not validate for any of the subdomains since the addresses do not match.  You could get separate certificates for each subdomain, but configuring those can be tricky.  Wildcard SSL certificates allow a single certificate for any immediate subdomain of the base, i.e. <em>*.mydomain.com</em>.</p>
<p>So problem solved right?  Well, not exactly&#8230; due to the SSL protocol you cannot use name-based virtual hosts in Apache with SSL.  Since only IP-based virtual hosts can be used Apache requires a single Virtual Host for all port 443 (SSL) traffic per IP address.  The way around this is to dynamically set the document root after receiving a request on port 443.  It may sound complicated, but the steps are pretty easy once you see how it is done.</p>
<h4>Generating the Wildcard Certificate</h4>
<p>First off, you need a wildcard SSL certificate.  You can purchase one commercially or just generate one yourself.  If you want to roll your you have to have Apache with mod-ssl.  (Note that if you are not running as root you will need to <em>sudo</em> all of the below commands):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 apache2-common</pre></div></div>

<p>Now we can generate the certificate.  First we generate a key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> server.key <span style="color: #000000;">2048</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">400</span> server.key</pre></div></div>

<p>Next we generate a certificate signing request (CSR).  This is where we can designate the wildcard.  Run the command below and you will be prompted with a series of questions.  When promted for <em>Common Name</em>, you would normally enter your domain name.  We want a wildcard so enter <em>*.mydomain.com</em></p>
<p> , replacing <em>mydomain.com</em> with your domain name:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> server.key <span style="color: #660033;">-out</span> server.csr</pre></div></div>

<p>Finally, create the self-signed wildcard certificate (the below example is valid for a year; change the number of days to reflect how long you want the certificate to be valid):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl x509 <span style="color: #660033;">-req</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">365</span> <span style="color: #660033;">-in</span> server.csr <span style="color: #660033;">-signkey</span> server.key <span style="color: #660033;">-out</span> server.crt</pre></div></div>

<h4>Configuring Apache</h4>
<p>First enable the Apache SSL module if it isn&#8217;t already:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2enmod ssl</pre></div></div>

<p>We also need to enable the vhost_alias module:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2enmod vhost_alias</pre></div></div>

<p>Apache needs to be told to listen on port 443.  Edit the ports.conf file in /etc/apache2 and add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Listen <span style="color: #000000;">443</span></pre></div></div>

<p>Now we need a Virtual Host to handle all the port 443 traffic.  I recommend creating and editing a new file in /etc/apache2/sites-available:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>ssl.mydomain.com</pre></div></div>

<p>Now to configure the Virtual Host.  Add the following to the newly created file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ServerAdmin webmaster<span style="color: #000000; font-weight: bold;">@</span>localhost
ServerName <span style="color: #000000; font-weight: bold;">*</span>.mydomain.com
SSLEngine On
SSLCertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM
VirtualDocumentRoot <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/%</span>0<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>A little explanation is in order here.  The ServerName (and any ServerAlias as well) uses the wildcard notation (i.e. <em>*.mydomain.com</em>) since we want to handle multiple subdomains.  Next are the directives to enable SSL and you will need to adjust the SSLCertificateFile path to point to your certificate.  The last line is where the magic happens using the <a href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#virtualdocumentroot">VirtualDocumentRoot</a> directive.  Thanks to the vhost_alias module, we can set the document root based on the address.</p>
<p>Say we have the two example subdomains from earlier, <em>code.mydomain.com</em> and <em>test.mydomain.com</em>.  We have our wildcard certificate in place and someone tries to go to <em>http://code.mydomain.com</em></p>
<p> .  The <em>%0</em> signifies that the entire string from the address should be substituted, yielding a <em>DocumentRoot</em> of <em>/var/www/code.mydomain.com</em>.  If someone tried <em>test.mydomain.com</em>, it would become <em>/var/www/test.mydomain.com</em>.  The <a href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html">documentation on the vhost_alias module</a> shows all the options for getting parts or all of the address string for substituting into the DocumentRoot.</p>
<p>Using this method, you can dynamically determine what the root document path should be and serve the correct information.  The only catch is that you will have to adhere to a naming scheme that follows however you design your rewrite rule (in my example above, it will be <em>/var/www/&lt;full subdomain path&gt;</em>.  But being forced to use a consistent naming scheme for your sites (which should probably be done anyway&#8230;) is a pretty good tradeoff for running multiple secure subdomains on a single IP address with a single SSL certificate.</p>
<p>One last thing, make sure to reload Apache so the changes take effect:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache force-reload</pre></div></div>

<p>If you are looking for a good host that will give you full control over your server, be sure to check out <a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a">Linode</a></p>
<p> .  We use them for all our Linux hosting and love it!</p>
]]></content:encoded>
			<wfw:commentRss>http://phaseshiftllc.com/archives/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Installing MySQL gem on Windows &amp; cygwin for Rails</title>
		<link>http://phaseshiftllc.com/archives/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails</link>
		<comments>http://phaseshiftllc.com/archives/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails#comments</comments>
		<pubDate>Sun, 26 Oct 2008 22:44:28 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://phaseshiftllc.com/?p=146</guid>
		<description><![CDATA[This post assumes that you&#8217;ve followed the Setting up Rails on Windows with Cygwin guide and are using Cygwin on Windows for your Rails development. If you&#8217;re upgrading to Rails 2.2 (or running on edge), you&#8217;ll need to build the mysql gem from source, as it&#8217;s being removed from the Rails pacakge. You&#8217;ll know if [...]]]></description>
			<content:encoded><![CDATA[<p>This post assumes that you&#8217;ve followed the <a href="http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin">Setting up Rails on Windows with Cygwin</a> guide and are using Cygwin on Windows for your Rails development.</p>
<p>If you&#8217;re upgrading to Rails 2.2 (or running on edge), you&#8217;ll need to build the mysql gem from source, as it&#8217;s being removed from the Rails pacakge.  You&#8217;ll know if you need to do this if you get the following error when building your app:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!!!</span> The bundled mysql.rb driver has been removed from Rails 2.2. Please <span style="color: #c20cb9; font-weight: bold;">install</span> the mysql gem and try again: gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql.</pre></div></div>

<h4>Installing MySQL from source</h4>
<p>First thing you&#8217;ll need to do is to <a href="http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz/from/pick#mirrors">download the source files from MySQL</a>.</p>
<p>The next steps are all from the command line (and will probably take a while to complete!):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf mysql-5.0.67.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> mysql-5.0.57
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><strong>UPDATE:</strong> As those who&#8217;ve commented here have noted, a common error you may come across while running make is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">readline<span style="color: #000000; font-weight: bold;">/</span>readline.h:<span style="color: #000000;">70</span>:<span style="color: #000000;">29</span>: sys<span style="color: #000000; font-weight: bold;">/</span>ttydefaults.h: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory</pre></div></div>

<p>The easiest way to solve this issue is to download the readline packages from cygwin (using the cygwin installer) and running</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--without-readline</span> <span style="color: #007800;">CFLAGS</span>=-O2</pre></div></div>

<p>Instead of plain <code>./configure</code></p>
<p>Also note, if you&#8217;ve already run <code>./configure</code> you&#8217;ll need to clean up the directory by running</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> distclean</pre></div></div>

<p>This will actually install the entire MySQL library, but we won&#8217;t be using it.  We just needed the library files to build the gem with.  Once MySQL is built, you just need to install the gem, and you&#8217;re good to go:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql</pre></div></div>

<p>Don&#8217;t forget to tell MySQL which configuration we want to load.  By default, it&#8217;ll try to use a local socket, but we want it to use the server we installed in Windows (outside of cygwin).  Check out the <a href="http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin#cygwin-rails-mysql">Getting Cygwin/Rails to work with MySQL section</a> of our previous guide.</p></p>
]]></content:encoded>
			<wfw:commentRss>http://phaseshiftllc.com/archives/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Setting up Rails on Windows with Cygwin</title>
		<link>http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin</link>
		<comments>http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin#comments</comments>
		<pubDate>Thu, 02 Oct 2008 22:07:21 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://phaseshiftllc.com/?p=109</guid>
		<description><![CDATA[Update: If you&#8217;re using Rails 2.2, you&#8217;ll need to perform some extra work to get MySQL working. Getting Started I like developing in Ruby on Rails, but I don&#8217;t own a Mac.  I&#8217;ve found that setting up a Rails development environment within Windows can get frustrating and cumbersome at times.  I&#8217;ve also found that using [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> If you&#8217;re using Rails 2.2, you&#8217;ll need to <a href="#rails-22-update">perform some extra work to get MySQL working</a>.</p>
<h4>Getting Started</h4>
<p>I like developing in <a href="http://www.rubyonrails.org">Ruby on Rails</a>, but I don&#8217;t own a Mac.  I&#8217;ve found that setting up a Rails development environment within Windows can get frustrating and cumbersome at times.  I&#8217;ve also found that using Cygwin helps to keep all of the Rails related libraries all in one easy to manage location.  OK, enough of the boring stuff, let&#8217;s open up that command prompt and get started!</p>
<p>But wait!  Before we begin, I have to talk about one more thing.  One of the frustrating things for me while I was learning Rails was watching all of these Rails screencasts and seeing everyone use <a href="http://macromates.com/">Textmate</a>.  Textmate is awesome for Rails development, but it&#8217;s not available for Windows (<a href="http://blog.macromates.com/2005/windowslinux-alternative/">and will probably never be</a>).  Luckily, Alexander Stigsen has been developing a great <a href="http://www.e-texteditor.com">Textmate app for Windows called &#8220;e&#8221;</a>. I use e (the text editor) almost everyday and it is great for development in Rails (other languages have good support as well).  One cool thing is that e relies on Cygwin for some of the bundles, so if you do install and use e, you&#8217;ll get Cygwin as part of the package.</p>
<p>If you don&#8217;t want to use e, that&#8217;s cool too.  Just <a href="http://www.cygwin.com">download the Cygwin setup file</a> and follow the same steps (just ignore any asides about setting up e).  Let&#8217;s roll.</p>
<h4>Installing Cygwin</h4>
<p>First things first and that&#8217;s installing Cygwin.  Either grab the <a href="http://www.cygwin.com">Cygwin standalone setup</a>, or <a href="http://www.e-texteditor.com">grab and install e</a> and get to the Cygwin setup screens.</p>
<p><strong>Note to e users:</strong> e will setup and install Cygwin the first time you run e, not upon installation of e.  Also, make sure to select &#8220;manual&#8221; configuration of Cygwin instead of &#8220;automatic&#8221;.</p>
<p><span id="more-109"></span></p>
<p>In the package selection screen, select the libraries that you&#8217;ll need.   Note, to make the package selection easier, hit the &#8220;View&#8221; button to change from &#8220;category&#8221; to &#8220;full&#8221;.  For reference, here&#8217;s what I install (the bold ones are the really important ones for Rails):</p>
<ul>
<li><strong>ruby</strong></li>
<li><strong>subversion</strong></li>
<li><strong>make</strong></li>
<li><strong>openssh</strong></li>
<li><strong>openssl</strong></li>
<li><strong>openssl-devel</strong></li>
<li><strong>sqlite</strong></li>
<li>git (if you&#8217;re into that sort of thing)</li>
<li>git-completion</li>
<li>nano</li>
</ul>
<p>A few other packages you may want to pick up: </p>
<ul>
<li>gcc</li>
<li>gcc-g++</li>
<li>ImageMagick</li>
<li>libmagick-devel</li>
</ul>
<p>Once the Cygwin installation is complete, you&#8217;ll be ready to get Rails up and running.</p>
<p><strong>IMPORTANT NOTE:</strong> Every command from this point assumes you are executing through a Cygwin command prompt (Not the Windows default command prompt). Also, I&#8217;m assuming you&#8217;re using nano as your text editor.  If not, just replace the command with your favorite one.</p>
<h4>Installing Ruby Gems</h4>
<p>You&#8217;ll need to pick up Ruby Gems to be able to get Rails going.  <a href="http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz">Download the latest release</a>, un-tar and run the setup script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">43985</span><span style="color: #000000; font-weight: bold;">/</span>rubygems-1.3.0.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> rubygems-1.3.0.tgz
<span style="color: #7a0874; font-weight: bold;">cd</span> rubygems-1.3.0
ruby setup.rb</pre></div></div>

<p>If you get an error like &#8220;No such file to load &#8212; ubygems (LoadError)&#8221;, all you need to do is run the following from the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">unset</span> RUBYOPT</pre></div></div>

<p>And rerun the Ruby Gems setup.</p>
<h4>Install Rails (Finally!)</h4>
<p>Once Ruby Gems is all set up, you&#8217;ll just need to run a few commands to get the rails and associated gems.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</pre></div></div>

<p>I like to install a few helpful gems to get things started:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> capistrano mongrel railsmachine gem_plugin daemons rspec</pre></div></div>

<h4>Testing it All Out</h4>
<p>Open up a command prompt and type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rails test_site
<span style="color: #7a0874; font-weight: bold;">cd</span> test_site
.<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>server</pre></div></div>

<p>Open up a browser and head to <a href="http://localhost:3000/">http://localhost:3000/</a>.  Your rails site should be up and running!  Congratulations, you&#8217;re ready to work with Rails.</p>
<h4 id="cygwin-rails-mysql">Getting Cygwin/Rails to Work with MySQL</h4>
<p>By default Rails will use the sqlite database driver, but you may want to develop using MySQL. This can be tricky.  In my experience, the best way to install MySQL for use with Rails/Cygwin is to install the <a href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads">Windows version of MySQL</a> (not the MySQL package via Cygwin).  Once MySQL is installed, you&#8217;ll need to setup a config file to tell Cygwin to use 127.0.0.1 instead of &#8220;localhost&#8221; when connecting (or you might run into an error saying it couldn&#8217;t find &#8220;tmp/mysql.sock&#8221;).</p>
<p> In Cygwin:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">nano</span> my.cnf</pre></div></div>

<p>Type the following into the file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>client<span style="">&#93;</span></span>
<span style="color: #000099;">host</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">127.0.0.1</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>mysqld<span style="">&#93;</span></span>
<span style="color: #000099;">host</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">127.0.0.1</span></pre></div></div>

<p>Save the file and you&#8217;re done.  No more &#8220;mysql.sock&#8221; errors!</p>
<h4 id="rails-22-update">Rails 2.2 Update for MySQL</h4>
<p>If you&#8217;re using Rails 2.2, you&#8217;ll need to <a href="http://phaseshiftllc.com/archives/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails">install MySQL and the gem from source</a>.</p>
<p>If you&#8217;re using MySQL on Windows, I suggest installing the <a href="http://dev.mysql.com/downloads/gui-tools/5.0.html">MySQL GUI Tools Suite</a>.  They&#8217;re great tools for managing and querying data from your MySQL databases.  Give them a try.</p>
<h4>Nice Trick for e</h4>
<p>A really nice thing about Textmate is the ability to cd into a rails directory and type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mate .</pre></div></div>

<p>Textmate pops open with the current directory set as the current project.   Great stuff.  Now how about getting that kind of functionality with e and Cygwin?  Easy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">nano</span> bash.rc</pre></div></div>

<p>Add the following to the file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">alias e<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;cygstart e&quot;</span></pre></div></div>

<p>Save and close the file, restart Cywgin and try it out:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">e .</pre></div></div>

<h4>Console 2</h4>
<p>Cygwin&#8217;s console is pretty neat, but we can do better.  I personally love using <a href="http://sourceforge.net/projects/console/">Console 2</a>, which gives you the ability to put cygwin into a tabbed environment (among other things such as colors and transparency).</p>
<p>Getting Cygwin to work with Console 2 is pretty straightforward.  Just install <a href="http://sourceforge.net/project/showfiles.php?group_id=43764">Console 2</a> (be sure to get the 2.0 release <sup>*</sup>), Go to &#8220;Settings &gt; Tabs&#8221; and click &#8220;Add&#8221;.  You can name the tab anything you&#8217;d like (&#8220;Cygwin&#8221; works just fine).  The only thing to do is set the &#8220;shell&#8221; parameter to:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">c:\cygwin\bin\<span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">--login</span> <span style="color: #660033;">-i</span></pre></div></div>

<p>Save the settings and now you&#8217;ve got a rocking command line app to do all of your Rails work in.</p>
<p><sup>*</sup> If you&#8217;re on Windows XP 64bit, you&#8217;ll need to download an older version of the 2.0 release.  I recommend getting version 2.00b124.</p>
<h4>Start Programming Already!</h4>
<p>As you can see, it doesn&#8217;t take too much work to have a great development environment for Rails on a Windows platform. Go start creating the next great app!</p>
<p>One final note: I&#8217;ve set this all up on a Windows XP 32 bit platform, but it should work just fine on 64 bit and Vista (32 or 64 bit). The only thing to watch out for is to install the correct version of Console 2 if you&#8217;re using Windows XP 64 bit (which you can find in the Console 2 notes above.</p>
</p>
<p>Happy programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Ubuntu 8.04 LTS 64-bit Server on Linode</title>
		<link>http://phaseshiftllc.com/archives/2008/08/07/ubuntu-804-lts-64-bit-server-on-linode</link>
		<comments>http://phaseshiftllc.com/archives/2008/08/07/ubuntu-804-lts-64-bit-server-on-linode#comments</comments>
		<pubDate>Fri, 08 Aug 2008 05:52:52 +0000</pubDate>
		<dc:creator>derek</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[linode]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://phaseshiftllc.com/?p=44</guid>
		<description><![CDATA[This guide is a step by step walk through for setting up an Ubuntu 8.04 LTS 64-bit server on Linode. Assuming a Linode 360 with 12288 megs of space, partition as follows: Ubuntu Image: 11776MB Swap: 512 The default swap size is only 256MB, but the recommended standard is to use between 1 to 2 [...]]]></description>
			<content:encoded><![CDATA[<p>This guide is a step by step walk through for setting up an Ubuntu 8.04 LTS 64-bit server on <a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a">Linode</a>.</p>
<p>Assuming a <a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a">Linode</a> 360 with 12288 megs of space, partition as follows:</p>
<ul>
<li>Ubuntu Image: 11776MB</li>
<li>Swap: 512</li>
</ul>
<p>The default swap size is only 256MB, but the recommended standard is to use between 1 to 2 times the amount of RAM installed on the machine.  A base Linode has 360MB of RAM, so 512 is a safe size to use.</p>
<h4>Getting Started</h4>
<p>First thing, grab your favorite text editor, such as nano or vi using aptitude or apt-get.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">nano</span></pre></div></div>

<p>If you would like auto completion in interactive shells, edit your bash.bashrc file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bash.bashrc</pre></div></div>

<p>and uncomment the following block to look as follows</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># enable bash completion in interactive shells</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bash_completion <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
. <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bash_completion
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>For some reason bash-completion is not installed by default</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> bash-completion</pre></div></div>

<p>There is no need to reboot, just restart bash and autocomplete should be working for interactive shells</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">bash</span></pre></div></div>

<p>To try it out, you can do something like &#8216;aptitude inst&lt;tab&gt;&#8217; and it should complete as &#8216;aptitude install&#8217;</p>
<p><span id="more-44"></span></p>
<p>If you enjoy having using manpages, you will need to install the man binary.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> man-db</pre></div></div>

<p>You may have seen perl warnings complaining that the locale information is not set when trying to install anything from the repositories.  To get this fixed, first install the locales package</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> locales</pre></div></div>

<p>and then define your locale information with the following command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">localedef <span style="color: #660033;">-i</span> en_US <span style="color: #660033;">-c</span> <span style="color: #660033;">-f</span> UTF-<span style="color: #000000;">8</span> en_US.UTF-<span style="color: #000000;">8</span></pre></div></div>

<p>Be sure to replace the locale name if you need something other than en_US.</p>
<p>Now we need to get everything up to date</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> safe-upgrade</pre></div></div>

<p>Clean up any old update files and reclaim some space</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> autoclean</pre></div></div>

<h4>Server Configuration</h4>
<p><a href="http://www.howtoforge.com/">HowtoForge</a> has a great <a href="http://www.howtoforge.com/perfect-server-ubuntu8.04-lts">guide for setting up an Ubuntu 8.04 server</a>.  Credit goes to them for several of the server configuration sections listed below, and I highly recommend supporting them and checking out their library of guides.</p>
<p>By default, Ubuntu will have DHCP enabled.  To get a static IP address, edit the interfaces file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>interfaces</pre></div></div>

<p>Replace the line</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iface eth0 inet dhcp</pre></div></div>

<p>with the following (substitute the values for your <a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a">Linode&#8217;s</a> information)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1</pre></div></div>

<p>Restart networking</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>networking restart</pre></div></div>

<p>Edit your hosts file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts</pre></div></div>

<p>Add a line mapping your host name to your server IP.  For example</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>
127.0.0.1    localhost
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>becomes</p>
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>
127.0.0.1    localhost
192.168.1.150    myserver.com    myserver
<span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Add the host name to the hostname file (it should be empty)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">hostname</span></pre></div></div>

<p>and add your host name</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">myserver.com</pre></div></div>

<p>Start the hostname.sh shell script</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>hostname.sh start</pre></div></div>

<p>Test that everything is working by running</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></pre></div></div>

<p>It should display your host name.</p>
<h4>Install Applications</h4>
<p><em>MySQL</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mysql-server mysql-client libmysqlclient15-dev</pre></div></div>

<p>You will be prompted to enter and re-enter a root password for MySQL.</p>
<p><em>Apache</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert</pre></div></div>

<p><em>PHP5/Ruby</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libapache2-mod-php5 libapache2-mod-ruby php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl</pre></div></div>

<p>Edit /etc/apache2/mods-available/dir.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>mods-available<span style="color: #000000; font-weight: bold;">/</span>dir.conf</pre></div></div>

<p>Change</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm</pre></div></div>

<p>to (adding &#8216;index.shtml index.php3&#8242; to the line above)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml index.php3</pre></div></div>

<p>Enable common apache modules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">a2enmod ssl
a2enmod suexec
a2enmod include
a2enmod rewrite</pre></div></div>

<p><em><a href="http://eaccelerator.net/">eAccelerator</a> for PHP (optional)</em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>bart.eaccelerator.net<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>0.9.5.3<span style="color: #000000; font-weight: bold;">/</span>eaccelerator-0.9.5.3.tar.bz2
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> eaccelerator-0.9.5.3.tar.bz2
<span style="color: #7a0874; font-weight: bold;">cd</span> eaccelerator-0.9.5.3
phpize
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Create the eaccelerator cache directory and assign the right ownership to it (the owner and group has to be the user and group apache is running as &#8211; in this case www-data) by executing the commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>eaccelerator
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> www-data:www-data <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>eaccelerator<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>The last thing to do is to enable eAccelerator in your php.ini file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>And add the following lines to the end of the file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">;uncomment if you want to use as a Zend extension</span>
<span style="color: #666666; font-style: italic;">;zend_extension=&quot;/usr/lib/php5/eaccelerator.so&quot;</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;eaccelerator.so&quot;</span>
eaccelerator.shm_size<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;16&quot;</span>
eaccelerator.cache_dir<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;/tmp/eaccelerator&quot;</span>
eaccelerator.enable<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;1&quot;</span>
eaccelerator.optimizer<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;1&quot;</span>
eaccelerator.check_mtime<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;1&quot;</span>
eaccelerator.debug<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;0&quot;</span>
eaccelerator.filter<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;&quot;</span>
eaccelerator.shm_max<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;0&quot;</span>
eaccelerator.shm_ttl<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;0&quot;</span>
eaccelerator.shm_prune_period<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;0&quot;</span>
eaccelerator.shm_only<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;0&quot;</span>
eaccelerator.compress<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;1&quot;</span>
eaccelerator.compress_level<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;9&quot;</span></pre></div></div>

<p>For more information on what these settings do, check out the <a href="http://eaccelerator.net/wiki/Settings">eAccelerator config file settings page</a>.</p>
<p>Reload Apache to load the new modules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 force-reload</pre></div></div>

<p>Go to your site (i.e. http://192.168.1.150) and you should see the default Apache page displaying &#8216;It works!&#8217;</p>
<p>To test that Apache is parsing PHP, make a new php file for Apache to display</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>test.php</pre></div></div>

<p>and add the following</p>
<p>Go to the test page (i.e. http://192.168.1.150/test.php) and you should see all the information about your PHP install.  It is a good idea to synchronize the clock to an internet time server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ntp ntpdate</pre></div></div>

<p>If you want a little protection from brute force attacks, fail2ban is an easy tool that uses IPTables and does the hard stuff for you.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> fail2ban</pre></div></div>

<p>Fail2ban has a main configuration file that you should not edit.  Instead the main config file is used as the default and local configurations override those settings when needed.  This way you can create finer grain control and still have the defaults in place to catch situations for which you haven&#8217;t defined rules.  To start, copy over the main config file into a local config file to edit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fail2ban<span style="color: #000000; font-weight: bold;">/</span>jail.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fail2ban<span style="color: #000000; font-weight: bold;">/</span>jail.local</pre></div></div>

<p>Now edit the local config file</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>fail2ban<span style="color: #000000; font-weight: bold;">/</span>jail.local</pre></div></div>

<p>The comments in the config file explain the options pretty well.  A quick rundown of some of the basics:</p>
<dl>
<dt>ignoreip</dt>
<dd>Space separated list of IPs that will never be banned.  Localhost is added by default, and you should add any machines that you don&#8217;t think fail2ban needs to monitor for brute force attacks (such as your personal computers).</dd>
<dt>bantime</dt>
<dd>The time an IP address will be blocked if it exceeds the maximum number of login attempts.  After that time, the IP will be removed from the banned list and allowed to login again.  Set this to -1 if you want bans to remain in effect indefinitely.</dd>
<dt>maxretry</dt>
<dd>The maximum number of login attempts before the IP is banned.</dd>
<dt>action</dt>
<dd>This determines the how fail2ban reacts when an IP exceeds the allowed number of logins.  There are 3 predefined shortcuts so you don&#8217;t have to figure out the syntax on this.  The first, &#8216;action_&#8217;, just bans the IP.  &#8216;action_mw&#8217; will ban the IP and send you an e-mail with a whois report on that IP.  Last, &#8216;action_mwl&#8217; will ban the IP and send an e-mail with a whois report and the relevant log file lines that caused the IP to be banned.  The default is u &#8216;action = %(action_)s&#8217;.  To change to one of the other shortcuts, replace only the &#8216;action_&#8217; part.  For example, if you wanted to ban with e-mail alerts containg the whois report and log file lines you would use &#8216;action = %(action_mwl)s&#8217; since the shortcut for is &#8216;action_mwl&#8217;.</dd>
<dt>destmail</dt>
<dd>If you elect to receive emails from fail2ban, this specifies the e-mail address tp which it should send the notifications.</dd>
</dl>
<p>The last thing to do in the config file is enable the sections that correspond to the services you want to monitor.  These are under the &#8216;JAILS&#8217; section.  This is done by setting the &#8216;enabled&#8217; flag to true for a given section.  For the simple server above, I would recommend the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">...
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>ssh<span style="">&#93;</span></span>
<span style="color: #000099;">enabled</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
<span style="color: #000099;">port</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ssh</span>
<span style="color: #000099;">filter</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> sshd</span>
<span style="color: #000099;">logpath</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /var/log/auth.log</span>
<span style="color: #000099;">maxretry</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 6</span>
...
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>apache<span style="">&#93;</span></span>
<span style="color: #000099;">enabled</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
<span style="color: #000099;">port</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> http,https</span>
<span style="color: #000099;">filter</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> apache-auth</span>
<span style="color: #000099;">logpath</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /var/log/apache*/*error.log</span>
<span style="color: #000099;">maxretry</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 6</span>
...</pre></div></div>

<p>After you get your configuration in place, restart the fail2ban service</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fail2ban</pre></div></div>

<p>I am not going to cover how to setup a mail server here because there is now a wonderful guide on <a href="http://www.howtoforge.com/">HowToForge</a>.  Using the HowtoForge <a href="http://www.howtoforge.org/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04">guide for Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 8.04 LTS)</a> will give you a mail server that supports IMAP and POP with virtual users and domains all configured via a MySQL database and much more.</p>
<p>Note that if you do use the mail server guide and run fail2ban, enable the [postfix], [courierpop3], [courierimap], and [sasl] sections in the fail2ban jail.local file.</p>
]]></content:encoded>
			<wfw:commentRss>http://phaseshiftllc.com/archives/2008/08/07/ubuntu-804-lts-64-bit-server-on-linode/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
