<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <title>Slicehost Articles - Home</title>
  <id>tag:articles.slicehost.com,2009:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  
  <link href="http://articles.slicehost.com/" rel="alternate" type="text/html" />
  <updated>2009-07-17T12:04:41Z</updated>
  <link rel="self" href="http://feeds.feedburner.com/SlicehostArticles" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-17:11811</id>
    <published>2009-07-17T12:02:00Z</published>
    <updated>2009-07-17T12:04:41Z</updated>
    <category term="Debian - Lenny" />
    <category term="Nginx" />
    <category term="debian" />
    <category term="lenny" />
    <category term="nginx" />
    <link href="http://articles.slicehost.com/2009/7/17/debian-lenny-installing-nginx-via-aptitude" rel="alternate" type="text/html" />
    <title>Debian Lenny - Installing Nginx via aptitude</title>
<summary type="html">&lt;p&gt;&lt;a href="http://nginx.net/" title="Nginx home page"&gt;Nginx&lt;/a&gt; is a popular lightweight server for those who do not need the bulk and extra services that Apache may offer.&lt;/p&gt;

&lt;p&gt;This article will look at installing Nginx on a Debian Lenny Slice using the 'aptitude' package manager.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;&lt;a href="http://nginx.net/" title="Nginx home page"&gt;Nginx&lt;/a&gt; is a popular lightweight server for those who do not need the bulk and extra services that Apache may offer.&lt;/p&gt;

&lt;p&gt;This article will look at installing Nginx on a Debian Lenny Slice using the 'aptitude' package manager.&lt;/p&gt;
&lt;p&gt;Using the built-in package manager to install packages is a great idea as it solves dependency issues and you are assured of any security updates, if and when they occur.&lt;/p&gt;

&lt;p&gt;However, one drawback can be that it is rare for a version upgrade to be placed into the repositories.  As such, it is possible for a newer version of an application to be released and not be placed into the repository.&lt;/p&gt;

&lt;h3&gt;Versions&lt;/h3&gt;

&lt;p&gt;At the time of writing, aptitude will install Nginx version 0.6.32.&lt;/p&gt;

&lt;p&gt;However, at the time of writing, the latest stable version of Nginx is 0.7.61.  You can check the latest versions and change logs at the &lt;a href="http://nginx.net/" title="Nginx Home Page"&gt;main nginx site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Which one you choose is, of course, entirely up to you.&lt;/p&gt;

&lt;h3&gt;Install and Dependencies&lt;/h3&gt;

&lt;p&gt;Installing Nginx is incredibly simple as it involves only one command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo aptitude install nginx&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will install any and all dependencies that Nginx requires, such as libpcre.&lt;/p&gt;

&lt;h3&gt;Start&lt;/h3&gt;

&lt;p&gt;One odd thing is that Nginx is not started automatically:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/nginx start&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Done.&lt;/p&gt;

&lt;h3&gt;Navigate&lt;/h3&gt;

&lt;p&gt;Now simply navigate to your IP address, and you will see the wonderfully simple welcome screen:&lt;/p&gt;

&lt;p&gt;&lt;img title="Nginx Welcome Screen" src="http://articles.slicehost.com/assets/2009/2/26/nginx-welcome.jpg" alt="Nginx Welcome Screen" /&gt;&lt;/p&gt;

&lt;h3&gt;Init scripts&lt;/h3&gt;

&lt;p&gt;As you would imagine when installing an application with the aptitude package manager, all init scripts have been created and added to the relevant run levels.&lt;/p&gt;

&lt;p&gt;Controlling nginx is done with these commands:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/nginx start
...
sudo /etc/init.d/nginx stop
...
sudo /etc/init.d/nginx restart&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That's it.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Using the aptitude package manager makes the installation of Nginx and associated dependencies very simple indeed.&lt;/p&gt;

&lt;p&gt;The only thing to consider is the version disparity between the one offered by aptitude and the one available via source code.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>ismail</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-16:11725</id>
    <published>2009-07-16T11:33:00Z</published>
    <updated>2009-07-16T11:35:12Z</updated>
    <category term="Backup" />
    <category term="SSH" />
    <category term="Windows" />
    <category term="sftp" />
    <category term="ssh" />
    <category term="windows" />
    <category term="winscp" />
    <link href="http://articles.slicehost.com/2009/7/16/automate-file-transfer-with-winscp-2" rel="alternate" type="text/html" />
    <title>Automate File Transfer with WinSCP</title>
<summary type="html">&lt;p&gt;In our first   &lt;a href="http://articles.slicehost.com/2009/6/26/winscp"&gt;WinSCP article&lt;/a&gt; we installed WinSCP and explored some of its basic features . In this article we'll explore some advanced features of WinSCP including automated file transfers and synchronization.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;In our first   &lt;a href="http://articles.slicehost.com/2009/6/26/winscp"&gt;&lt;/p&gt;

&lt;h3&gt;How to automate file transfers&lt;/h3&gt;

&lt;p&gt;WinSCP provides a strong set of command line tools, useful for writing scripts. Let's open notepad in Windows and write our first script.&lt;/p&gt;

&lt;pre&gt;option batch on
option confirm off
open mySlice1
get /home/users/demo/example_file.txt C:\Backups\
exit&lt;/pre&gt;

&lt;p&gt;save this file as testScript.txt.&lt;/p&gt;

&lt;p&gt;Basically, we are telling WinSCP  that it can answer all prompts negatively and disable overwrite confirmation.&lt;/p&gt;

&lt;p&gt;Then the script opens our mySlice1 session which we configured in the first &lt;a href="http://articles.slicehost.com/2009/6/26/winscp"&gt;&lt;/p&gt;

&lt;p&gt;Click next to choose how frequently  we want to run the script. In this case, I chose daily. On the next screen set 8pm as the starting time.&lt;/p&gt;

&lt;p&gt;&lt;img title="task scheduler" src="http://articles.slicehost.com/assets/2009/7/12/taskScheduler6.JPG" alt="task scheduler"&gt;&lt;/p&gt;

&lt;p&gt;Nice!&lt;/p&gt;

&lt;h3&gt;How to Synchronize Directories&lt;/h3&gt;

&lt;p&gt;Sometimes it will be useful to work in a local directory and then synchronize those files with a directory on our slice.  WinSCP make this possible with a single command. &lt;/p&gt;

&lt;p&gt;Suppose we want to synchronize our local directory C:\www with our remote directory /home/demo/public_html. &lt;/p&gt;

&lt;pre&gt; winscp \command "option batch on" "open mySlice1" "synchronize remote C:\www /home/demo/public_html" "exit" &lt;/pre&gt; 

&lt;p&gt;Note that the remote directory must be specified after the local directory, otherwise the command doesn't work. For a full explanation of the syntax, please refer to the &lt;a href="http://winscp.net/eng/docs/script_commands#synchronize"&gt;official documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Quite a lot here, but as you see WinSCP makes our life easier with its scripting capability. By combining it with Windows Task Scheduler, we can automate  file transfer between slices and our local machines. Moreover, we can synchronize remote and local directories. WinSCP has lots of commands. Please check &lt;a href="true" /&gt;here&lt;/a&gt;  for WinSCP commands.&lt;/p&gt;

&lt;p&gt;Ismail&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Demond</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-15:11734</id>
    <published>2009-07-15T15:18:00Z</published>
    <updated>2009-07-15T15:18:52Z</updated>
    <category term="RHEL" />
    <category term="iptables" />
    <category term="rhel" />
    <category term="shorewall" />
    <link href="http://articles.slicehost.com/2009/7/15/rhel-shorewall-installation" rel="alternate" type="text/html" />
    <title>RHEL - Shorewall installation</title>
<summary type="html">&lt;p&gt;So you're ready to start installing applications on your slice and, rightly, you want to make sure that you're nice and secure.  IPTables, right?  Well, sure, but the only thing is that IPTables can be a messy beast to deal with.  That's where Shorewall comes in. &lt;/p&gt;

&lt;p&gt;Shorewall is the common name for the Shoreline firewall, a “wrapper” for IPTables that will handle all the heavy lifting for you.  This article will get you started, showing you how to get Shorewall on your system.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;So you're ready to start installing applications on your slice and, rightly, you want to make sure that you're nice and secure.  IPTables, right?  Well, sure, but the only thing is that IPTables can be a messy beast to deal with.  That's where Shorewall comes in. &lt;/p&gt;

&lt;p&gt;Shorewall is the common name for the Shoreline firewall, a “wrapper” for IPTables that will handle all the heavy lifting for you.  This article will get you started, showing you how to get Shorewall on your system.&lt;/p&gt;
&lt;p&gt;This article is the first in a series designed to get you started using the Shorewall firewall system.  Shorewall will help simplify tasks done with IPTables, making those tasks more intuitive and easier to deal with.  &lt;/p&gt;

&lt;h3&gt;Installation&lt;/h3&gt;

&lt;p&gt;Now then, I have good news and bad news for you.  The bad news is that you probably won't be able to get Shorewall with your standard RHEL package manager, YUM.  But don't worry, the good news is that it's still very easy to install with RPMs.&lt;/p&gt;

&lt;p&gt;Let's go ahead and get the packages.  Go ahead and change directories so that you're in your home directory and let's pull down the packages we need.  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd ~&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At the time of this writing, the latest stable version of Shorewall is 4.2.10-3.  That's the version that we're going to work with.  &lt;/p&gt;

&lt;p&gt;Currently, the standard version of Shorewall needs two packages, shorewall and shorewall-perl, to function.  Subsequent versions are reported to have those packages combined into one, but as of right now, we'll need both packages to get up and running.&lt;/p&gt;

&lt;p&gt;Let's get the RPMs downloaded onto our system.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget http://www.invoca.ch/pub/packages/shorewall/4.2/shorewall-4.2.10/shorewall-4.2.10-3.noarch.rpm

wget http://www.invoca.ch/pub/packages/shorewall/4.2/shorewall-4.2.10/shorewall-perl-4.2.10-3.noarch.rpm&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When it comes time to update, you can check on the &lt;a href="http://www.shorewall.net/download.htm"&gt;Shorewall download page&lt;/a&gt; for new versions to download.&lt;/p&gt;

&lt;p&gt;Okay now that we have the RPMs in our clutches, let's install them.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo rpm -ihv shorewall-*&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Don't look now, but you just installed Shorewall.  I told you, easy right?  Don't believe me?  Let's check:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo rpm -q shorewall
Password:
shorewall-4.2.10-3&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hard to argue with that. We've just installed and confirmed the latest version of Shorewall.  In the next article, we're going to set up a nice, basic one-interface configuration for it.  Excited?  Yep, me too.&lt;/p&gt;

&lt;p&gt;DP&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Matthew</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-14:8190</id>
    <published>2009-07-14T12:58:00Z</published>
    <updated>2009-07-14T12:59:52Z</updated>
    <category term="Gentoo" />
    <category term="gentoo" />
    <link href="http://articles.slicehost.com/2009/7/14/gentoo-portage-trouble-shooting" rel="alternate" type="text/html" />
    <title>Gentoo - Using Masked Packages</title>
<summary type="html">&lt;p&gt;When a package is masked, it means you have to explicitly alter some configuration files to emerge it.&lt;/p&gt;

&lt;p&gt;Usually packages are masked because they’re not considered stable enough for the standard Gentoo environment.
This can be because they just need more testing, or they’re incompatible with another package, or there may be something
seriously wrong with the package itself.&lt;/p&gt;

&lt;p&gt;In this article we’ll see how we can access these packages.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;When a package is masked, it means you have to explicitly alter some configuration files to emerge it.&lt;/p&gt;

&lt;p&gt;Usually packages are masked because they’re not considered stable enough for the standard Gentoo environment.
This can be because they just need more testing, or they’re incompatible with another package, or there may be something
seriously wrong with the package itself.&lt;/p&gt;

&lt;p&gt;In this article we’ll see how we can access these packages.&lt;/p&gt;
&lt;h3&gt;Warning!&lt;/h3&gt;

&lt;p&gt;Packages are usually masked for a very good reason.&lt;/p&gt;

&lt;p&gt;Although the aim of these articles is to assist in building a stable server environment and we do show you what to do, we recommend that you don’t unmask packages in most situations.&lt;/p&gt;

&lt;p&gt;Just keep in mind what we are trying to achieve when creating and building our Slice.&lt;/p&gt;

&lt;p&gt;Remembering these recommendations, let’s see what to do if we really need to have a masked package installed…&lt;/p&gt;

&lt;h3&gt;Using a masked package&lt;/h3&gt;

&lt;p&gt;In our example &lt;code&gt;esearch&lt;/code&gt; is masked; the stable version is broken and only the testing version is available.
This is what happens when we try to emerge &lt;code&gt;esearch&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ emerge -vp esearch
...
!!! All ebuilds that could satisfy &amp;quot;app-portage/esearch&amp;quot; have been masked.
!!! One of the following masked packages is required to complete your request:
- app-portage/esearch-0.7.1-r7 (masked by: ~amd64 keyword)
- app-portage/esearch-0.7.1-r6 (masked by: ~amd64 keyword)
- app-portage/esearch-0.7.1 (masked by: package.mask, ~amd64 keyword)
/usr/portage/profiles/package.mask:
# Paul Varner &amp;lt;fuzzyray@gentoo.org&amp;gt; (31 Dec 2008)
# Masked due to being broken with portage 2.1 and 2.2.
# Users can use either the unstable versions or switch to app-portage/eix&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are two types of masks in this output; &lt;em&gt;keyword masks&lt;/em&gt; &lt;code&gt;(masked by: ~amd64 keyword)&lt;/code&gt;,
and &lt;em&gt;hard masks&lt;/em&gt; &lt;code&gt;(masked by: package.mask)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Keyword Masks&lt;/h3&gt;

&lt;p&gt;Keywords are defined in the ebuild file itself; in this case:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/usr/portage/app-portage/esearch/esearch-0.7.1-r7.ebuild&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This mask is declaring that the version we want to install is flagged as ”&lt;em&gt;testing only&lt;/em&gt;” on our amd64 architecture Slice.&lt;/p&gt;

&lt;p&gt;We can enable the latest testing version on our system by adding the following line to &lt;code&gt;/etc/portage/package.keywords&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;=app-portage/esearch-0.7.1-r7 ~amd64&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can see more information on the syntax on this file by entering &lt;code&gt;man portage&lt;/code&gt; on the Linux command prompt:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;man portage&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once inside the &lt;code&gt;man&lt;/code&gt; program, you can type &lt;code&gt;/package.keywords&lt;/code&gt; and hit enter to find the correct place in the file.
Hitting the &lt;code&gt;q&lt;/code&gt; key will exit the &lt;code&gt;man&lt;/code&gt; program.&lt;/p&gt;

&lt;p&gt;Once the &lt;code&gt;package.keywords&lt;/code&gt; file has been updated, we should be able to emerge &lt;code&gt;esearch&lt;/code&gt; without any further problems.
As always, we’d test with &lt;code&gt;-vp&lt;/code&gt; first, then when we’re ready, run the real command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo emerge esearch&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Hard Masks&lt;/h3&gt;

&lt;p&gt;The other type of mask shown comes from the &lt;code&gt;package.mask&lt;/code&gt; file, indicating that the &lt;code&gt;0.7.1&lt;/code&gt; version is broken
or has a security risk and is not supported by the Gentoo team. In the emerge output, it looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;...
- app-portage/esearch-0.7.1 (masked by: package.mask, ~amd64 keyword)
/usr/portage/profiles/package.mask:
# Paul Varner &amp;lt;fuzzyray@gentoo.org&amp;gt; (31 Dec 2008)
# Masked due to being broken with portage 2.1 and 2.2.
# Users can use either the unstable versions or switch to app-portage/eix&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this particular case, there are two masks on this package; the &lt;em&gt;hard mask&lt;/em&gt; represented by &lt;code&gt;masked by: package.mask&lt;/code&gt;,
plus a keyword mask shown as &lt;code&gt;~amd64 keyword&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The last 3 lines of the output are actually an excerpt from the
&lt;code&gt;/usr/portage/profiles/package.mask&lt;/code&gt; file; they explain the reason that it is masked.&lt;/p&gt;

&lt;p&gt;To override the &lt;em&gt;hard mask&lt;/em&gt; we could add a line like this to &lt;code&gt;/etc/portage/package.unmask&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;=app-portage/esearch-0.7.1&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;More info on this file can be found in the portage man page.&lt;/p&gt;

&lt;p&gt;That’s the &lt;em&gt;hard mask&lt;/em&gt; out of the way, but we’d still need to get around the keyword mask if we wanted to emerge this
version of the &lt;code&gt;esearch&lt;/code&gt; package. 
To do this we could repeat the earlier process, only with a different version number, by adding a line like
the following to &lt;code&gt;/etc/portage/package.keywords&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;=app-portage/esearch-0.7.1 ~amd64&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Just be careful when installing these types of packages - they’re usually masked for a reason.&lt;/p&gt;

&lt;p&gt;matiu&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-14:11655</id>
    <published>2009-07-14T12:31:00Z</published>
    <updated>2009-07-14T12:34:32Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="Ruby on Rails" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <category term="passenger" />
    <category term="rails" />
    <link href="http://articles.slicehost.com/2009/7/14/debian-lenny-using-passenger-to-serve-your-applications-with-apache" rel="alternate" type="text/html" />
    <title>Debian Lenny - using passenger to serve your applications with Apache</title>
<summary type="html">&lt;p&gt;Following from the &lt;a href="http://articles.slicehost.com/2009/7/3/debian-lenny-installing-passenger-with-apache" title="Debian Lenny - passenger installation"&gt;first article&lt;/a&gt;, we now have passenger (mod_rails) installed.&lt;/p&gt;

&lt;p&gt;As such, we can move on and create a Ruby on Rails application and see how easy it is to serve using passenger.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Following from the &lt;a href="http://articles.slicehost.com/2009/7/3/debian-lenny-installing-passenger-with-apache" title="Debian Lenny - passenger installation"&gt;first article&lt;/a&gt;, we now have passenger (mod_rails) installed.&lt;/p&gt;

&lt;p&gt;As such, we can move on and create a Ruby on Rails application and see how easy it is to serve using passenger.&lt;/p&gt;
&lt;h3&gt;Rails application&lt;/h3&gt;

&lt;p&gt;Move into the public_html folder (if you don't have one, then simply create it):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd ~/public_html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then create a simple Ruby on Rails application:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rails testapp&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Done.&lt;/p&gt;

&lt;h3&gt;Virtual Host&lt;/h3&gt;

&lt;p&gt;To serve the Rails application, we need to create a virtual host:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/sites-available/testapp&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Although already mentioned, one of the exciting things about mod_rails is that you don't need any special settings in the virtual host configuration.&lt;/p&gt;

&lt;p&gt;The contents can be as simple as this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;

  ServerName  domain1.com
  ServerAlias www.domain1.com

  DocumentRoot /home/demo/public_html/testapp/public

&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Of course, you can add custom log file locations and other settings but the main thing to understand is the lack of proxy and port settings.&lt;/p&gt;

&lt;p&gt;Once done, we can enable the new site:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2ensite testapp&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Rewrite&lt;/h3&gt;

&lt;p&gt;As you may know, Rails applications make use of an .htaccess file for various rewrite rules.&lt;/p&gt;

&lt;p&gt;If this is a fresh Slice and you do not have the Apache rewrite module enabled, now would be a good time to enable it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2enmod rewrite&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Reload&lt;/h3&gt;

&lt;p&gt;Finally, restart Apache:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 restart&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note: If you get any port and NameVirtualHost errors on reloading Apache, please ensure you read the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1" title="Debian Lenny - Apache Virtual Hosts"&gt;Apache Virtual Hosts article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Done.&lt;/p&gt;

&lt;h3&gt;Is that it?&lt;/h3&gt;

&lt;p&gt;Yup. It really is that simple to serve Ruby on Rails applications with passenger (mod_rails).&lt;/p&gt;

&lt;p&gt;Additional Rails apps can be configured in the same way — create a vhost and it's done.&lt;/p&gt;

&lt;p&gt;Note: you may have noticed that we didn't even need to do anything special with regards to permissions here, as passenger will automatically run the application as the user who owns directory that the virtual host points to.  In my case, the 'public_html' directory is in the 'demo' users home directory, as such, my application is being run as the 'demo' user.  Which is a good thing.  We don't want it to be running as root.&lt;/p&gt;

&lt;h3&gt;Changes to the application&lt;/h3&gt;

&lt;p&gt;Whenever you deploy changes to your application all you need to do to is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;touch /home/demo/public_html/testapp/tmp/restart.txt&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That will enable the new content to be served — the command can be used in Capistrano or any script you use to deploy your applications.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Phusion's passenger (mod_rails) is easy to install and even easier to use.&lt;/p&gt;

&lt;p&gt;There are no ports or proxies or any other complicated configurations — passenger offers a great deal to the Ruby on Rails community.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Mike</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-14:11045</id>
    <published>2009-07-14T12:24:00Z</published>
    <updated>2009-07-14T20:02:16Z</updated>
    <category term="PostgreSQL" />
    <category term="Ubuntu - Hardy" />
    <category term="hardy" />
    <category term="Hardy" />
    <category term="postgresql" />
    <link href="http://articles.slicehost.com/2009/7/14/postgresql-creating-and-dropping-tables" rel="alternate" type="text/html" />
    <title>PostgreSQL - creating and dropping tables</title>
<summary type="html">&lt;p&gt;This article will explain how to create and drop database tables using the psql client.&lt;/p&gt;

&lt;p&gt;Many web frameworks, such as Ruby on Rails, handle creation and access to database tables automatically.  But it's a good idea to learn the basics of working with them manually; also, not everyone running a postgres server will use it in conjunction with a web framework.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;This article will explain how to create and drop database tables using the psql client.&lt;/p&gt;

&lt;p&gt;Many web frameworks, such as Ruby on Rails, handle creation and access to database tables automatically.  But it's a good idea to learn the basics of working with them manually; also, not everyone running a postgres server will use it in conjunction with a web framework.&lt;/p&gt;
&lt;h3&gt;Preparation&lt;/h3&gt;

&lt;p&gt;Going forward I'll assume you have a database and a normal database role: 'demodb1' owned by role 'demorole1'.&lt;/p&gt;

&lt;p&gt;See the &lt;a href="http://articles.slicehost.com/2009/5/7/postgresql-creating-and-deleting-roles" title="PostgreSQL - creating and dropping databases"&gt;creating and dropping roles&lt;/a&gt; and &lt;a href="http://articles.slicehost.com/2009/5/7/postgresql-creating-and-dropping-databases" title="PostgreSQL - creating and dropping databases"&gt;creating and dropping databases&lt;/a&gt; articles if you need help with role and database creation.&lt;/p&gt;

&lt;h3&gt;Connect with psql&lt;/h3&gt;

&lt;p&gt;Logged into my demo slice as a Linux user named "mike" I'll make a local TCP connection with psql:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mike@demo:~$ psql -U demorole1 -d demodb1 -h localhost
Password for user demorole1: 
Welcome to psql 8.3.6, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)

demodb1=&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once we're connected with psql we can get started with the SQL commands.  If you need help connecting to your postgres server, please see the three &lt;a href="http://articles.slicehost.com/2009/5/27/postgresql-making-connections-1" title="PostgreSQL - making connections #1"&gt;making connections&lt;/a&gt; articles in this series.&lt;/p&gt;

&lt;h3&gt;Creating a table&lt;/h3&gt;

&lt;p&gt;The first table within 'demodb1' will house a list of clients associated with our web app.&lt;/p&gt;

&lt;p&gt;We'll need a unique ID number and an email address for each client.  The following code can be pasted into our psql session; then we can hit enter to execute the command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CREATE TABLE clients (
    id serial PRIMARY KEY,
    email varchar(50)
    );&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Success! We now have a table named "clients" with two columns:&lt;/p&gt;

&lt;p&gt;The "id" column will consist of unique, automatically incrementing integers (the 'serial' data type) and will act as the primary key for the table. &lt;/p&gt;

&lt;p&gt;The "email" column will contain text strings no more than 50 characters long.&lt;/p&gt;

&lt;p&gt;For a complete explanation see &lt;a href="http://www.postgresql.org/docs/8.3/static/sql-createtable.html" title="PostgreSQL 8.3: CREATE TABLE"&gt;CREATE TABLE&lt;/a&gt; in the official documentation.&lt;/p&gt;

&lt;p&gt;Note that postgres responded with two (expected) notices regarding the consequences of our command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NOTICE:  CREATE TABLE will create implicit sequence &amp;quot;clients_id_seq&amp;quot; for serial column &amp;quot;clients.id&amp;quot;
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index &amp;quot;clients_pkey&amp;quot; for table &amp;quot;clients&amp;quot;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Listing all tables&lt;/h3&gt;

&lt;p&gt;We can get a list of all tables in the database to which we're connected using the '\dt' command in psql:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;demodb1=&amp;gt; \dt
          List of relations
 Schema |  Name   | Type  |   Owner   
--------+---------+-------+-----------
 public | clients | table | demorole1
(1 row)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Great, it shows the one table we've created so far.&lt;/p&gt;

&lt;p&gt;We can use the '\d' command with a table's name to inspect it more closely:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;demodb1=&amp;gt; \d clients
                                Table &amp;quot;public.clients&amp;quot;
 Column |         Type          |                      Modifiers                       
--------+-----------------------+------------------------------------------------------
 id     | integer               | not null default nextval('clients_id_seq'::regclass)
 email  | character varying(50) | 
Indexes:
    &amp;quot;clients_pkey&amp;quot; PRIMARY KEY, btree (id)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Nice, we can see the column names, the data types we specified, and any modifiers — the data type and modifiers listed for the "id" column are a consequence of the 'serial PRIMARY KEY' argument in our first 'CREATE TABLE' command above.&lt;/p&gt;

&lt;p&gt;Any indexes for the table will be reported too — note the one listed here matches up with the notices that appeared following our 'CREATE TABLE' command.&lt;/p&gt;

&lt;h3&gt;Renaming a table&lt;/h3&gt;

&lt;p&gt;We may occasionally need to rename a table, for clarity's sake or just personal preference; this is easily accomplished:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ALTER TABLE clients
    RENAME TO customers;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We'll paste it into psql, hit enter, and then rerun the '\dt' command to verify it worked:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;demodb1=&amp;gt; \dt
           List of relations
 Schema |   Name    | Type  |   Owner   
--------+-----------+-------+-----------
 public | customers | table | demorole1
(1 row)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Fanstastic! Note this 'ALTER' command doesn't change any data inside the table.&lt;/p&gt;

&lt;h3&gt;Dropping a table&lt;/h3&gt;

&lt;p&gt;Tables can be dropped (deleted) from our database using the 'DROP TABLE' command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DROPT TABLE customers;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;NOTE:  This deletion is irreversible; a dropped table and all the data it contains is permanently erased from the database.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Manual creation and management of tables in postgres is a useful skill.  Future articles in this series will explore other common commands for manipulating table objects and the data they contain.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Mike&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben H</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-14:10624</id>
    <published>2009-07-14T12:18:00Z</published>
    <updated>2009-07-14T12:18:38Z</updated>
    <category term="Django" />
    <category term="Ubuntu - Hardy" />
    <category term="django" />
    <category term="hardy" />
    <category term="Hardy" />
    <link href="http://articles.slicehost.com/2009/7/14/ubuntu-hardy-using-mod_python-to-serve-your-application" rel="alternate" type="text/html" />
    <title>Ubuntu Hardy - Using mod_python to Serve Your Application</title>
<summary type="html">&lt;p&gt;If you've followed the &lt;a href="http://articles.slicehost.com/2009/5/14/ubuntu-hardy-mod_python-installation" title="Ubuntu Hardy - mod_python Installation"&gt;previous article&lt;/a&gt; you should have Apache and mod_python ready to serve an app for you.&lt;/p&gt;

&lt;p&gt;In this article we'll create a basic Django app and setup the virtual host that will allow Apache and mod_python to work their magic.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;If you've followed the &lt;a href="http://articles.slicehost.com/2009/5/14/ubuntu-hardy-mod_python-installation" title="Ubuntu Hardy - mod_python Installation"&gt;previous article&lt;/a&gt; you should have Apache and mod_python ready to serve an app for you.&lt;/p&gt;

&lt;p&gt;In this article we'll create a basic Django app and setup the virtual host that will allow Apache and mod_python to work their magic.&lt;/p&gt;
&lt;h3&gt;Create the Django Application&lt;/h3&gt;

&lt;p&gt;First thing's first, move to your home directory and go into your public_html/domain1.com directory (if you don't have one, create one and of course give it the name of your domain rather than domain1.com):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd ~/public_html/domain1.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Next you'll want to create a Django project which is done simply with the django-admin.py tool.&lt;/p&gt;

&lt;p&gt;In this case we will call it 'testproject':&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;django-admin.py startproject testproject&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Create the Virtual Host&lt;/h3&gt;

&lt;p&gt;For Apache to be able to actually serve a Django application it needs to know that it should hand off certain requests to mod_python.  To accomplish this, we'll setup a virtual host that takes care of letting Apache know what to do in certain situations.&lt;/p&gt;

&lt;p&gt;This example is very basic but it will get you going:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/sites-available/domain1.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then type or copy the following virtual host definition:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
        ServerName domain1.com
        ServerAlias www.domain1.com

        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE testproject.settings
        PythonPath &amp;quot;['/home/demo/public_html/domain1.com'] + sys.path&amp;quot;
        PythonDebug On
&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once you've saved the virtual host you'll need to enable it and reload Apache:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2ensite domain1.com
sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Provided everything went as expected you should be able to visit your domain (or slice IP) in your browser and get your newly created Django application.  It should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://articles.slicehost.com/assets/2009/5/13/welcometodjango.png" alt="Welcome to Django" /&gt;&lt;/p&gt;

&lt;p&gt;Note: If you get any port and NameVirtualHost errors upon reloading Apache, please ensure you read the &lt;a href="http://articles.slicehost.com/2008/4/29/ubuntu-hardy-apache-virtual-hosts-1" title="Ubuntu Hardy - Apache Virtual Hosts #1"&gt;Apache Virtual Hosts article&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Static Content&lt;/h3&gt;

&lt;p&gt;There is a caveat to the virtual host definition provided, namely it does not allow serving of static content.&lt;/p&gt;

&lt;p&gt;That is to say, no document root was specified and there is nothing to indicate that static files are not to be handled by mod_python and Django.&lt;/p&gt;

&lt;p&gt;The Django team actually recommends you use a &lt;a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#serving-media-files"&gt;secondary web server to serve static content&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, you can make a few tweaks in your testproject/settings.py file and use the following virtual host definition:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
        ServerName domain1.com
        ServerAlias www.domain1.com

        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE testproject.settings
        PythonPath &amp;quot;['/home/demo/public_html/domain1.com'] + sys.path&amp;quot;
        PythonDebug On

        DocumentRoot /home/demo/public_html/domain1.com
        &amp;lt;Location &amp;quot;/static/&amp;quot;&amp;gt;
            SetHandler none
            Options -Indexes
        &amp;lt;/Location&amp;gt;
&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The Location block tells Apache to not let Django handle anything that's located under /static/ on your site.  You can set this to be anything you like, but you'll need to make the appropriate directory available under /home/demo/public_html/domain1.com.  In this example the directory would be called "static".&lt;/p&gt;

&lt;p&gt;Tweaks for the settings.py file involve setting the MEDIA_URL and MEDIA_ROOT settings appropriately:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nano /home/demo/public_html/domain1.com/testproject/settings.py&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Find the following two settings and edit them like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;MEDIA_ROOT = '/home/demo/public_html/domain1.com/static/'
MEDIA_URL = '/static/'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reload Apache now to make the updates take effect:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now any items placed in /home/demo/public_html/domain1.com/static can be accessed via http://domain1.com/static/path/to/file.&lt;/p&gt;

&lt;h3&gt;Changes to your Django Application&lt;/h3&gt;

&lt;p&gt;When you update your python code or templates in a Django application with mod_python, you'll usually need to give Apache a reload to see the changes.  So it's good to get into the habit of reloading Apache after making any changes to your project.&lt;/p&gt;

&lt;p&gt;At this point you should now be able to successfully build out a Django application and have mod_python and Apache serve it up for you.&lt;/p&gt;

&lt;p&gt;Ben H.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-07-03:11574</id>
    <published>2009-07-03T11:28:00Z</published>
    <updated>2009-07-03T11:29:12Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="Ruby on Rails" />
    <category term="debian" />
    <category term="lenny" />
    <category term="passenger" />
    <category term="rails" />
    <link href="http://articles.slicehost.com/2009/7/3/debian-lenny-installing-passenger-with-apache" rel="alternate" type="text/html" />
    <title>Debian Lenny - Installing Passenger with Apache</title>
<summary type="html">&lt;p&gt;&lt;a href="http://www.modrails.com/" title="mod_rails home page"&gt;Phusion's Passenger&lt;/a&gt; (mod_rails) is an exciting development in serving your Ruby on Rails application with the Apache web server.&lt;/p&gt;

&lt;p&gt;Incredibly simple to install and use, you can have a rails application up and running in no time. You don't even have to worry about ports or setting up a proxy to another server.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;&lt;a href="http://www.modrails.com/" title="mod_rails home page"&gt;Phusion's Passenger&lt;/a&gt; (mod_rails) is an exciting development in serving your Ruby on Rails application with the Apache web server.&lt;/p&gt;

&lt;p&gt;Incredibly simple to install and use, you can have a rails application up and running in no time. You don't even have to worry about ports or setting up a proxy to another server.&lt;/p&gt;
&lt;h3&gt;Prerequisites&lt;/h3&gt;

&lt;p&gt;To get the most out of this article you need to have a couple of things preinstalled:&lt;/p&gt;

&lt;p&gt;Firstly, you need Apache installed (see &lt;a href="http://articles.slicehost.com/2009/4/9/debian-lenny-installing-apache2-and-php5" title="Debian Lenny - Apache installation"&gt;this article&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Secondly, you need ruby and rubygems installed (if not please see the &lt;a href="http://articles.slicehost.com/2009/4/9/debian-lenny-ruby-on-rails" title="Debian Lenny - Ruby on Rails"&gt;Ruby on Rails article&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;mod_rails installation&lt;/h3&gt;

&lt;p&gt;Passenger (mod_rails) is a rubygem. &lt;/p&gt;

&lt;p&gt;Let's install the passenger gem:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo gem install passenger&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once completed, we need to install the Apache2 module:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo passenger-install-apache2-module&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A dialogue opens in the terminal and starts with:&lt;/p&gt;

&lt;p&gt;&lt;img title="mod_rails installation 1" src="http://articles.slicehost.com/assets/2009/1/24/passenger-apache-module-install.jpg" alt="mod_rails installation 1" /&gt;&lt;/p&gt;

&lt;p&gt;As suggested, press 'Enter/Return':&lt;/p&gt;

&lt;p&gt;&lt;img title="mod_rails installation 2" src="http://articles.slicehost.com/assets/2009/1/24/passenger-apache-module-install-notinstalled.jpg" alt="mod_rails installation 2" /&gt;&lt;/p&gt;

&lt;p&gt;I deliberately left the Apache headers off the installation until this point as I want to demonstrate how easy the installation is.&lt;/p&gt;

&lt;p&gt;The passenger (mod_rails) install has found a missing dependency — let's press 'Enter/Return':&lt;/p&gt;

&lt;p&gt;&lt;img title="mod_rails installation 3" src="http://articles.slicehost.com/assets/2009/1/24/passenger-apache-module-install-aptgetinstruct.jpg" alt="mod_rails installation 3" /&gt;&lt;/p&gt;

&lt;p&gt;How cool is that? It tells us what to do.&lt;/p&gt;

&lt;p&gt;Well, let's go ahead and install the headers (we'll use aptitude though):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo aptitude install apache2-prefork-dev&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once done, we can try the install again:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo passenger-install-apache2-module&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All being well, the install will complete with instructions at the end letting us know we need to add some lines to the main Apache2 config file.&lt;/p&gt;

&lt;p&gt;No problem:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/apache2.conf&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Passenger is an active gem and is being updated all the time. Rather than copy and paste the output I show below, please ensure you copy and paste the output from the install itself.&lt;/p&gt;

&lt;p&gt;At the time of writing the article, I installed passenger v2.2.4 — you may have installed a later version.&lt;/p&gt;

&lt;p&gt;So, for my v2.2.4 install, I added the following lines to my apache2.conf:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4
PassengerRuby /usr/bin/ruby1.8&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Apache restart&lt;/h3&gt;

&lt;p&gt;Now all we need to do is restart Apache:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 restart&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Done&lt;/h3&gt;

&lt;p&gt;That's all we need to do to install mod_rails onto our Slice.&lt;/p&gt;

&lt;p&gt;The next article will show how to create a Ruby on Rails application and serve it using passenger — an incredibly easy process.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>ismail</name>
    </author>
    <id>tag:articles.slicehost.com,2009-06-26:10173</id>
    <published>2009-06-26T12:47:00Z</published>
    <updated>2009-07-11T05:47:33Z</updated>
    <category term="SSH" />
    <category term="Windows" />
    <category term="sftp" />
    <category term="windows" />
    <category term="winscp" />
    <link href="http://articles.slicehost.com/2009/6/26/winscp" rel="alternate" type="text/html" />
    <title>WinSCP</title>
<summary type="html">&lt;p&gt;In this article you will learn how to securely transfer files between your windows machine and your slice, using the WinSCP application. You will also learn how to create new files and set their permissions.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;In this article you will learn how to securely transfer files between your windows machine and your slice, using the WinSCP application. You will also learn how to create new files and set their permissions.&lt;/p&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;

&lt;p&gt;WinSCP is an open-source free SFTP client and FTP client for Windows.  Its main function is safe copying and transfer of files between a local and remote computer.  Windows Vista SP1 was used for this article. Different versions of Windows may have slightly different screens.&lt;/p&gt;

&lt;h3&gt;Download and install&lt;/h3&gt;

&lt;p&gt;First, WinSCP should be downloaded from &lt;a href="http://winscp.net/eng/download.php" title="WinSCP download"&gt;this website&lt;/a&gt;.
After you download the installation file, double click the executable file of WinSCP. &lt;/p&gt;

&lt;p&gt;&lt;img src="http://articles.slicehost.com/assets/2009/4/15/setup-WinSCP.jpg"&gt; &lt;/p&gt;

&lt;p&gt;As you see you can check set permission box and set the permission for that directory by simply clicking R, W and X. You can also see the equivalent octal value for your settings. Please remember that we login as “sliceIsmail” so owner of the directory will be that user.
You can change permission of an existing file or directory by right clicking and then selecting “properties” from the menu.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;WinSCP is a great sftp client for windows users.  Files can be copied/pasted between your windows machine and your slice securely since all of the communication is encrypted. It also allows flexibility for creating, modifying files, and changing file permissions.
I will explain other features of WinSCP such as executing commands on the slice, how to automate file transfers, synchronization, etc., in the next article.&lt;/p&gt;

&lt;p&gt;Ismail&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-06-24:11301</id>
    <published>2009-06-24T13:19:00Z</published>
    <updated>2009-06-24T13:20:15Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <category term="vhosts" />
    <link href="http://articles.slicehost.com/2009/6/24/debian-lenny-apache-virtual-hosts-2" rel="alternate" type="text/html" />
    <title>Debian Lenny - Apache Virtual Hosts #2</title>
<summary type="html">&lt;p&gt;Following on from the first &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1" title="Debian Lenny - Apache Virtual Hosts #1"&gt;Debian Lenny - Apache Virtual Hosts&lt;/a&gt; article, we can now look in detail at some of the settings available to us in the Virtual Hosts file.&lt;/p&gt;

&lt;p&gt;This will enable us to have complete control of the domain we want to serve.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Following on from the first &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1" title="Debian Lenny - Apache Virtual Hosts #1"&gt;Debian Lenny - Apache Virtual Hosts&lt;/a&gt; article, we can now look in detail at some of the settings available to us in the Virtual Hosts file.&lt;/p&gt;

&lt;p&gt;This will enable us to have complete control of the domain we want to serve.&lt;/p&gt;
&lt;p&gt;Some of the settings discussed were introduced in the previous article but some are new.&lt;/p&gt;

&lt;p&gt;Take the time to read through the explanations and you will soon have an understanding of how powerful vhosts actually are.&lt;/p&gt;

&lt;h3&gt;Email&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ServerAdmin&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerAdmin webmaster@domain.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sets the email address for the server administrator - this will be used if you have setup the server to contact you on errors. It is also shown in the ServerSignature (if set to 'Email' - see below)&lt;/p&gt;

&lt;h3&gt;Domain Name&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ServerName&lt;/strong&gt; and &lt;strong&gt;ServerAlias&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerName domain.com
ServerAlias www.domain.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sets the domain name for the virtual host. You can have as many aliases as required. For example, you can have domain.com and domain.net point to the same content.&lt;/p&gt;

&lt;p&gt;Note this is not a rewrite rule (we'll look at those later) but the domains defined here will serve the same content (assuming you have set the DNS to point to your Slice IP).&lt;/p&gt;

&lt;h3&gt;Index Files&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;DirectoryIndex&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DirectoryIndex index.html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Defines the index file (the 'home' page that is shown on entering the domain address). Useful if you have want the user to be directed to an alternate page or to a non-standard home page.&lt;/p&gt;

&lt;p&gt;Do note this is not a good way of redirecting users as they may go directly to a non specified page such as domain.com/index.php whilst the DirectoryIndex will only work for those entering domain.com.&lt;/p&gt;

&lt;h3&gt;Documents&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;DocumentRoot&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DocumentRoot /home/demo/public_html/domain.com/public&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The location of the domain's public files. Use an absolute path name.&lt;/p&gt;

&lt;h3&gt;Log Files&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ErrorLog&lt;/strong&gt; and &lt;strong&gt;CustomLog&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;LogLevel warn
ErrorLog  /home/demo/public_html/domain.com/log/error.log
CustomLog /home/demo/public_html/domain.com/log/access.log combined&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Set the Log levels and the location for the Virtual Hosts log files. Very useful for easy analysis of the domain statistics.&lt;/p&gt;

&lt;h3&gt;Error Documents&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ErrorDocument&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Used for all the standard error messages.&lt;/p&gt;

&lt;p&gt;In these examples I have an 'errors' folder in my public directory. I created each error document and place them in the 'errors' folder. The paths shown are relative to the DocumentRoot folder defined above.&lt;/p&gt;

&lt;p&gt;If not defined, Apache will generate its own error pages. Custom error pages are more user friendly and can be customised as much, or as little, as you want.&lt;/p&gt;

&lt;h3&gt;Apache Footers&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ServerSignature&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerSignature On&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sets whether the server details are displayed in any server generated error pages or index lists. Options are On, Off and Email.&lt;/p&gt;

&lt;p&gt;Note the level of detail in the signature is configured via ServerTokens which cannot be set in the Virtual Hosts file — for Debian Lenny's Apache layout this is properly set in '/etc/apache2/conf.d/security'. See the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-2" title="Debian Lenny Apache configuration #2"&gt;Apache configuration #2&lt;/a&gt; article for more details.&lt;/p&gt;

&lt;p&gt;If set to Email, the ServerAdmin email will be displayed.&lt;/p&gt;

&lt;h3&gt;cgi-bin&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ScriptAlias&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ScriptAlias /cgi-bin/ /home/demo/public_html/domain.com/cgi-bin/
&amp;lt;Location /cgi-bin&amp;gt;
  Options +ExecCGI
&amp;lt;/Location&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Enables the cgi-bin location as defined by the custom virtual hosts layout. You can, of course, leave the cgi-bin in the DocumentRoot location if you so wish.&lt;/p&gt;

&lt;h3&gt;Directory&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;Directory /home/demo/public_html/domain.com/public&amp;gt;
  Options FollowSymLinks
&amp;lt;/Directory&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Set the Options for the specified directory - the example shown allows the Option FollowSymLinks to be enable for the public directory of domain.com&lt;/p&gt;

&lt;p&gt;Listed below are further Options that can be set:&lt;/p&gt;

&lt;h3&gt;Directory Browsing&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Options -Indexes&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To turn off directory browsing use '-Indexes' or 'None'. To turn them on, use '+Indexes'.&lt;/p&gt;

&lt;h3&gt;SSI&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Options -Includes&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This Option disables Server Side Inlcudes.  SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.&lt;/p&gt;

&lt;h3&gt;Symlinks&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Options&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Options -FollowSymLinks&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Enable or disable the option to follow symlinks. Be careful with this option as it can lead to security risks (inadvertently linking to configuration folders).&lt;/p&gt;

&lt;p&gt;You can consider using the SymLinksIfOwnerMatch directive instead of FollowSymLinks. The SymLinksIfOwnerMatch allows symbolic links to be followed only if the owner of the link is identical to the owner of the target file or directory (in terms of Linux filesystem ownership/permissions). Thus preventing many of the security risks that a simple FollowSymlinks directive can create.&lt;/p&gt;

&lt;h3&gt;.htaccess&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;AllowOverride&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;AllowOverride None&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Setting AllowOverride to none disables .htaccess support. Set to All to allow them.&lt;/p&gt;

&lt;p&gt;You can also specify which .htaccess features to enable such as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;AllowOverride AuthConfig Indexes&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The Apache &lt;a href="http://httpd.apache.org/docs/2.2/howto/htaccess.html" title="Apache Tutorial: .htaccess files"&gt;htaccess&lt;/a&gt; and &lt;a href="http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride" title="Apache AllowOverride Documentation"&gt;AllowOverride docs&lt;/a&gt; have more information on the different features.&lt;/p&gt;

&lt;p&gt;Remember to specifically protect your .htaccess file. This can be done in two ways:&lt;/p&gt;

&lt;p&gt;Firstly rename it to something obscure and, secondly, deny access to the file from external sources:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;AccessFileName .myobscurefilename
&amp;lt;Files ~ &amp;quot;^\.my&amp;quot;&amp;gt;
    Order allow,deny
    Deny from all
    Satisfy All
&amp;lt;/Files&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;No Options&lt;/h3&gt;

&lt;p&gt;This will turn off all the available options.  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Options None&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We'll see more of this directive later.&lt;/p&gt;

&lt;h3&gt;Hierarchy&lt;/h3&gt;

&lt;p&gt;Remember that the Options directives can be set per directory like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;Directory /&amp;gt;
  AllowOverride None
  Options None
&amp;lt;/Directory&amp;gt;

&amp;lt;Directory /home/demo/public_html/domain.com/public&amp;gt;
  AllowOverride All
&amp;lt;/directory&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will turn of all Options and disable .htaccess support for all directories.&lt;/p&gt;

&lt;p&gt;However, the second Directory setting will override the first and allow .htaccess support for the domain.com/public directory.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;The Virtual Hosts file is at once an easy tool to use and a very powerful one. My advice is to enter one setting and test it. Then enter the next setting and so on.&lt;/p&gt;

&lt;p&gt;Once familiar you will see you have fine control over all of your web folders and files.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Mike</name>
    </author>
    <id>tag:articles.slicehost.com,2009-06-08:10669</id>
    <published>2009-06-08T11:41:00Z</published>
    <updated>2009-06-08T11:42:42Z</updated>
    <category term="PostgreSQL" />
    <category term="Ubuntu - Hardy" />
    <category term="Hardy" />
    <category term="hardy" />
    <category term="postgresql" />
    <link href="http://articles.slicehost.com/2009/6/8/postgresql-making-connections-3" rel="alternate" type="text/html" />
    <title>PostgreSQL - making connections #3</title>
<summary type="html">&lt;p&gt;Following &lt;a href="http://articles.slicehost.com/2009/5/27/postgresql-making-connections-2" title="PostgreSQL - making connections #2"&gt;part 2&lt;/a&gt;, this article addresses some security-related concerns affecting postgres servers open to remote TCP connections.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Following &lt;a href="http://articles.slicehost.com/2009/5/27/postgresql-making-connections-2" title="PostgreSQL - making connections #2"&gt;part 2&lt;/a&gt;, this article addresses some security-related concerns affecting postgres servers open to remote TCP connections.&lt;/p&gt;
&lt;h3&gt;Motivation&lt;/h3&gt;

&lt;p&gt;As we worked through the previous article, we briefly considered several points regarding the security of our postgres server. We'll highlight them here, and address a few related concerns.&lt;/p&gt;

&lt;p&gt;TCP connectivity to a postgres server from remote hosts is a common requirement in the design of many web applications, but we want to make sure our databases are not exposed or weakened unnecessarily — the Internet is full of hackers and other unsavoury individuals who might like to steal or damage our data, or hijack our database server for nefarious purposes.&lt;/p&gt;

&lt;h3&gt;Port change&lt;/h3&gt;

&lt;p&gt;Port 5432, the default postgres listening port, is well known and relatively common — hackers and bots will check whether it's open when scanning an Internet host, such as a slice.&lt;/p&gt;

&lt;p&gt;One way to add a bit of extra protection to our postgres server is to change the port on which it's listening.  We can choose any integer between 1025 and 65536 that doesn't conflict with another process listening on our slice, '43210' for example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# - Connection Settings -

#listen_addresses = 'localhost, 123.45.67.890, 10.300.300.300'  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 43210                            # (change requires restart)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It's not a necessary change, just a simple protective measure we can take. If we do change it, our iptables rules will need updating and we'll have to specify the custom port in a web application's settings and for any port forwarded connections.&lt;/p&gt;

&lt;p&gt;For the remainder of this article and in subsequent articles, we'll stick with the default value (5432) for simplicity's sake.&lt;/p&gt;

&lt;h3&gt;Port exposure&lt;/h3&gt;

&lt;p&gt;We previously learned that our postgres server was configured by default to listen only on the slice's localhost interface (127.0.0.1).&lt;/p&gt;

&lt;p&gt;For the purposes of the tutorial, we re-configured it to listen on both the slice's public and private IPs. Further, we loaded an iptables rule that opened port 5432 on both IPs.  While this is convenient for exploration and testing of remote connections, doing so is not without long-term risks.&lt;/p&gt;

&lt;p&gt;If our postgres server is listening on the public IP, and iptables is allowing inbound connections, that means it's a potential target for brute force attacks or attempts at known exploits (if any are known or discovered).  And if it's listening on the private IP, an attack could come from another host on the Slicehost network — the latter is less likely than the former, but still a real possibility.&lt;/p&gt;

&lt;p&gt;We want to make choices for our postgres setup that minimize its exposure right from the start.&lt;/p&gt;

&lt;h3&gt;Listen on an interface only as needed&lt;/h3&gt;

&lt;p&gt;The primary thing we can do to limit our security risks is to specify a listening interface in  'postgresql.conf' only when it's truly required for our application.&lt;/p&gt;

&lt;p&gt;Hosts which are remote to the the Slicehost network — such as your local computer — will rarely need a persistent connection. SSH port forwarded connections will suffice, making it unnecessary to have postgres listen on the slice's public IP.&lt;/p&gt;

&lt;p&gt;As was explained previously, SSH port forwarded connections appear to originate from the slice's localhost interface while connecting to the same, from the perspective of the postgres server.  Review the section in the &lt;a href="http://articles.slicehost.com/2009/5/27/postgresql-making-connections-2" title="PostgreSQL - making connections #2"&gt;previous article&lt;/a&gt; titled "Remote clients with dynamic IPs" for a more detailed explanation and example.&lt;/p&gt;

&lt;p&gt;So we can remove the public IP from the 'listen_addresses' list in 'postgresql.conf'. What about the slice's private IP? If our database server is split off from the slice(s) running our web application — a common setup —  postgres will need to listen on that interface.&lt;/p&gt;

&lt;p&gt;Let's modify 'postgresql.conf' accordingly:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/postgresql/8.3/main/postgresql.conf&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;# - Connection Settings -

#listen_addresses = 'localhost, 10.300.300.300'  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost', '*' = all
                                        # (change requires restart)
port = 5432                             # (change requires restart)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, we used 10.300.300.300 as the Slice internal IP - you would need to enter your Slice private IP.&lt;/p&gt;

&lt;p&gt;We'll need to restart postgres to apply the changes.&lt;/p&gt;

&lt;p&gt;Note that if postgres is running on the same slice as our application's other processes, and we don't otherwise plan on connecting to our databases from another slice, we should also remove the private IP from 'postgresql.conf', leaving only localhost specified for 'listen_addresses'.  In fact, that's the default setup.&lt;/p&gt;

&lt;h3&gt;Tighten iptables&lt;/h3&gt;

&lt;p&gt;We should now modify the iptables rule we loaded in the previous article, such that port 5432 is open to inbound traffic destined only for our slice's private IP. For a Slicehost slice, the private IP is always bound to interface 'eth1', while the default public IP is bound to 'eth0'. Extra public IPs are bound to 'eth0:x' (x = 1, 2, 3 ... ). We can use the '-i' flag to specify an interface for our iptables rule:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/iptables.up.rules&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code&gt;# Allows connections to the PostgreSQL process
-A INPUT -i eth1 -p tcp --dport 5432 -j ACCEPT&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The reasoning here:  don't keep ports open unnecessarily. After saving the changes, we'll need to flush and reload our rules:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo iptables -F
...
sudo iptables-restore &amp;lt; /etc/iptables.up.rules&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We should simply remove the iptables rule for the postgres port if the database server will be listening only on localhost.&lt;/p&gt;

&lt;h3&gt;pg_hba.conf - careful choices&lt;/h3&gt;

&lt;p&gt;There are a few principles to keep in mind when adding and pruning host records in 'pg_hba.conf', especially for production servers:&lt;/p&gt;

&lt;p&gt;— Specify hosts only as necessary.&lt;/p&gt;

&lt;p&gt;If we have four additional slices and only one of them will be connecting to the postgres server, we should make a host record only for that one slice's IP.&lt;/p&gt;

&lt;p&gt;Most especially, if for convenience you ever set a record allowing connections from all hosts, don't run with it for long, and never on a production server. That would be asking for trouble.&lt;/p&gt;

&lt;p&gt;If we're developing a setup that will eventually go into production, it's a good idea to occasionally review 'pg_hba.conf' and prune any host records that have turned out to be unnecessary.&lt;/p&gt;

&lt;p&gt;— Use hostssl whenever possible.&lt;/p&gt;

&lt;p&gt;We learned in the previous article that host records with the "host" connection type will allow both plain and SSL-encrypted connections. The "hostssl" connection type requires the postgres server and client to use SSL encryption.&lt;/p&gt;

&lt;p&gt;The "host" type is okay for localhost's record — in fact we may have processes running on the slice which aren't SSL-enabled, yet need to communicate with postgres.&lt;/p&gt;

&lt;p&gt;But for remote TCP connections, we should use "hostssl" whenever possible, whether the database client is on the Slicehost network or somewhere else on the Internet.  Databases quite often store sensitive information we don't want traversing cyberspace naked before the peeping eyes of unscrupulous parties who would like to abuse it for their gain.&lt;/p&gt;

&lt;p&gt;If we find that the database client software running on our remote host (another slice, some other server, or a local computer) doesn't support SSL-enabled connections, it's best to search for instructions on how to re-install or compile a version which does.  If an SSL-enabled version doesn't exist, we can consider using SSH port forwarding to make the connection. Stunnel is another possibility in that situation.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Most anyone running a PostgreSQL server will make remote TCP connections to it.&lt;/p&gt;

&lt;p&gt;The configuration files are flexible enough to leave the database server wide open to Internet connections.  It's better though to specify only the necessary interfaces and hosts in its white lists — postgresql.conf, pg_hba.conf.&lt;/p&gt;

&lt;p&gt;Encrypted connections are also possible, and should generally be required for all remote clients.&lt;/p&gt;

&lt;p&gt;Further, the slice's iptables firewall should be adjusted to pass traffic on an interface and port only as needed.&lt;/p&gt;

&lt;p&gt;It's your server and your data — configure PostgreSQL wisely.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Mike&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-05-27:10891</id>
    <published>2009-05-27T13:36:00Z</published>
    <updated>2009-06-24T13:24:51Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <category term="vhosts" />
    <link href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-virtual-hosts-1" rel="alternate" type="text/html" />
    <title>Debian Lenny - Apache Virtual Hosts #1</title>
<summary type="html">&lt;p&gt;Now we have Apache installed and running, we can configure it to serve multiple domains using Virtual Hosts.&lt;/p&gt;

&lt;p&gt;Do note the layout used in these articles is explained &lt;a href="http://articles.slicehost.com/2007/9/13/multiple-hosts-layout" title="Multiple hosts layout"&gt;here&lt;/a&gt; - feel free to use the directories of your choice.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Now we have Apache installed and running, we can configure it to serve multiple domains using Virtual Hosts.&lt;/p&gt;

&lt;p&gt;Do note the layout used in these articles is explained &lt;a href="http://articles.slicehost.com/2007/9/13/multiple-hosts-layout" title="Multiple hosts layout"&gt;here&lt;/a&gt; - feel free to use the directories of your choice.&lt;/p&gt;
&lt;h3&gt;Create the layout&lt;/h3&gt;

&lt;p&gt;In this example we'll be using two domains: domain1.com and domain2.com.&lt;/p&gt;

&lt;p&gt;In your home directory create a 'public_html' folder:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd ~
mkdir public_html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now for each domain we want to host create a folder with a standard set of sub-folders:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir -p public_html/domain1.com/{public,private,log,cgi-bin,backup}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir -p public_html/domain2.com/{public,private,log,cgi-bin,backup}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That will create the folders public, private, log, cgi-bin and backup for each of our domains (domain1.com and domain2.com).&lt;/p&gt;

&lt;h3&gt;index.html&lt;/h3&gt;

&lt;p&gt;The content of the public folder is, naturally, up to you but for this example I am going to use a very simple html file so we can check the virtual hosts work.&lt;/p&gt;

&lt;p&gt;So for each domain create an index.html file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nano public_html/domain1.com/public/index.html&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;add the following to the index.html file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;domain1.com&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;domain1.com&amp;lt;/h1&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Repeat the process so you have a similar file for domain2.com (simply replace all instances of 'domain1.com' with 'domain2.com).&lt;/p&gt;

&lt;p&gt;OK. Now we have a basic structure for our two domains we can look at defining two virtual hosts.&lt;/p&gt;

&lt;h3&gt;NameVirtualHost&lt;/h3&gt;

&lt;p&gt;With virtual hosts, one thing that often confuses people is the NameVirtualHost setting.&lt;/p&gt;

&lt;p&gt;For each interface and port on which Apache is set to listen on, we need a NameVirtualHost directive.  Something to keep in mind is you can only define it once per port.&lt;/p&gt;

&lt;p&gt;In the Apache layout for Debian Lenny there is a default NameVirtualHost directive in the 'ports.conf' file.  If you've worked through the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-1" title="Debian Lenny - Apache configuration #1"&gt;Apache configuration #1&lt;/a&gt; article for Lenny, you may remember it being noted previously.&lt;/p&gt;

&lt;p&gt;Let's take another look at the contents of 'ports.conf':&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cat /etc/apache2/ports.conf&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should get the following output (unless you've previously modified the file):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

&amp;lt;IfModule mod_ssl.c&amp;gt;
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
&amp;lt;/IfModule&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The default NameVirtualHost setting satisfies our requirements at present — Apache will apply named based virtual host logic and settings for HTTP requests made on any available interface (*) at port 80.&lt;/p&gt;

&lt;h3&gt;Custom Virtual Hosts&lt;/h3&gt;

&lt;p&gt;We've set up the basics and now we're ready to add our own virtual hosts so we can start to serve our domains.&lt;/p&gt;

&lt;p&gt;Let's go ahead and create the vhost file for domain1:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/sites-available/domain1.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The contents look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Place any notes or comments you have here
# It will make any customisation easier to understand in the weeks to come

# domain: domain1.com
# public: /home/demo/public_html/domain1.com/

&amp;lt;VirtualHost *:80&amp;gt;

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@domain1.com
  ServerName  domain1.com
  ServerAlias www.domain1.com


  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html
  DocumentRoot /home/demo/public_html/domain1.com/public


  # Custom log file locations
  LogLevel warn
  ErrorLog  /home/demo/public_html/domain1.com/log/error.log
  CustomLog /home/demo/public_html/domain1.com/log/access.log combined

&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;a2ensite&lt;/h3&gt;

&lt;p&gt;Now we have the site available, we need to enable it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2ensite domain1.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output of the command is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Site domain1.com installed; run /etc/init.d/apache2 reload to enable.&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Seems like good advice:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Navigate&lt;/h3&gt;

&lt;p&gt;To test the domain without creating a DNS zone and record(s) on some Internet namserver(s), I've modified the '/etc/hosts' file on my &lt;em&gt;local&lt;/em&gt; computer to include some entries mapping 'domain1.com', etc. to the demo Slice's public IP:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;127.0.0.1    localhost
...

# entries related to the demo slice
123.45.67.890   domain1.com
123.45.67.890   www.domain1.com
123.45.67.890   domain2.com
...&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can add similar entries in your own 'hosts' file, though it's location will vary depending on what OS is loaded on your local computer (try a Google search).&lt;/p&gt;

&lt;p&gt;NOTE:  entries in the 'hosts' file will need to be removed prior to testing and using live DNS zones and records created on Internet nameservers.  Failure to remove them will likely lead to confusion on your part and inaccurate tests of new or modified public DNS records.&lt;/p&gt;

&lt;p&gt;With such changes made for testing purposes, you can navigate to your site in a web browser on your local computer:&lt;/p&gt;

&lt;p&gt;&lt;img title="Domain1 Home Page" src="http://articles.slicehost.com/assets/2008/12/5/apache-vhostworking-domain1.jpg" alt="Domain1 Home Page" /&gt;&lt;/p&gt;

&lt;p&gt;Tada! You now have the contents of public/index.html being shown:&lt;/p&gt;

&lt;h3&gt;ServerAlias&lt;/h3&gt;

&lt;p&gt;Note that in the vhost file, we set a ServerAlias. Providing you have the DNS set up correctly you can also use that address — for quick testing purposes you can place another entry in your 'hosts' file (I've already done so in the example code given above):&lt;/p&gt;

&lt;p&gt;&lt;img title="Domain1 Home Page (hostname alias)" src="http://articles.slicehost.com/assets/2008/12/5/apache-vhostworking-wwwdomain1.jpg" alt="Domain1 Home Page (hostname alias)" /&gt;&lt;/p&gt;

&lt;p&gt;We'll talk about forcing one address or the other in a later article about rewrite rules.&lt;/p&gt;

&lt;h3&gt;Repeat as necessary&lt;/h3&gt;

&lt;p&gt;To create and enable domain2.com simply go through the process again:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/sites-available/domain2.com
...
# Enter the details for domain2.com as per the example shown above&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then enable the site and restart Apache:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2ensite domain2.com
...
sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally navigate to your second domain:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;http://domain2.com
or
http://www.domain2.com&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All being well, you will see the 'domain2.com' index file.&lt;/p&gt;

&lt;h3&gt;Log Files&lt;/h3&gt;

&lt;p&gt;As defined in the vhosts file, each domain has its own log files. Let's take a quick look:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls /home/demo/public_html/domain1.com/log/&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output is exactly as expected:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;access.log  error.log&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This makes for much easier analysis as each set of logs is self contained.&lt;/p&gt;

&lt;h3&gt;Default&lt;/h3&gt;

&lt;p&gt;Remember that although we changed the default virtual host, we did leave it in place.&lt;/p&gt;

&lt;p&gt;Now, if someone enters the IP address of the Slice they are served the contents of that default vhosts file (providing, of course, you have not set up a separate vhost for the IP address).&lt;/p&gt;

&lt;p&gt;Why are they served from that vhost file?&lt;/p&gt;

&lt;p&gt;Apache searches the enabled vhosts in alphabetical order and if it can't find one for the requested IP address or domain name, it serves the first one (alphabetically).&lt;/p&gt;

&lt;p&gt;If we had disabled or deleted the default vhost, then the contents of domain1.com would be displayed (being before domain2.com alphabetically).&lt;/p&gt;

&lt;p&gt;This is something to keep in mind when planning your websites. Do you want a particular domain to be the default? Do you want the IP address to have completely different content?&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;We've gone into some detail here but, overall, setting up a virtual host is relatively easy. Of course, there are many settings and configurations to take into account but you should have your site up and running in no time.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://articles.slicehost.com/2009/6/24/debian-lenny-apache-virtual-hosts-2" title="Debian Lenny - Virtual Hosts #2"&gt;next virtual host article&lt;/a&gt; will look in more detail at some of the settings that are available and what they mean.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-05-27:10890</id>
    <published>2009-05-27T13:28:00Z</published>
    <updated>2009-05-27T13:29:21Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <link href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-2" rel="alternate" type="text/html" />
    <title>Debian Lenny - Apache configuration #2</title>
<summary type="html">&lt;p&gt;Continuing from the first Debian Lenny &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-1" title="Debian Lenny - Apache configuration, part 1"&gt;Apache configuration&lt;/a&gt; article, we'll now look at some of the other settings in the main apache2.conf file and what they can do.&lt;/p&gt;

&lt;p&gt;Concentrating on efficiency and security, this will end our apache2.conf journey (for now.)&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Continuing from the first Debian Lenny &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-1" title="Debian Lenny - Apache configuration, part 1"&gt;Apache configuration&lt;/a&gt; article, we'll now look at some of the other settings in the main apache2.conf file and what they can do.&lt;/p&gt;

&lt;p&gt;Concentrating on efficiency and security, this will end our apache2.conf journey (for now.)&lt;/p&gt;
&lt;h3&gt;ServerName&lt;/h3&gt;

&lt;p&gt;Default: &lt;strong&gt;Not Set&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The ServerName is usually a hostname or a FQDN (Fully Qualified Domain Name).&lt;/p&gt;

&lt;p&gt;If you followed the &lt;a href="http://articles.slicehost.com/2009/4/9/debian-lenny-installing-apache2-and-php5" title="Debian Lenny - Apache2 and PHP install"&gt;Debian Lenny installing Apache2 and PHP5&lt;/a&gt; article, you will have already set the ServerName configuration.&lt;/p&gt;

&lt;p&gt;If you fail to set the ServerName then on an Apache restart you will see the following warning:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To stop the warning and set the ServerName, add the following to the apache2.conf:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerName demo&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Remember the test slice has a hostname of 'demo' - set this to your hostname or FQDN.&lt;/p&gt;

&lt;h3&gt;HostnameLookups&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;HostnameLookups Off&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you want happy users and to save traffic, keep this at Off.&lt;/p&gt;

&lt;p&gt;Setting this to 'On' will enable DNS lookups so host names can be logged (it performs a reverse DNS check), setting it to 'Double' will not only perform the reverse DNS check it will then check the resulting hostname.&lt;/p&gt;

&lt;p&gt;All a bit much and if you desperately need hostname information from your visitors it is advised to use logresolve (located in /usr/sbin/logresolve) for this purpose. A small explanation can be found &lt;a href="http://httpd.apache.org/docs/2.2/programs/logresolve.html" title="Apache 2.2. logresolve"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Security Settings&lt;/h3&gt;

&lt;p&gt;It's a good idea to review a couple of security-related settings for Apache — ServerTokens and ServerSignature — which in the Debian Lenny Apache layout are stored by default in the 'security' config file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/etc/apache2/conf.d/security&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;ServerTokens&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerTokens Full&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The ServerTokens setting will dictate how much information is sent in the Headers with regard to Apache version and modules in use.&lt;/p&gt;

&lt;p&gt;The default (Full) would send something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch Server at demo&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Does this make a difference? Well, yes. If we can suppress that information it will make it harder for someone to find an exploit.&lt;/p&gt;

&lt;p&gt;It does &lt;em&gt;not&lt;/em&gt; make the actual install any more secure but all someone has to do right now is look for an exploit in Debian Lenny, Apache 2.2.9 and so on. Why make it easy for them?&lt;/p&gt;

&lt;p&gt;The options are (with example outputs):&lt;/p&gt;

&lt;p&gt;Full&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch Server at demo&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;OS&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2.2.9 (Debian) Server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Minimal&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2.2.9 Server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Minor&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2.2 Server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Major&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache/2 Server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Prod&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Apache Server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It's up to you what level of info you want to give out. I prefer setting ServerTokens to Prod.&lt;/p&gt;

&lt;h3&gt;ServerSignature&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerSignature On&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Server generated pages, such as 404 pages or directory listings, can contain a footer line which includes server information and can include the ServerAdmin email address.&lt;/p&gt;

&lt;p&gt;If you navigate to your Slice IP address and a non-existent page, you will see a 404 Page not found page with the footer information:&lt;/p&gt;

&lt;p&gt;&lt;img title="Apache ServerSignature" src="http://articles.slicehost.com/assets/2008/12/5/apache-404-footer.jpg" alt="Apache  ServerSignature" /&gt;&lt;/p&gt;

&lt;p&gt;The options are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Off&lt;/strong&gt;: Produces no footer&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On&lt;/strong&gt;: Produces footer information (at a level defined by the ServerTokens setting)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Email&lt;/strong&gt;: Adds an email link to the information (email address is defined in the vhosts file with the ServerAdmin setting)&lt;/p&gt;

&lt;p&gt;Keep in mind that many settings can be overridden by a virtual host file.&lt;/p&gt;

&lt;p&gt;If you disable the ServerSignature in the 'security' config file, but a virtual host file has:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ServerSignature On&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then the global setting will be overridden and a footer will still be displayed on 404 pages, etc. for any sites associated with that virtual host.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;There are some simple steps in this article, but ones which I believe are quite useful and aid in increasing the efficiency of your Slice and assist in the overall security of your Slice.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-05-27:10888</id>
    <published>2009-05-27T13:22:00Z</published>
    <updated>2009-05-27T13:33:44Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <link href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-1" rel="alternate" type="text/html" />
    <title>Debian Lenny - Apache configuration #1</title>
<summary type="html">&lt;p&gt;As we know from the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-config-layout" title="Debian Lenny - Apache Layout"&gt;previous article&lt;/a&gt;, Debian Lenny uses a different layout from other non-Debian based systems - let's move on and take a look at the main apache2.conf and ports.conf.&lt;/p&gt;

&lt;p&gt;We're not actually going to change a lot at this point, just look at the main settings and see what they mean and what a change will actually do.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;As we know from the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-config-layout" title="Debian Lenny - Apache Layout"&gt;previous article&lt;/a&gt;, Debian Lenny uses a different layout from other non-Debian based systems - let's move on and take a look at the main apache2.conf and ports.conf.&lt;/p&gt;

&lt;p&gt;We're not actually going to change a lot at this point, just look at the main settings and see what they mean and what a change will actually do.&lt;/p&gt;
&lt;h3&gt;Defaults&lt;/h3&gt;

&lt;p&gt;Why no specific changes to the default?&lt;/p&gt;

&lt;p&gt;Well, it's difficult to give a definitive configuration as there are so many variables to consider such as expected site traffic, Slice size, site type, etc.&lt;/p&gt;

&lt;p&gt;Remember that it is very unlikely the default Apache configuration will be ideal for your Slice. Don't be intimidated by the thought of 'optimizing' the install - following the next couple of articles will allow you to understand the meaning behind the concepts.&lt;/p&gt;

&lt;p&gt;You'll also find the same things apply to any web server - they may call them different things, but the concepts remain the same. &lt;/p&gt;

&lt;p&gt;My advice is very simple: experiment. Find what works best on your setup.&lt;/p&gt;

&lt;h3&gt;ports.conf&lt;/h3&gt;

&lt;p&gt;Let's start with the ports.conf file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NameVirtualHost *:80
Listen 80

&amp;lt;IfModule mod_ssl.c&amp;gt;
    # SSL name based virtual hosts are not yet supported, therefore no
    # NameVirtualHost statement here
    Listen 443
&amp;lt;/IfModule&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well, that seems fair enough. Port 80 is the standard HTTP port to listen on and if you have the ssl module loaded, then it will also listen on port 443 (HTTPS).&lt;/p&gt;

&lt;p&gt;Also, name based virtual hosts are enabled by default, for HTTP requests made on all interfaces (*) on port 80, per the NameVirtualHost directive.  Note the comment concerning the lack of support for SSL name based virtual hosts — in practical terms this means that you will need an additional public IP assigned to your Slice for each additional SSL-enabled site that you intend to host on the same Slice.&lt;/p&gt;

&lt;p&gt;Configuring Apache to listen on another port, say 8080, is as simple as adding:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Listen 8080&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once that is added to the file and Apache restarted, it would listen on port 8080.  You would want to change the port specified in the NameVirtualHost directive to match.&lt;/p&gt;

&lt;h3&gt;apache2.conf&lt;/h3&gt;

&lt;p&gt;now open up the main Lenny Apache config file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo nano /etc/apache2/apache2.conf&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I won't list the contents here but, if you are not familiar with the settings, have a read of the comments. I find them very informative and straight to the point.&lt;/p&gt;

&lt;p&gt;You may be surprised how well config files are documented. I always recommend giving them a read - sure, they may not make a lot of sense to begin with but as time goes by you will be able to glance at them and know what to change.&lt;/p&gt;

&lt;p&gt;Anyway, let's look at some of the main settings and what they mean:&lt;/p&gt;

&lt;h3&gt;Timeout&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Timeout 300&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This sets (in simple terms) the maximum time, in seconds, to wait for a request, action it and the response to the request.&lt;/p&gt;

&lt;p&gt;The default is deliberately set high to allow for varied situations. You can reduce this to something more sane, such as 45 or even lower. A decrease may also help in reducing the effects of a DOS attack.&lt;/p&gt;

&lt;h3&gt;KeepAlive&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;KeepAlive On&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Keep this set at 'On' as it allows for persistent connections to a client so each file, image, etc is not requested with a new connection. This allows for more efficiency. Define the KeepAlive settings as shown below:&lt;/p&gt;

&lt;h3&gt;MaxKeepAliveRequests&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;MaxKeepAliveRequests 100&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we have our persistent connection, set the maximum number of requests per connection. Keep this high for maximum efficiency. If you have a site with lots of images, javascripts, etc, try increasing this to 200.&lt;/p&gt;

&lt;h3&gt;KeepAliveTimeout&lt;/h3&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;KeepAliveTimeout 15&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So how long does the persistent connection wait for the next request? The default setting is very high and can easily be reduced to 2 or 3 seconds. If no new requests are received during this time the connection is killed.&lt;/p&gt;

&lt;p&gt;What does this mean? Well, once a connection has been established and the client has requested the files needed for the web page, this setting says "sit there and ignore everyone else until the time limit is reached or you get a new request from the client".&lt;/p&gt;

&lt;p&gt;Why would you want a higher time? In cases where there will be a lot of interactivity on the site. However, in most cases, people will go to a page, read it for a while and then click for the next page. You don't want the connection sat there doing nothing and ignoring other users.&lt;/p&gt;

&lt;h3&gt;prefork MPM&lt;/h3&gt;

&lt;p&gt;During the &lt;a href="http://articles.slicehost.com/2009/4/9/debian-lenny-installing-apache2-and-php5" title="Debian Lenny - Apache2 and PHP5 install"&gt;Debian Lenny Apache install&lt;/a&gt;, we selected apache2-mpm-prefork and not apache2-mpm-worker. If you want to know more about the differences between the two I will point you towards the official &lt;a href="http://httpd.apache.org/docs/2.2/" title="Apache2.2 Documentation"&gt;Apache docs&lt;/a&gt; (which are actually very good).&lt;/p&gt;

&lt;p&gt;Default:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;IfModule mpm_prefork_module&amp;gt;
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
&amp;lt;/IfModule&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Again, it's difficult to give a suggestion here as to what is best for your site but have a read of the definitions below and see if anything could be improved when you consider what your site(s) serves.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;StartServers&lt;/strong&gt;: number of child server processes created at startup&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MinSpareServers&lt;/strong&gt;: minimum number of child server processes not doing anything (idle).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MaxSpareServers&lt;/strong&gt;: maximum number of child server processes not doing anything (idle) — any more than the maximum will be killed.&lt;/p&gt;

&lt;p&gt;Don't set Max lower than Min, but Apache will ignore silly numbers here and set the Max at Min+1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MaxClients&lt;/strong&gt;: sets the maximum simultaneous requests that Apache will handle. Anything over this number will be queued until a process is free to action the request. &lt;/p&gt;

&lt;p&gt;MaxClients is &lt;em&gt;not&lt;/em&gt; the same as the maximum number of visitors you can have. It is the maximum requests.&lt;/p&gt;

&lt;p&gt;Remember the KeepAliveTimeout? This was set low so the next request can be actioned and the original (now 'idle') client will still be sat there reading your webpage — the new (active) request will be actioned or, if the MaxClients limit has been reached, will be queued ready for the next available process.&lt;/p&gt;

&lt;p&gt;In most cases, the client is not 'active'. Take this page, for example: you requested it (using an active process) and then spent a while reading it which uses no processes — you are 'idle' (as far as the server is concerned!).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MaxRequestsPerChild&lt;/strong&gt;: sets how many requests a child process will handle before terminating. The default is zero, which means it will never die.&lt;/p&gt;

&lt;p&gt;Why change this if the Max numbers are set as shown above? Well, it can help in managing your Slice memory usage.&lt;/p&gt;

&lt;p&gt;If you change the default you give a child a finite number of actions before it will die. This will, in effect, reduce the number of processes in use when the server is not busy. Thus freeing memory.&lt;/p&gt;

&lt;p&gt;Freeing it for what though? If other software needed memory then it would also need it when the server is under load. It is unlikely you will have anything that requires memory &lt;em&gt;only&lt;/em&gt; when the server is quiet.&lt;/p&gt;

&lt;h3&gt;Summary&lt;/h3&gt;

&lt;p&gt;Quite a lot here, but as you go through the different settings you will see that the theory is quite simple. Naturally, there is a lot more to it than this article (or set of articles) can go into.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-2" title="Debian Lenny - Apache Configuration #2"&gt;second apache2.conf article&lt;/a&gt;, we will look at other settings that will add some more efficiency and help in increasing the security of our Slice.&lt;/p&gt;

&lt;p&gt;—&lt;/p&gt;

&lt;p&gt;Ben B&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://articles.slicehost.com/">
    <author>
      <name>Ben B</name>
    </author>
    <id>tag:articles.slicehost.com,2009-05-27:10843</id>
    <published>2009-05-27T13:17:00Z</published>
    <updated>2009-05-27T13:25:52Z</updated>
    <category term="Apache" />
    <category term="Debian - Lenny" />
    <category term="apache" />
    <category term="debian" />
    <category term="lenny" />
    <link href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-config-layout" rel="alternate" type="text/html" />
    <title>Debian Lenny - Apache config layout</title>
<summary type="html">&lt;p&gt;Debian Lenny uses a different Apache layout than you may have encountered if you have used Apache with non-Debian based Operating Systems.&lt;/p&gt;

&lt;p&gt;The differences are not huge and, indeed, help in configuring and deploying websites.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Debian Lenny uses a different Apache layout than you may have encountered if you have used Apache with non-Debian based Operating Systems.&lt;/p&gt;

&lt;p&gt;The differences are not huge and, indeed, help in configuring and deploying websites.&lt;/p&gt;
&lt;h3&gt;Looksee&lt;/h3&gt;

&lt;p&gt;Assuming you have used aptitude to install Apache (see the &lt;a href="http://articles.slicehost.com/2009/4/9/debian-lenny-installing-apache2-and-php5" title="Debian Lenny Apache and PHP5 install"&gt;Debian Lenny Apache and PHP5 install&lt;/a&gt; article), move into the config folder and have a look:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cd /etc/apache2
ls&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will see this:&lt;/p&gt;

&lt;p&gt;&lt;img title="Apache Configuration Directory" src="http://articles.slicehost.com/assets/2009/5/26/debian-lenny_etc-apache-ls.png" alt="Apache Configuration Directory" /&gt;&lt;/p&gt;

&lt;p&gt;The folders are highlighted in blue. Let's look at those first:&lt;/p&gt;

&lt;h3&gt;sites-available&lt;/h3&gt;

&lt;p&gt;Inside sites-available will be files containing the configurations for each site you want to serve - these are known as vhosts or virtual hosts.&lt;/p&gt;

&lt;p&gt;Have a look now and see that there is one site (default) available:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls sites-available/
...
default  default-ssl&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The apache install has a 'default' and a 'default-ssl' vhost available - when we navigated to the Slice IP and got the 'It works!" message, it was the 'default' file that told Apache what to do and where the files where located.&lt;/p&gt;

&lt;p&gt;We'll look at vhosts in more detail and create our own in a later article.&lt;/p&gt;

&lt;p&gt;Do note that a file in sites-available does not mean they are active. They are simply available for serving if you enable them. Which brings us to...&lt;/p&gt;

&lt;h3&gt;sites-enabled&lt;/h3&gt;

&lt;p&gt;This folder contains symlinks to the sites you actually want to serve.&lt;/p&gt;

&lt;p&gt;For example, you could have two vhosts configured and ready to use in the sites-available folder, but only one of them enabled. Only the one symlinked from the sites-enabled folder would be served.&lt;/p&gt;

&lt;p&gt;Have a look at the default contents:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls -l sites-enabled
...
lrwxrwxrwx 1 root root 26 Nov 28 22:38 000-default -&amp;gt; ../sites-available/default&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This means that the 'default' site has been enabled - the symlink named '000-default' links to the 'default' file in the sites-available folder.&lt;/p&gt;

&lt;p&gt;Without the symlink in this folder it would remain available (in the sites-available folder) but not active.&lt;/p&gt;

&lt;p&gt;The other thing to note is the naming. It's possible for a domain to point to your Slice IP but have no site configuration file. In these cases, the first enabled site (alphabetically) will be displayed, i.e. 000-default's config will be used.&lt;/p&gt;

&lt;h3&gt;mods-available&lt;/h3&gt;

&lt;p&gt;Well, I guess you get the idea already but this folder holds the modules that are available to be loaded.&lt;/p&gt;

&lt;p&gt;Have a look:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls mods-available&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A fair list is available from our base install but remember that they are not all enabled, merely available for use.&lt;/p&gt;

&lt;p&gt;Just as with the vhosts files, any modules that we want to use must be enabled.&lt;/p&gt;

&lt;h3&gt;mods-enabled&lt;/h3&gt;

&lt;p&gt;This folder contains symlinks to the modules that we want enabled. Have a look and compare it to the list of modules available:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ls mods-enabled&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This list is a lot shorter than the list of available modules (meaning not all the available modules are enabled) and includes php5.conf - which is handy as we installed PHP5 earlier.&lt;/p&gt;

&lt;h3&gt;a2en and a2dis&lt;/h3&gt;

&lt;p&gt;Being good sysadmins, we like to get hands on and create our vhosts, and now that we know how the symlinks work we could go ahead and 'ln -s' until all our sites are enabled.&lt;/p&gt;

&lt;p&gt;However, there are some commands that make this process much easier.&lt;/p&gt;

&lt;p&gt;They are a2dissite, a2ensite, a2dismod and a2enmod.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a2dissite&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will delete the symlink to a site you have previously enabled.&lt;/p&gt;

&lt;p&gt;For example, let's disable the default site:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2dissite default&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The symlink in sites-enabled has been deleted and the output is as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Site default disabled.
Run '/etc/init.d/apache2 reload' to activate new configuration!&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reload Apache as indicated to ensure the site is fully disabled:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When you now visit your Slice IP, instead of the nice 'It Works!' page, you will get a 404 Not Found message:&lt;/p&gt;

&lt;p&gt;&lt;img title="Apache Configuration Directory" src="http://articles.slicehost.com/assets/2008/12/1/no-default-vhost-404.jpg" alt="Apache Configuration Directory" /&gt;&lt;/p&gt;

&lt;p&gt;Note the main vhosts file in sites-available is still there - all the a2dissite command did was remove the symlink in the sites-enabled folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a2ensite&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's enable the default site again:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2ensite default&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Enabling site default.
Run '/etc/init.d/apache2 reload' to activate new configuration!&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Reload Apache:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Visit your Slice IP - the default 'It works!' page is being served again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a2dismod&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the same way as just shown, a2dismod will disable any modules you have previously enabled:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2dismod php5&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Module php5 disabled.
Run '/etc/init.d/apache2 restart' to activate new configuration!&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That will disable the php5 module and if you look in the mods-enabled folder, you will see that the symlinks php5.conf and php5.load have been deleted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a2enmod&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I reckon you've got it now, but to enable the php5 module simply enter:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo a2enmod php5&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The output:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Enabling module php5.
Run '/etc/init.d/apache2 restart' to activate new configuration!&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And a quick check will show that indeed, the php5.conf and php5.load symlinks are back in the mods-enabled folder.&lt;/p&gt;

&lt;h3&gt;Done&lt;/h3&gt;

&lt;p&gt;Don't forget to reload Apache after each site or module change.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="http://articles.slicehost.com/2009/5/27/debian-lenny-apache-configuration-1" title="Debian Lenny - Apache configuration #1"&gt;next article&lt;/a&gt; we'll discuss the main apache2.conf file and look at what changes can be made to optimise the install.&lt;/p&gt;

&lt;p&gt;--&lt;/p&gt;

&lt;p&gt;Ben&lt;/p&gt;
          </content>  </entry>
</feed>
