<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Phase Shift</title>
  <subtitle>An IT and Web Consulting Company from Baton Rouge, Louisiana&lt;</subtitle>
  <id>http://phaseshiftllc.com/</id>
  <link href="http://phaseshiftllc.com/"/>
  <link href="http://phaseshiftllc.com/feed.xml" rel="self"/>
  <updated>2012-03-19T00:00:00Z</updated>
  <author>
    <name>Phase Shift, LLC</name>
  </author>
  <entry>
    <title>Configuring Vagrant using Puppet with RVM and MySQL for Rails development</title>
    <link rel="alternate" href="/articles/2012/03/19/setting-up-vagrant-with-rvm-and-mysql-for-rails-development.html"/>
    <id>/articles/2012/03/19/setting-up-vagrant-with-rvm-and-mysql-for-rails-development.html</id>
    <published>2012-03-19T00:00:00Z</published>
    <updated>2012-03-19T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;We&amp;#39;re a small team here at Phase Shift. One of the biggest challenges we face is standardizing our development environment across different platforms.  We have several Windows, OSX and Ubuntu machines in use as development machines and our usual production environment is Linux based. Ideally, each development machine would be set up with the exact same software and configuration as our production machines, but in practice, this is almost impossible. Enter hardware virtualization.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;We&amp;#39;re a small team here at Phase Shift. One of the biggest challenges we face is standardizing our development environment across different platforms.  We have several Windows, OSX and Ubuntu machines in use as development machines and our usual production environment is Linux based. Ideally, each development machine would be set up with the exact same software and configuration as our production machines, but in practice, this is almost impossible. Enter hardware virtualization.&lt;/p&gt;

&lt;p&gt;We&amp;#39;ve used &lt;a href="https://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt; in the past to setup environments on development machines.  This worked, but was clunky and difficult to maintain consistency in software versions across each developer&amp;#39;s instance. We thought of using custom scripts to keep things in synch, but never got good results. After reading up on &lt;a href="http://vagrantup.com/"&gt;Vagrant&lt;/a&gt;, we knew this was the setup we&amp;#39;ve been after.&lt;/p&gt;

&lt;h3&gt;How this will work&lt;/h3&gt;

&lt;p&gt;Once a developer has Vagrant and VirtualBox setup on their machine, they will download the project&amp;#39;s source and run &lt;code&gt;vagrant up&lt;/code&gt;.  That&amp;#39;s really it!  Vagrant will run a VM instance with the project loaded and all dependencies installed and configured.  The developer can make changes to the code locally and have those changes reflected instantly within the VM.  Port forwarding will allow access to the server running on the VM through a local browser.  Access to the VM is through SSH, so any SSH client will work.  Sounds great?  All we need to do is a little setup and configuration at the beginning to get the project ready.&lt;/p&gt;

&lt;h3&gt;What we need installed&lt;/h3&gt;

&lt;p&gt;Our typical new Rails application is running on &lt;strong&gt;Ruby 1.9.3&lt;/strong&gt; and is using &lt;strong&gt;MySQL&lt;/strong&gt; as the datastore. Some applications may require other software such as Memcached, Redis, or MongoDB. For this setup, we&amp;#39;re using &lt;strong&gt;RVM&lt;/strong&gt; to manage our ruby installation.  Once this VM is setup, it will have RVM, Ruby 1.9.3, Rails, and MySQL installed and running.  Other packages can be added in easily, as you&amp;#39;ll see below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE: We use a custom Vagrant box built on Ubuntu 11.10, but this setup should work just fine on the default Vagrant box - &lt;code&gt;lucid32&lt;/code&gt;.&lt;/strong&gt; For other custom boxes, checkout &lt;a href="http://vagrantbox.es/"&gt;Vagrantbox.es&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Let&amp;#39;s get started&lt;/h3&gt;

&lt;p&gt;First, create a new directory to put this new project. Next, &lt;a href="http://vagrantup.com/docs/getting-started/index.html"&gt;install Vagrant per the setup instructions&lt;/a&gt;, &lt;em&gt;up to the point of running &lt;code&gt;vagrant up&lt;/code&gt;&lt;/em&gt;. We&amp;#39;re going to define some custom Puppet settings to get the items we need installed before continuing.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;puppet&lt;/code&gt; directory directly under your project. We&amp;#39;ll put all of our puppet setup scripts here.  Your directory structure should look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
your_project/
  puppet/
  Vagrantfile
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Open up your project&amp;#39;s &lt;code&gt;Vagrantfile&lt;/code&gt; and add the following configuration for Puppet and Rails:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
config.vm.forward_port 3000, 3000

config.vm.provision :puppet do |puppet|
  puppet.manifests_path = &amp;quot;puppet/manifests&amp;quot;
  puppet.module_path    = &amp;quot;puppet/modules&amp;quot;
  puppet.manifest_file  = &amp;quot;development.pp&amp;quot;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This tells Vagrant to check these directories for Puppet configuration when initializing up our instance.  We&amp;#39;re also forwarding port 3000 since &lt;code&gt;rails s&lt;/code&gt; starts on this port.&lt;/p&gt;

&lt;h3&gt;Defining your Puppet Configuration&lt;/h3&gt;

&lt;p&gt;We&amp;#39;ll be using RVM to manage our ruby installations within the VM instance. &lt;a href="https://github.com/blt04"&gt;Brandon Turner&lt;/a&gt; has done all of the hard work to get Puppet and RVM working with his project &lt;a href="https://github.com/blt04/puppet-rvm"&gt;puppet-rvm&lt;/a&gt;. We&amp;#39;ll be using this for our setup.&lt;/p&gt;

&lt;p&gt;You&amp;#39;ll need to put puppet-rvm into the &lt;code&gt;puppet/modules&lt;/code&gt; directory as &lt;code&gt;rvm&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
git clone git://github.com/blt04/puppet-rvm.git puppet/modules/rvm
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next, in the &lt;code&gt;puppet/manifests&lt;/code&gt; directory, make a new file named &lt;code&gt;development.pp&lt;/code&gt;.  This file will define all of our Puppet configuration.  Paste the following into the file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
# development.pp
stage { &amp;#39;req-install&amp;#39;: before =&amp;gt; Stage[&amp;#39;rvm-install&amp;#39;] }

class requirements {
  group { &amp;quot;puppet&amp;quot;: ensure =&amp;gt; &amp;quot;present&amp;quot;, }
  exec { &amp;quot;apt-update&amp;quot;:
    command =&amp;gt; &amp;quot;/usr/bin/apt-get -y update&amp;quot;
  }

  package {
    [&amp;quot;mysql-client&amp;quot;, &amp;quot;mysql-server&amp;quot;, &amp;quot;libmysqlclient-dev&amp;quot;]: 
      ensure =&amp;gt; installed, require =&amp;gt; Exec[&amp;#39;apt-update&amp;#39;]
  }
}

class installrvm {
  include rvm
  rvm::system_user { vagrant: ; }

  if $rvm_installed == &amp;quot;true&amp;quot; {
    rvm_system_ruby {
      &amp;#39;ruby-1.9.3-p0&amp;#39;:
        ensure =&amp;gt; &amp;#39;present&amp;#39;;
    }
  }
}

class doinstall {
  class { requirements:, stage =&amp;gt; &amp;quot;req-install&amp;quot; }
  include installrvm
}

include doinstall
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There&amp;#39;s a lot going on here.  Let&amp;#39;s explain what each part does:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
stage { &amp;#39;req-install&amp;#39;: before =&amp;gt; Stage[&amp;#39;rvm-install&amp;#39;] }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The puppet-rvm package uses &lt;a href="http://docs.puppetlabs.com/guides/language_guide.html#run-stages"&gt;Puppet run stages&lt;/a&gt; to set itself as the first package to run.  We need to run &lt;code&gt;apt-get update&lt;/code&gt; and install our packages &lt;em&gt;before&lt;/em&gt; this happens.  So, we are creating our own run stage, and running ours before puppet-rvm&amp;#39;s.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
class requirements {
  group { &amp;quot;puppet&amp;quot;: ensure =&amp;gt; &amp;quot;present&amp;quot;, }
  exec { &amp;quot;apt-update&amp;quot;:
    command =&amp;gt; &amp;quot;/usr/bin/apt-get -y update&amp;quot;
  }

  package {
    [&amp;quot;mysql-client&amp;quot;, &amp;quot;mysql-server&amp;quot;, &amp;quot;libmysqlclient-dev&amp;quot;]: 
      ensure =&amp;gt; installed, require =&amp;gt; Exec[&amp;#39;apt-update&amp;#39;]
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is where we define the packages we need to install.  You can see we define a list of packages, including mysql-client, and we require that &lt;code&gt;apt-get update&lt;/code&gt; is run before installation.  Also, we&amp;#39;re ensuring that a group &lt;code&gt;puppet&lt;/code&gt; is present on the system. If you need other packages, just add them to the list.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
class installrvm {
  include rvm
  rvm::system_user { vagrant: ; }

  if $rvm_installed == &amp;quot;true&amp;quot; {
    rvm_system_ruby {
      &amp;#39;ruby-1.9.3-p0&amp;#39;:
        ensure =&amp;gt; &amp;#39;present&amp;#39;;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here, we are installing RVM as a system install, but are not setting it as the system default. Vagrant has a &amp;quot;system&amp;quot; ruby installed by default, and we want to make sure this remains the default.  We are also adding the &lt;code&gt;vagrant&lt;/code&gt; user as an RVM system user to avoid needing &lt;code&gt;rvm-sudo&lt;/code&gt; when running ruby executables.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ruby
class doinstall {
  class { requirements:, stage =&amp;gt; &amp;quot;req-install&amp;quot; }
  include installrvm
}

include doinstall
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we hook our requirements setup into our custom Puppet run stage and install both the requirements and RVM setups we defined.  The final line runs our setup.&lt;/p&gt;

&lt;h3&gt;Running Vagrant for the first time&lt;/h3&gt;

&lt;p&gt;For reference, your project directory should now look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
your_project/
  puppet/
    manifests/
      development.pp
    modules/
      rvm/
        ...
  Vagrantfile
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can run &lt;code&gt;vagrant up&lt;/code&gt; and watch as Vagrant sets up the VM instance and installs all of our pre-requisites.  This may take some time depending on the speed of your system.&lt;/p&gt;

&lt;p&gt;Once the VM is up and running, follow the &lt;a href="http://vagrantup.com/docs/getting-started/ssh.html"&gt;Vagrant SSH instructions&lt;/a&gt; to SSH into the VM. Once in the VM, do the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cd /vagrant
rvm use 1.9.3
gem install rails
rails new .
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will install rails and setup a new application within the project directory.  A good idea here is to use an &lt;code&gt;.rvmrc&lt;/code&gt; file to automatically use the version of ruby we want as well as a gemset for our application:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
# .rvmrc
rvm use 1.9.3@your_project --create
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, add this project into your favorite source control and you&amp;#39;re good to go!&lt;/p&gt;

&lt;h3&gt;Links&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://vagrantup.com/"&gt;Vagrant&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/blt04/puppet-rvm"&gt;puppet-rvm&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Rewriting Online Real Estate with Fizbeaux.com</title>
    <link rel="alternate" href="/articles/2012/03/14/rewriting-online-real-estate-with-fizbeaux.html"/>
    <id>/articles/2012/03/14/rewriting-online-real-estate-with-fizbeaux.html</id>
    <published>2012-03-14T00:00:00Z</published>
    <updated>2012-03-14T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;&lt;a href="http://siliconbayounews.com/"&gt;Silicon Bayou News&lt;/a&gt; has written an article about our newest product, &lt;a href="http://fizbeaux.com"&gt;Fizbeaux.com&lt;/a&gt;. We&amp;#39;re trying to change the local real estate world by making it easier for independent sellers to list and sell their home online. We&amp;#39;re also changing the way potential buyers search for and find properties online, with advanced tools and maps.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;&lt;a href="http://siliconbayounews.com/"&gt;Silicon Bayou News&lt;/a&gt; has written an article about our newest product, &lt;a href="http://fizbeaux.com"&gt;Fizbeaux.com&lt;/a&gt;. We&amp;#39;re trying to change the local real estate world by making it easier for independent sellers to list and sell their home online. We&amp;#39;re also changing the way potential buyers search for and find properties online, with advanced tools and maps.&lt;/p&gt;

&lt;p&gt;Are you looking to sell your home online? Give &lt;a href="http://fizbeaux.com"&gt;Fizbeaux&lt;/a&gt; a try today.&lt;/p&gt;

&lt;p&gt;Read more: &lt;a href="http://siliconbayounews.com/2012/02/22/phaseshift-rewrites-online-real-estate-with-fizbeaux-com/"&gt;Phase Shift Rewrites Online Real Estate with Fizbeaux.com&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Setting up a custom Weave 0.5 server</title>
    <link rel="alternate" href="/articles/2009/10/09/setting-up-a-custom-weave-0-5-server.html"/>
    <id>/articles/2009/10/09/setting-up-a-custom-weave-0-5-server.html</id>
    <published>2009-10-09T00:00:00Z</published>
    <updated>2009-10-09T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;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&amp;#39;s servers  to store your information.  This guide, however, is for anyone interested in setting up their own secure Weave server.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;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&amp;#39;s servers  to store your information.  This guide, however, is for anyone interested in setting up their own secure Weave server.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;Assumptions&lt;/h3&gt;

&lt;p&gt;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&amp;#39;t be enabled on that server.&lt;/p&gt;

&lt;h3&gt;Server Configuration&lt;/h3&gt;

&lt;p&gt;First things, grab the latest version of the Weave Server from Mozilla Labs at &lt;a href="http://hg.mozilla.org/labs/weaveserver"&gt;http://hg.mozilla.org/labs/weaveserver&lt;/a&gt; in whichever format you prefer.  Extract the files into a folder accessible by your web server.  The &amp;quot;server&amp;quot; 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):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::apache
&amp;lt;VirtualHost weave.my.domain:443&amp;gt;

  ServerName weave.my.domain
  DocumentRoot /var/www/weaveserver/server/

  ErrorLog /var/log/apache2/weave-error.log
  CustomLog /var/log/apache2/weave-access.log combined

  SSLEngine on
  SSLCertificateFile /path/to/server.cert.crt
  SSLCertificateKeyFile /path/to/server.cert.key

  &amp;lt;Directory &amp;quot;/var/www/weaveserver/server/&amp;quot;&amp;gt;

    Options Indexes FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
    AuthType Basic
    AuthName &amp;quot;Weave Server&amp;quot;
    AuthUserFile /path/to/auth/file
    require valid-user

  &amp;lt;/Directory&amp;gt;

  Alias /0.5 /var/www/weaveserver/server/0.5/index.php
  Alias /user/1 /var/www/weaveserver/server/user/1/index.php

&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;Generating a Self-Signed SSL Certificate&lt;/h3&gt;

&lt;p&gt;First, generate a key:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl genrsa -des3 -out server.key 1024
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Generate a certificate signing request (CSR):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl req -new -key server.key -out server.csr
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Optional – At this point you can remove the password from the key if you wish… please be aware of the security risks before doing this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cp server.key server.key.pass
openssl rsa -in server.key.pass -out server.key
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, generate the certificate:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Make sure the Apache Virtual Host configuration paths match the locations of the key and certificate files.&lt;/p&gt;

&lt;h3&gt;Creating a Password File&lt;/h3&gt;

&lt;p&gt;Generate an &lt;code&gt;htpasswd&lt;/code&gt; file using the following command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
htpasswd -c weaveserver.pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will be prompted to enter a password for the user you created.  Make sure to update the &lt;code&gt;AuthUserFile&lt;/code&gt; path in the Apache Virtual Server config to point to this file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You need to have the same user name(s) and password(s) in the &lt;code&gt;htpasswd&lt;/code&gt; file as you plan on having setup in the Weave user database table (covered later).&lt;/p&gt;

&lt;h3&gt;Database Setup&lt;/h3&gt;

&lt;p&gt;Create a new database and create the two tables as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::sql
CREATE DATABASE weave;
USE weave;

CREATE TABLE `wbo` (
  `username` varbinary(32) NOT NULL default &amp;#39;&amp;#39;,
  `collection` varbinary(64) NOT NULL default &amp;#39;&amp;#39;,
  `id` varbinary(64) NOT NULL default &amp;#39;&amp;#39;,
  `parentid` varbinary(64) default NULL,
  `predecessorid` varbinary(64) default NULL,
  `modified` decimal(12,2) default NULL,
  `sortindex` int(11) default NULL,
  `depth` tinyint(4) default NULL,
  `payload` longtext,
  `payload_size` int(11) default NULL,
  PRIMARY KEY  (`username`,`collection`,`id`),
  KEY `parentindex` (`username`,`collection`,`parentid`),
  KEY `modified` (`username`,`collection`,`modified`),
  KEY `weightindex` (`username`,`collection`,`sortindex`),
  KEY `predecessorindex` (`username`,`collection`,`predecessorid`),
  KEY `size_index` (`username`,`payload_size`)
) ENGINE=InnoDB;

CREATE TABLE `users`
(
  `username` varchar(32) PRIMARY KEY,
  `md5` varbinary(32),
  `email` varbinary(64),
  `status` tinyint,
  `location` text,
  `alert` text
) ENGINE=InnoDB;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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 syntax:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::sql
GRANT SELECT, INSERT, UPDATE, DELETE ON weave.* TO &amp;#39;myuser&amp;#39;@&amp;#39;localhost&amp;#39;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you are creating this user, be sure to set the password by adding &amp;quot; IDENTIFIED BY &amp;#39;mypassword&amp;#39; &amp;quot; on the end of the above statement.&lt;/p&gt;

&lt;h3&gt;Weave Server Configuration&lt;/h3&gt;

&lt;p&gt;Navigate to the &lt;code&gt;weaverserver/server/user/1&lt;/code&gt; folder. Copy &lt;code&gt;weave_user_constants.php.dist&lt;/code&gt; to &lt;code&gt;weave_user_constants.php&lt;/code&gt; and set the following items:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::php
&amp;lt;?php
...
define(&amp;#39;WEAVE_STORAGE_ENGINE&amp;#39;, &amp;#39;mysql&amp;#39;);
...
define(&amp;#39;WEAVE_MYSQL_STORE_READ_HOST&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_STORE_READ_DB&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_STORE_READ_USER&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_STORE_READ_PASS&amp;#39;, &amp;#39;&amp;#39;);
...
define(&amp;#39;WEAVE_AUTH_ENGINE&amp;#39;, &amp;#39;mysql&amp;#39;);
...
define(&amp;#39;WEAVE_MYSQL_AUTH_HOST&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_AUTH_DB&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_AUTH_USER&amp;#39;, &amp;#39;&amp;#39;);
define(&amp;#39;WEAVE_MYSQL_AUTH_PASS&amp;#39;, &amp;#39;&amp;#39;);
...
define(&amp;#39;WEAVE_REGISTER_STORAGE_LOCATION&amp;#39;, &amp;#39;weave.my.domain&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Now do essentially the exact same steps for &lt;code&gt;weaveserver/server/0.5/default_constants.php.dist&lt;/code&gt;. That is, copy it over to &lt;code&gt;default_constants.php&lt;/code&gt; 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 &lt;code&gt;WEAVE_REGISTER_STORAGE_LOCATION&lt;/code&gt;, which will not exist, set the following line if both the authentication and store tables are in the same database:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::php
&amp;lt;?php
...
define(&amp;#39;WEAVE_SHARE_DBH&amp;#39;, &amp;#39;1&amp;#39;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you are using different databases, just leave this one alone. Also, you can easily use Sqlite as well by setting the various &lt;code&gt;engine&lt;/code&gt; variables to &lt;code&gt;sqlite&lt;/code&gt; and configuring the path to the stores (this is pretty self explanatory once you read through the constants files).&lt;/p&gt;

&lt;h3&gt;CAPTCHA&lt;/h3&gt;

&lt;p&gt;If you want to use CAPTCHA when creating an account, you will need to grab a public and private key from &lt;a href="http://recaptcha.net"&gt;http://recaptcha.net&lt;/a&gt; and make some changes to the Apache and Weaver Server configs. This is completely optional (just ignore the CAPTCHA field if you don&amp;#39;t set this up when creating a new user).&lt;/p&gt;

&lt;p&gt;Back in &lt;code&gt;weaveserver/server/user/1/weave_user_constants.php&lt;/code&gt; set the following to &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::php
&amp;lt;?php
...
define(&amp;#39;WEAVE_REGISTER_USE_CAPTCHA&amp;#39;, 1);
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;:::apache
Alias /misc/1/captcha_html /server/misc/1/captcha.php
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Test It!&lt;/h3&gt;

&lt;p&gt;Now everything should be configured, so install the Weave add-on for Firefox if you haven&amp;#39;t already (&lt;a href="http://labs.mozilla.com/weave/"&gt;http://labs.mozilla.com/weave/&lt;/a&gt;). At the time of writing this, the latest was 0.7.&lt;/p&gt;

&lt;p&gt;Open a new tab in Firefox and type &lt;code&gt;about:config&lt;/code&gt; and search for &lt;code&gt;extensions.weave.clusterURL&lt;/code&gt;. Set this to your Weave Server URL (i.e. &lt;code&gt;https://weave.my.domain/&lt;/code&gt;). Make sure to include the trailing slash.&lt;/p&gt;

&lt;p&gt;Now open weave and go to the user creation screen. At the bottom of the form box there is an option that says &amp;quot;Create my account with:,&amp;quot; select &amp;quot;A custom Weave server&amp;quot; and input your server into the textbox below (i.e. – &lt;code&gt;https://weave.my.domain/&lt;/code&gt;). Again here, make sure you include a trailing slash as the underlying code doesn&amp;#39;t check and append if needed.&lt;/p&gt;

&lt;p&gt;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 -&amp;gt; debug log to see what the problem is). If you didn&amp;#39;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 &amp;quot;Signed in as&amp;quot; -&amp;gt; &amp;quot;Sync now&amp;quot; in the upper right. If everything went correctly, your data should be sent over SSL and encrypted into your server&amp;#39;s database.&lt;/p&gt;

&lt;h3&gt;References&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://wiki.mozilla.org/Labs/Weave/0.5/Setup/Storage"&gt;Weave Storage / Server Setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.mozilla.org/Labs/Weave/User/1/Setup"&gt;Weave User Setup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://labs.mozilla.com/weave/"&gt;Weave Page on Mozilla Labs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.akadia.com/services/ssh_test_certificate.html"&gt;Creating a Self Signed SSL Certificate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://httpd.apache.org/docs/2.0/programs/htpasswd.html"&gt;htpasswd Apache Reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Multiple Secure Subdomains with a Wildcard SSL Certificate</title>
    <link rel="alternate" href="/articles/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate.html"/>
    <id>/articles/2008/10/27/multiple-secure-subdomains-with-a-wildcard-ssl-certificate.html</id>
    <published>2008-10-27T00:00:00Z</published>
    <updated>2008-10-27T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;This guide is a walk through for configuring multiple secure subdomains using a wildcard SSL certificate and Apache2 on Ubuntu 8.04.&lt;/p&gt;

&lt;p&gt;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, &lt;code&gt;example.com&lt;/code&gt;, it is convenient to organize things into subdomains. For example, maybe you have code repositories at &lt;code&gt;code.example.com&lt;/code&gt; or a development environment for testing at &lt;code&gt;test.example.com&lt;/code&gt;. But what if you want both of these subdomains to be secure? A standard SSL certificate for &lt;code&gt;example.com&lt;/code&gt; 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 and time consuming. Wildcard SSL certificates allow a single certificate for any immediate subdomain of the base, i.e. &lt;code&gt;*.example.com&lt;/code&gt;.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;This guide is a walk through for configuring multiple secure subdomains using a wildcard SSL certificate and Apache2 on Ubuntu 8.04.&lt;/p&gt;

&lt;p&gt;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, &lt;code&gt;example.com&lt;/code&gt;, it is convenient to organize things into subdomains. For example, maybe you have code repositories at &lt;code&gt;code.example.com&lt;/code&gt; or a development environment for testing at &lt;code&gt;test.example.com&lt;/code&gt;. But what if you want both of these subdomains to be secure? A standard SSL certificate for &lt;code&gt;example.com&lt;/code&gt; 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 and time consuming. Wildcard SSL certificates allow a single certificate for any immediate subdomain of the base, i.e. &lt;code&gt;*.example.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So problem solved right? Well, not exactly... 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.&lt;/p&gt;

&lt;h3&gt;Generating the Wildcard Certificate&lt;/h3&gt;

&lt;p&gt;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 &lt;code&gt;sudo&lt;/code&gt; all of the below commands):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
apt-get install apache2 apache2-common
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we can generate the certificate. First we generate a key:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl genrsa -out server.key 2048
chmod 400 server.key
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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 prompted for Common Name, you would normally enter your domain name. We want a wildcard so enter &lt;code&gt;*.example.com&lt;/code&gt;, replacing &lt;code&gt;example.com&lt;/code&gt; with your domain name:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl req -new -key server.key -out server.csr
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Configuring Apache&lt;/h3&gt;

&lt;p&gt;First enable the Apache SSL module if it isn&amp;#39;t already:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
a2enmod ssl
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We also need to enable the &lt;code&gt;vhost_alias&lt;/code&gt; module:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
a2enmod vhost_alias
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Apache needs to be told to listen on port 443. Edit the &lt;code&gt;ports.conf&lt;/code&gt; file in &lt;code&gt;/etc/apache2&lt;/code&gt; and add the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::apache
Listen 443
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;:::bash
vi /etc/apache2/sites-available/ssl.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now to configure the Virtual Host. Add the following to the newly created file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::apache
ServerAdmin webmaster@localhost
ServerName *.example.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM
VirtualDocumentRoot /var/www/%0/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A little explanation is in order here. The &lt;code&gt;ServerName&lt;/code&gt; (and any &lt;code&gt;ServerAlias&lt;/code&gt; as well) uses the wildcard notation (i.e. &lt;code&gt;*.example.com&lt;/code&gt;) since we want to handle multiple subdomains. Next are the directives to enable SSL and you will need to adjust the &lt;code&gt;SSLCertificateFile&lt;/code&gt; path to point to your certificate. The last line is where the magic happens using the &lt;a href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#virtualdocumentroot"&gt;&lt;code&gt;VirtualDocumentRoot&lt;/code&gt;&lt;/a&gt; directive. Thanks to the &lt;code&gt;vhost_alias&lt;/code&gt; module, we can set the document root based on the address.&lt;/p&gt;

&lt;p&gt;Say we have the two example subdomains from earlier, &lt;code&gt;code.example.com&lt;/code&gt; and &lt;code&gt;test.example.com&lt;/code&gt;. We have our wildcard certificate in place and someone tries to go to &lt;code&gt;http://code.example.com&lt;/code&gt;. The &lt;code&gt;%0&lt;/code&gt; signifies that the entire string from the address should be substituted, yielding a &lt;code&gt;DocumentRoot&lt;/code&gt; of &lt;code&gt;/var/www/code.example.com&lt;/code&gt;. If someone tried &lt;code&gt;test.example.com&lt;/code&gt;, it would become &lt;code&gt;/var/www/test.example.com&lt;/code&gt;. &lt;a href="http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html"&gt;The documentation on the &lt;code&gt;vhost_alias&lt;/code&gt; module&lt;/a&gt; shows all the options for getting parts or all of the address string for substituting into the &lt;code&gt;DocumentRoot&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;/var/www/&amp;lt;full subdomain path&amp;gt;&lt;/code&gt;. But being forced to use a consistent naming scheme for your sites (which should probably be done anyway...) is a pretty good tradeoff for running multiple secure subdomains on a single IP address with a single SSL certificate.&lt;/p&gt;

&lt;p&gt;One last thing, make sure to reload Apache so the changes take effect:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
/etc/init.d/apache force-reload
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you are looking for a good host that will give you full control over your server, be sure to check out &lt;a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a"&gt;Linode&lt;/a&gt;. We use them for all our Linux hosting and love it!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Installing MySQL gem on Windows &amp; cygwin for Rails</title>
    <link rel="alternate" href="/articles/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails.html"/>
    <id>/articles/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails.html</id>
    <published>2008-10-26T00:00:00Z</published>
    <updated>2008-10-26T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;This post assumes that you&amp;#39;ve followed the Setting up Rails on Windows with Cygwin guide and are using Cygwin on Windows for your Rails development.&lt;/p&gt;

&lt;p&gt;If you&amp;#39;re upgrading to Rails 2.2 (or running on edge), you&amp;#39;ll need to build the mysql gem from source, as it&amp;#39;s being removed from the Rails pacakge. You&amp;#39;ll know if you need to do this if you get the following error when building your app:&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;This post assumes that you&amp;#39;ve followed the Setting up Rails on Windows with Cygwin guide and are using Cygwin on Windows for your Rails development.&lt;/p&gt;

&lt;p&gt;If you&amp;#39;re upgrading to Rails 2.2 (or running on edge), you&amp;#39;ll need to build the mysql gem from source, as it&amp;#39;s being removed from the Rails pacakge. You&amp;#39;ll know if you need to do this if you get the following error when building your app:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Installing Mysql from Source&lt;/h3&gt;

&lt;p&gt;First thing you&amp;#39;ll need to do is to &lt;a href="http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz/from/pick#mirrors"&gt;download the source files from MySQL&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The next steps are all from the command line (and will probably take a while to complete!):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
tar xzvf mysql-5.0.67.tar.gz
cd mysql-5.0.57
./configure
make
make install
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;:::bash
readline/readline.h:70:29: sys/ttydefaults.h: No such file or directory
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The easiest way to solve this issue is to download the &lt;code&gt;readline&lt;/code&gt; packages from cygwin (using the cygwin installer) and running&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
./configure --without-readline CFLAGS=-O2
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Instead of plain &lt;code&gt;./configure&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also note, if you&amp;#39;ve already run &lt;code&gt;./configure&lt;/code&gt; you&amp;#39;ll need to clean up the directory by running&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
make distclean
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will actually install the entire MySQL library, but we won&amp;#39;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&amp;#39;re good to go:&lt;/p&gt;

&lt;p&gt;gem install mysql
Don&amp;#39;t forget to tell MySQL which configuration we want to load. By default, it&amp;#39;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 &lt;a href="http://phaseshiftllc.com/archives/2008/10/02/setting-up-rails-on-windows-with-cygwin#cygwin-rails-mysql"&gt;Getting Cygwin/Rails to work with MySQL section&lt;/a&gt; of our previous guide.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Setting up Rails on Windows with Cygwin</title>
    <link rel="alternate" href="/articles/2008/10/02/setting-up-rails-on-windows-with-cygwin.html"/>
    <id>/articles/2008/10/02/setting-up-rails-on-windows-with-cygwin.html</id>
    <published>2008-10-02T00:00:00Z</published>
    <updated>2008-10-02T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: If you&amp;#39;re using Rails 2.2, you&amp;#39;ll need to &lt;a href="/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails.html"&gt;perform some extra work to get MySQL working&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Getting Started&lt;/h3&gt;

&lt;p&gt;I like developing in &lt;a href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;, but I don&amp;#39;t own a Mac.  I&amp;#39;ve found that setting up a Rails development environment within Windows can get frustrating and cumbersome at times.  I&amp;#39;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&amp;#39;s open up that command prompt and get started!&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: If you&amp;#39;re using Rails 2.2, you&amp;#39;ll need to &lt;a href="/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails.html"&gt;perform some extra work to get MySQL working&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Getting Started&lt;/h3&gt;

&lt;p&gt;I like developing in &lt;a href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;, but I don&amp;#39;t own a Mac.  I&amp;#39;ve found that setting up a Rails development environment within Windows can get frustrating and cumbersome at times.  I&amp;#39;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&amp;#39;s open up that command prompt and get started!&lt;/p&gt;

&lt;p&gt;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 &lt;a href="http://macromates.com/"&gt;Textmate&lt;/a&gt;. Textmate is awesome for Rails development, but it&amp;#39;s not available for Windows (&lt;a href="http://blog.macromates.com/2005/windowslinux-alternative/"&gt;and will probably never be&lt;/a&gt;). Luckily, Alexander Stigsen has been developing a great &lt;a href="http://www.e-texteditor.com/"&gt;Textmate app for Windows called &amp;quot;e&amp;quot;&lt;/a&gt;. 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&amp;#39;ll get Cygwin as part of the package.&lt;/p&gt;

&lt;p&gt;If you don&amp;#39;t want to use e, that&amp;#39;s cool too.  Just &lt;a href="http://www.cygwin.com/"&gt;download the Cygwin setup file&lt;/a&gt; and follow the same steps (just ignore any asides about setting up e).  Let&amp;#39;s roll.&lt;/p&gt;

&lt;h3&gt;Installing Cygwin&lt;/h3&gt;

&lt;p&gt;First things first and that&amp;#39;s installing Cygwin.  Either grab the &lt;a href="http://www.cygwin.com/"&gt;Cygwin standalone setup&lt;/a&gt;, or &lt;a href="http://www.e-texteditor.com/"&gt;grab and install e&lt;/a&gt; and get to the Cygwin setup screens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note to e users&lt;/strong&gt;: e will setup and install Cygwin the first time you run e, not upon installation of e.  Also, make sure to select &amp;quot;manual&amp;quot; configuration of Cygwin instead of &amp;quot;automatic&amp;quot;.&lt;/p&gt;

&lt;p&gt;In the package selection screen, select the libraries that you&amp;#39;ll need.   Note, to make the package selection easier, hit the &amp;quot;View&amp;quot; button to change from &amp;quot;category&amp;quot; to &amp;quot;full&amp;quot;.  For reference, here&amp;#39;s what I install (the bold ones are the really important ones for Rails):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ruby&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;subversion&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;make&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;openssh&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;openssl&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;openssl-devel&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sqlite&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;git (if you&amp;#39;re into that sort of thing)&lt;/li&gt;
&lt;li&gt;git-completion&lt;/li&gt;
&lt;li&gt;nano&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few other packages you may want to pick up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;gcc&lt;/li&gt;
&lt;li&gt;gcc-g++&lt;/li&gt;
&lt;li&gt;ImageMagick&lt;/li&gt;
&lt;li&gt;libmagick-devel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the Cygwin installation is complete, you&amp;#39;ll be ready to get Rails up and running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT NOTE&lt;/strong&gt;: Every command from this point assumes you are executing through a Cygwin command prompt (Not the Windows default command prompt). Also, I&amp;#39;m assuming you&amp;#39;re using nano as your text editor.  If not, just replace the command with your favorite one.&lt;/p&gt;

&lt;h3&gt;Installing Ruby Gems&lt;/h3&gt;

&lt;p&gt;You&amp;#39;ll need to pick up Ruby Gems to be able to get Rails going.  &lt;a href="http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz"&gt;Download the latest release&lt;/a&gt;, un-tar and run the setup script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz
tar -xzf rubygems-1.3.0.tgz
cd rubygems-1.3.0
ruby setup.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you get an error like &lt;code&gt;No such file to load -- ubygems (LoadError)&lt;/code&gt;, all you need to do is run the following from the command line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
unset RUBYOPT
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And rerun the Ruby Gems setup.&lt;/p&gt;

&lt;h3&gt;Install Rails (Finally!)&lt;/h3&gt;

&lt;p&gt;Once Ruby Gems is all set up, you&amp;#39;ll just need to run a few commands to get the rails and associated gems.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
gem install rails
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I like to install a few helpful gems to get things started:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
gem install capistrano mongrel railsmachine gem_plugin daemons rspec
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Testing It All Out&lt;/h3&gt;

&lt;p&gt;Open up a command prompt and type:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
rails test_site
cd test_site
./script/server
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Open up a browser and head to &lt;a href="http://localhost:3000"&gt;http://localhost:3000/&lt;/a&gt;.  Your rails site should be up and running!  Congratulations, you&amp;#39;re ready to work with Rails.&lt;/p&gt;

&lt;h3&gt;Getting Cygwin/Rails to Work With MySQL&lt;/h3&gt;

&lt;p&gt;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 &lt;a href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads"&gt;Windows version of MySQL&lt;/a&gt; (not the MySQL package via Cygwin).  Once MySQL is installed, you&amp;#39;ll need to setup a config file to tell Cygwin to use &lt;code&gt;127.0.0.1&lt;/code&gt; instead of &lt;code&gt;localhost&lt;/code&gt; when connecting (or you might run into an error saying it couldn&amp;#39;t find &lt;code&gt;tmp/mysql.sock&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;In Cygwin:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cd /etc/
nano my.cnf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Type the following into the file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ini
[client]
host=127.0.0.1
[mysqld]
host=127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Save the file and you&amp;#39;re done.  No more &lt;code&gt;mysql.sock&lt;/code&gt; errors!&lt;/p&gt;

&lt;h3&gt;Rails 2.2 Update for MySQL&lt;/h3&gt;

&lt;p&gt;If you&amp;#39;re using Rails 2.2, you&amp;#39;ll need to &lt;a href="/2008/10/26/installing-mysql-gem-on-windows-cygwin-for-rails.html"&gt;install MySQL and the gem from source&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you&amp;#39;re using MySQL on Windows, I suggest installing the &lt;a href="http://dev.mysql.com/downloads/gui-tools/5.0.html"&gt;MySQL GUI Tools Suite&lt;/a&gt;.  They&amp;#39;re great tools for managing and querying data from your MySQL databases.  Give them a try.&lt;/p&gt;

&lt;h3&gt;Nice Trick for e&lt;/h3&gt;

&lt;p&gt;A really nice thing about Textmate is the ability to cd into a rails directory and type:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
mate .
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cd ~/
nano bash.rc
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add the following to the file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
alias e=&amp;quot;cygstart e&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Save and close the file, restart Cywgin and try it out:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
e .
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Console 2&lt;/h3&gt;

&lt;p&gt;Cygwin&amp;#39;s console is pretty neat, but we can do better.  I personally love using &lt;a href="http://sourceforge.net/projects/console/"&gt;Console 2&lt;/a&gt;, which gives you the ability to put cygwin into a tabbed environment (among other things such as colors and transparency).&lt;/p&gt;

&lt;p&gt;Getting Cygwin to work with Console 2 is pretty straightforward.  Just install &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=43764"&gt;Console 2&lt;/a&gt; (be sure to get the 2.0 release *), Go to &amp;quot;Settings &amp;gt; Tabs&amp;quot; and click &amp;quot;Add&amp;quot;.  You can name the tab anything you&amp;#39;d like (&amp;quot;Cygwin&amp;quot; works just fine).  The only thing to do is set the &lt;code&gt;shell&lt;/code&gt; parameter to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::text
c:\cygwin\bin\bash --login -i
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Save the settings and now you&amp;#39;ve got a rocking command line app to do all of your Rails work in.&lt;/p&gt;

&lt;p&gt;* If you&amp;#39;re on Windows XP 64bit, you&amp;#39;ll need to download an older version of the 2.0 release.  I recommend getting version 2.00b124.&lt;/p&gt;

&lt;h3&gt;Start Programming Already!&lt;/h3&gt;

&lt;p&gt;As you can see, it doesn&amp;#39;t take too much work to have a great development environment for Rails on a Windows platform. Go start creating the next great app!&lt;/p&gt;

&lt;p&gt;One final note: I&amp;#39;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&amp;#39;re using Windows XP 64 bit (which you can find in the Console 2 notes above.&lt;/p&gt;

&lt;p&gt;Happy programming!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ubuntu 8.04 LTS 64-bit Server on Linode</title>
    <link rel="alternate" href="/articles/2008/08/07/ubuntu-804-lts-64-bit-server-on-linode.html"/>
    <id>/articles/2008/08/07/ubuntu-804-lts-64-bit-server-on-linode.html</id>
    <published>2008-08-07T00:00:00Z</published>
    <updated>2008-08-07T00:00:00Z</updated>
    <author>
      <name>Phase Shift, LLC</name>
    </author>
    <summary type="html">&lt;p&gt;This guide is a step by step walk through for setting up an Ubuntu 8.04 LTS 64-bit server on &lt;a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a"&gt;Linode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Assuming a &lt;a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a"&gt;Linode&lt;/a&gt; 360 with 12288 megs of space, partition as follows:&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;This guide is a step by step walk through for setting up an Ubuntu 8.04 LTS 64-bit server on &lt;a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a"&gt;Linode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Assuming a &lt;a href="http://www.linode.com/?r=272ff3b88d6cc2c100904e0ab73ba96305e2664a"&gt;Linode&lt;/a&gt; 360 with 12288 megs of space, partition as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ubuntu Image: 11776MB&lt;/li&gt;
&lt;li&gt;Swap: 512&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;Getting Started&lt;/h3&gt;

&lt;p&gt;First thing, grab your favorite text editor, such as nano or vi using aptitude or apt-get.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install nano
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you would like auto completion in interactive shells, edit your &lt;code&gt;bash.bashrc&lt;/code&gt; file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/bash.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and uncomment the following block to look as follows&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
[...]
# enable bash completion in interactive shells
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
[...]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For some reason &lt;code&gt;bash-completion&lt;/code&gt; is not installed by default&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install bash-completion
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There is no need to reboot, just restart bash and autocomplete should be working for interactive shells&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
bash
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To try it out, you can do something like &lt;code&gt;aptitude inst&amp;lt;tab&amp;gt;&lt;/code&gt; and it should complete as &lt;code&gt;aptitude install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you enjoy having using &lt;code&gt;manpages&lt;/code&gt;, you will need to install the man binary.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install man-db
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install locales
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and then define your locale information with the following command.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
localedef -i en_US -c -f UTF-8 en_US.UTF-8
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Be sure to replace the locale name if you need something other than &lt;code&gt;en_US&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now we need to get everything up to date&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude update
aptitude safe-upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Clean up any old update files and reclaim some space&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude autoclean
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Server Configuration&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://www.howtoforge.com/"&gt;HowtoForge&lt;/a&gt; has a great &lt;a href="http://www.howtoforge.com/perfect-server-ubuntu8.04-lts"&gt;guide for setting up an Ubuntu 8.04 server&lt;/a&gt;. 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.&lt;/p&gt;

&lt;p&gt;By default, Ubuntu will have DHCP enabled. To get a static IP address, edit the interfaces file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/network/interfaces
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Replace the line&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::text
iface eth0 inet dhcp
&lt;/code&gt;&lt;/pre&gt;

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

&lt;pre&gt;&lt;code&gt;:::bash
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Restart networking&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
/etc/init.d/networking restart
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Edit your hosts file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/hosts
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add a line mapping your host name to your server IP. For example&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
[...]
127.0.0.1    localhost
[...]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;becomes&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
[...]
127.0.0.1    localhost
192.168.1.150    example.com    example
[...]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Add the host name to the &lt;code&gt;hostname&lt;/code&gt; file (it should be empty)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/hostname
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and add your host name&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Start the &lt;code&gt;hostname.sh&lt;/code&gt; shell script&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
/etc/init.d/hostname.sh start
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Test that everything is working by running&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
hostname
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It should display your host name.&lt;/p&gt;

&lt;h3&gt;Install Applications&lt;/h3&gt;

&lt;h4&gt;MySQL&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install mysql-server mysql-client libmysqlclient15-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will be prompted to enter and re-enter a root password for MySQL.&lt;/p&gt;

&lt;h5&gt;Apache&lt;/h5&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
&lt;/code&gt;&lt;/pre&gt;

&lt;h5&gt;PHP5/Ruby&lt;/h5&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install 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
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/apache2/mods-available/dir.conf&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/apache2/mods-available/dir.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Change&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::apache
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to (adding &lt;code&gt;index.shtml index.php3&lt;/code&gt; to the line above)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::apache
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml index.php3
&lt;/code&gt;&lt;/pre&gt;

&lt;h6&gt;Enable common apache modules&lt;/h6&gt;

&lt;pre&gt;&lt;code&gt;:::bash
a2enmod ssl
a2enmod suexec
a2enmod include
a2enmod rewrite
&lt;/code&gt;&lt;/pre&gt;

&lt;h5&gt;&lt;a href="http://eaccelerator.net/"&gt;eAccelerator&lt;/a&gt; for PHP (optional)&lt;/h5&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cd /usr/src
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
tar -xvjf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
phpize
./configure
make
make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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 – in this case &lt;code&gt;www-data&lt;/code&gt;) by executing the commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
mkdir /tmp/eaccelerator
chown -R www-data:www-data /tmp/eaccelerator/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The last thing to do is to enable eAccelerator in your &lt;code&gt;php.ini&lt;/code&gt; file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/php5/apache2/php.ini
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And add the following lines to the end of the file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ini
;uncomment if you want to use as a Zend extension
;zend_extension=&amp;quot;/usr/lib/php5/eaccelerator.so&amp;quot;
extension=&amp;quot;eaccelerator.so&amp;quot;
eaccelerator.shm_size=&amp;quot;16&amp;quot;
eaccelerator.cache_dir=&amp;quot;/tmp/eaccelerator&amp;quot;
eaccelerator.enable=&amp;quot;1&amp;quot;
eaccelerator.optimizer=&amp;quot;1&amp;quot;
eaccelerator.check_mtime=&amp;quot;1&amp;quot;
eaccelerator.debug=&amp;quot;0&amp;quot;
eaccelerator.filter=&amp;quot;&amp;quot;
eaccelerator.shm_max=&amp;quot;0&amp;quot;
eaccelerator.shm_ttl=&amp;quot;0&amp;quot;
eaccelerator.shm_prune_period=&amp;quot;0&amp;quot;
eaccelerator.shm_only=&amp;quot;0&amp;quot;
eaccelerator.compress=&amp;quot;1&amp;quot;
eaccelerator.compress_level=&amp;quot;9&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For more information on what these settings do, check out the &lt;a href="http://eaccelerator.net/wiki/Settings"&gt;eAccelerator config file settings&lt;/a&gt; page.&lt;/p&gt;

&lt;p&gt;Reload Apache to load the new modules&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
/etc/init.d/apache2 force-reload
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Go to your site (i.e. &lt;code&gt;http://192.168.1.150&lt;/code&gt;) and you should see the default Apache page displaying &amp;quot;It works!&amp;quot;&lt;/p&gt;

&lt;p&gt;To test that Apache is parsing PHP, make a new php file for Apache to display&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /var/www/test.php
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and add the following&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::php
&amp;lt;?php
phpinfo();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Go to the test page (i.e. &lt;code&gt;http://192.168.1.150/test.php&lt;/code&gt;) and you should see all the information about your PHP install.&lt;/p&gt;

&lt;p&gt;It is a good idea to synchronize the clock to an internet time server&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install ntp ntpdate
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you want a little protection from brute force attacks, &lt;a href="http://www.fail2ban.org/"&gt;fail2ban&lt;/a&gt; is an easy tool that uses IPTables and does the hard stuff for you.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
aptitude install fail2ban
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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 grained control and still have the defaults in place to catch situations for which you haven&amp;#39;t defined rules. To start, copy over the main config file into a local config file to edit.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now edit the local config file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
nano /etc/fail2ban/jail.local
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The comments in the config file explain the options pretty well. A quick rundown of some of the basics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ignoreip&lt;/strong&gt; - Space separated list of IPs that will never be banned. Localhost is added by default, and you should add any machines that you don&amp;#39;t think fail2ban needs to monitor for brute force attacks (such as your personal computers).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bantime&lt;/strong&gt; - 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;maxretry&lt;/strong&gt; - The maximum number of login attempts before the IP is banned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;action&lt;/strong&gt; - This determines the how fail2ban reacts when an IP exceeds the allowed number of logins. There are 3 predefined shortcuts so you don&amp;#39;t have to figure out the syntax on this. The first, &lt;code&gt;action_&lt;/code&gt;, just bans the IP. &lt;code&gt;action_mw&lt;/code&gt; will ban the IP and send you an e-mail with a whois report on that IP. Last, &lt;code&gt;action_mwl&lt;/code&gt; 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 &lt;code&gt;action = %(action_)s&lt;/code&gt;. To change to one of the other shortcuts, replace only the &lt;code&gt;action_&lt;/code&gt; part. For example, if you wanted to ban with e-mail alerts containing the whois report and log file lines you would use &lt;code&gt;action = %(action_mwl)s&lt;/code&gt; since the shortcut for is &lt;code&gt;action_mwl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;destmail&lt;/strong&gt; - If you elect to receive emails from fail2ban, this specifies the e-mail address to which it should send the notifications.
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 &lt;code&gt;JAILS&lt;/code&gt; section. This is done by setting the &lt;code&gt;enabled&lt;/code&gt; flag to true for a given section. For the simple server above, I would recommend the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::ini
...
[ssh]
enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 6
...
[apache]
enabled = true
port    = http,https
filter  = apache-auth
logpath = /var/log/apache*/*error.log
maxretry = 6
...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After you get your configuration in place, restart the fail2ban service&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash
/etc/init.d/fail2ban
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I am not going to cover how to setup a mail server here because there is now a wonderful guide on HowToForge. Using the &lt;a href="http://www.howtoforge.com/"&gt;HowtoForge&lt;/a&gt; guide for &lt;a href="http://www.howtoforge.org/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04"&gt;Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 8.04 LTS)&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;Note that if you do use the mail server guide and run fail2ban, enable the &lt;code&gt;[postfix]&lt;/code&gt;, &lt;code&gt;[courierpop3]&lt;/code&gt;, &lt;code&gt;[courierimap]&lt;/code&gt;, and &lt;code&gt;[sasl]&lt;/code&gt; sections in the &lt;code&gt;fail2ban jail.local&lt;/code&gt; file.&lt;/p&gt;
</content>
  </entry>
</feed>

