<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Stephen Foskett, Pack Rat &#187; Slicehost Archives  &#8211; Stephen Foskett, Pack Rat</title>
	<atom:link href="http://blog.fosketts.net/tag/slicehost/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fosketts.net</link>
	<description>Understanding the accumulation of data</description>
	<lastBuildDate>Fri, 10 Feb 2012 17:40:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
	<atom:link rel="hub" href="http://superfeedr.com/hubbub" />
			<item>
		<title>A High-Performance, Low-Memory Apache/PHP Virtual Private Server</title>
		<link>http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/</link>
		<comments>http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 18:16:38 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Computer History]]></category>
		<category><![CDATA[Everything]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[FCGI]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[mod_fcgi]]></category>
		<category><![CDATA[mpm-worker]]></category>
		<category><![CDATA[Netscape]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-cgi]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP-SuperCache]]></category>

		<guid isPermaLink="false">http://blog.fosketts.net/?p=3472</guid>
		<description><![CDATA[I've previously written about my Multi-Server Web Hosting Environment and the how I Tuned Lighttpd For Linux to run as well as possible. But I've been having weird issues with that setup lately and was forced to rebuild the server entirely. While I was at it, I decided to give Apache another try, since the lighttpd hackery I needed to perform to get things like WP-SuperCache running were starting to get me down. The configuration documented here uses Ubuntu Lucid (10.04), Apache 2.2, FCGI, and PHP-CGI tuned for a 512 MB virtual private server (VPS) running on Rackspace Slicehost.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve previously written about my <a href="http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/" >Multi-Server Web Hosting Environment</a> and the how I <a href="http://blog.fosketts.net/2009/06/29/tuning-lighttpd-linux/" >Tuned Lighttpd For Linux</a> to run as well as possible. But I&#8217;ve been having weird issues with that setup lately and was forced to rebuild the server entirely. While I was at it, I decided to give Apache another try, since the lighttpd hackery I needed to perform to get things like WP-SuperCache running were starting to get me down. The configuration documented here uses Ubuntu Lucid (10.04), Apache 2.2, FCGI, and PHP-CGI tuned for a 512 MB virtual private server (VPS) running on Rackspace Slicehost.</p>
<h3>A Brief History of the Web</h3>
<p>I&#8217;ve been pretty happy with lighttpd as my web server. It&#8217;s light and quick and has a workable fastcgi/PHP implementation. Right out of the box, lighttpd kicks Apache up and down the block on low-memory servers &#8211; the kind you&#8217;ll find in virtual private server hosting companies.</p>
<p>To understand why lighttpd is so good, we have to understand why Apache is so bad. And this means going way back in time to the dawn of the web. In the beginning, web servers were single-threaded processes that slapped pages over network connections on demand. This is like a single lemonade stand, where every customer waits in line but there&#8217;s only one item on offer and it&#8217;s a quick serve. So the line moves pretty quickly but it&#8217;s not all that interesting.</p>
<p>The Netscape Navigator browser revolutionized end-user experience by downloading web page elements in parallel and displaying them as they came in. Web servers responded by &#8220;forking&#8221; multiple copies of themselves to handle these requests (and those from other users) in parallel. Our lemonade stand is still limited in selection, but it now has more workers to hand over the juice.</p>
<p>At the same time, users began demanding more-interesting content. Web 2.0 replaced the old static HTML pages and graphics with interactive web applications, and the PHP language became dominant. Today, most popular web software (including WordPress and Mediawiki) require a PHP interpreter as well as an HTTP server to run. In the old days, server-side compute was handled by a &#8220;back room&#8221; CGI task. Our lemonade counter is now a restaurant, with a kitchen and added a variety of hot foods. But customers (and servers) have to wait while these are cooked up.</p>
<p>The Apache answer to this challenge was to add a kitchen to every checkout position. Out of the box, installing Apache and PHP adds a complete PHP runtime to each Apache process. And since the Apache PHP module is reputed to be unstable in multi-threaded environments, these default setups use the &#8220;prefork&#8221; single-thread-per-process method of handling multiple connections. Now our imaginary fast food restaurant can handle an unlimited number of customers in parallel, right?</p>
<p>In practice, this doesn&#8217;t work well. A 50-position counter could handle tons of customers, but that would be one wide restaurant! The same issue crops up with Apache. It looks super-speedy until loaded up (say, with a midnight Google, Yahoo, or MSN crawl) when it promptly uses up all of your memory forcing the OOM killer to murder your system. The only way to get this default (mod_php/mpm-prefork) version of Apache to be stable, other than adding RAM, is to limit the number of processes spawned. Customers are now back to waiting in line for just a few servers and their experience suffers.</p>
<h3>Lighty Did It, Apache Didn&#8217;t?</h3>
<p>Lighttpd (&#8220;lighty&#8221;) is totally different. It is a small, lightweight HTTP server that farms out PHP tasks to a constantly-running PHP process. This sounds pretty much exactly like the single-kitchen CGI approach of the mid-1990&#8242;s, but there&#8217;s a trick here (as there was then) that makes it work. In traditional CGI, the command processor was started on demand and closed when its work was done. Like a short-order cook, PHP-CGI makes everything to order.</p>
<p>But Netscape had a better idea. They built an always-running server (NSAPI) that could save work in a cache and reuse it for the next visitor. Suddenly we have a full kitchen up and running, complete with prep and sous chefs, able to turn orders around almost as quickly as the servers placed them. FastCGI was an open implementation of this concept, and it allows little lighttpd processes to serve up complex PHP web sites with ease.</p>
<p>Apache has a similar capability, using the modern FCGI implementation, and has also added multi-threaded server capability called mpm-worker. But the multi-threaded server is reputedly unstable when running PHP as a module, and configuring both mpm-worker and mod_fcgi isn&#8217;t yet standard-issue for Apache installs. So most Apache users still use the old prefork/mod_php configuration while most lighttpd users now rely on fastcgi.</p>
<p>Now, these FCGI PHP processes aren&#8217;t exactly light. Each can use 100 MB or more, especially when xcache is used for faster processing. So a lightweight server still needs to limit the number of &#8220;kitchens&#8221; serving the customers. And using a separate process to handle PHP isn&#8217;t as speedy as having an integrated PHP engine. But having more light HTTP servers to move files around reduces the overall load on the system, even if complicated tasks might have to wait for PHP processing.</p>
<p>Then there&#8217;s WP-SuperCache. This WordPress plugin converts complicated PHP pages into simple HTML for the HTTP server to hand off to visitors. In combination with a lightweight server like Apache/mpm-worker or Lighttpd, WP-SuperCache speeds up WordPress sites dramatically.</p>
<p>Although it&#8217;s possible to convince Lighttpd to play nicely with WP-SuperCache (using mod_magnet), it&#8217;s much easier and better-supported in Apache. I was also having an odd issue with Lighttpd &#8220;pausing&#8221; for a few seconds when clients connected it. So I decided to make the switch back to Apache.</p>
<h3>Configuring Apache With MPM-Worker and Mod_FCGI/PHP-CGI</h3>
<p>Now for the technical details. WP-SuperCache and Lighttpd might be poorly-documented, but Mod_FCGI in Apache isn&#8217;t much better. There are a dozen ways to do everything, and everyone&#8217;s recipe differs. Here&#8217;s how I got it to work.</p>
<p>First, I spun up a fresh 512 MB VPS on Slicehost running Ubuntu 10.04 Lucid. I configured it my normal way (locking down access, setting up a restrictive firewall, and installing only basic packages) and rsync-ed over my web site content.</p>
<p>One goal when tuning a server is to use all of the RAM but not much of the swap. Unused RAM is wasted potential, while swapping processes can quickly kill performance. This is one reason to run Apache with FCGI: You can run just a few heavy (large RAM footprint) PHP engines and many more light (3-5 MB) HTTP servers. Using the multi-threaded mpm-worker mode allows each of those Apache processes to serve more requests with less process creation and destruction.</p>
<p>My next step was to install Apache and its required modules along with mpm-worker, mod_fcgi, php5-cgi, and the rest needed to support wordpress. I think the following command should do the trick:</p>
<pre>sudo apt-get install apache2-mpm-worker libapache2-mod_fcgi \
php5-cgi php5-xcache php5-mysql wordpress</pre>
<p>This won&#8217;t work out of the box. We have to set up some wrapper scripts and configuration files for fcgi and php-cgi, but more important is the tuning, which we&#8217;ll get to next.</p>
<p>First, create a php-cgi wrapper for FCGI to use. I called mine /usr/local/bin/php-wrapper and set up a very basic environment. Be sure to make this script executable, too.</p>
<pre>#!/bin/sh
# Set desired PHP_FCGI_* environment variables.
# Example:
# PHP FastCGI processes exit after 500 requests by default.
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_MAX_REQUESTS
# DO NOT SET PHP_FCGI_CHILDREN!
# Replace with the path to your FastCGI-enabled PHP executable
exec /usr/bin/php-cgi</pre>
<p>As the script comment says, whatever you do, do not set PHP_FCGI_CHILDREN in some misguided attempt to conserve RAM. It will conflict with mod_fcgi and you&#8217;ll end up spawning RAM-hungry but useless child processes and killing your system!</p>
<p>Next, create an fcgi configuration file called /etc/apache2/conf.d/php-fcgid.conf and containing something like the following lines:</p>
<pre>FcgidInitialEnv PHPRC=/etc/php5/cgi
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
# FcgidMaxRequestsPerProcess should be &lt;= PHP_FCGI_MAX_REQUESTS
# The example PHP wrapper script overrides the default PHP setting.
FcgidMaxRequestsPerProcess 1000
FcgidMaxProcesses 3
FcgidMaxProcessesPerClass 3
FcgidMinProcessesPerClass 1
# Uncomment the following line if cgi.fix_pathinfo is set to 1 in php.ini:
# FcgidFixPathinfo 1
# This makes php scripts work everywhere Apache serves
&lt;Location /&gt;
AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper /usr/local/bin/php-wrapper .php
# Customize the next two directives for your requirements.
Order allow,deny
Allow from all
&lt;/Location&gt;</pre>
<p>This is a very permissive configuration, and you might want to tweak things somewhat. But you get the general idea. The important things going on here are the configuration of FCGI to launch just 3 PHP-CGI engines and the assignment of the php-wrapper script to files ending in &#8220;php&#8221; anywhere Apache finds them. This means no special configuration is needed in VirtualHost directives, or anywhere else really.</p>
<p>One more tweak I like is to limit Apache to just 6 worker processes. Since each is multi-threaded and under 5 MB in this configuration, this works well. Add a line to /etc/apache2/apache2.conf in the &#8220;&lt;IfModule mpm_worker_module&gt;&#8221; section saying the following. This is a good complement to the default setting of 25 ThreadsPerChild and  150 MaxClients.</p>
<pre>ServerLimit             6</pre>
<p>Limiting the number of php-cgi processes launched is critical for low-memory systems. A good-sized opcode cache (thanks to xcache) helps them perform well but grows the memory usage like crazy. Although I had just three php-cgi processes running, with one topping 225 MB, overall system performance remained good thanks to WP-SuperCache and six multi-threaded lightweight Apache HTTP servers.</p>
<p>So far, I&#8217;m able to serve multiple WordPress and Mediawiki sites with a few thousand pageviews per day on a 512 MB slice. Running with six Apache workers and 3 or 4 php-cgi processes just gets me under the RAM limit. Of course, I&#8217;m still using a separate 256 MB server for MySQL in addition.</p>
<div id="crp_related"><h3>You might also want to read these other posts...</h3><ul><li><a href="http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/"  rel="bookmark" class="crp_title">Setting Up a Multi-Server Web Hosting Environment</a></li><li><a href="http://blog.fosketts.net/2010/08/01/force-apache-redirect-canonical-hostnames-serveralias-friend/"  rel="bookmark" class="crp_title">How To Force Apache To Redirect To Canonical Hostnames, or ServerAlias Is Not Your Friend</a></li><li><a href="http://blog.fosketts.net/2009/06/29/tuning-lighttpd-linux/"  rel="bookmark" class="crp_title">Tuning Lighttpd For Linux</a></li><li><a href="http://blog.fosketts.net/2009/02/07/apologies-404s/"  rel="bookmark" class="crp_title">Apologies For The 404s!</a></li><li><a href="http://blog.fosketts.net/2010/03/25/robocopy-multi-threaded/"  rel="bookmark" class="crp_title">Robocopy: Better, Faster, Stronger</a></li></ul></div><script src="http://feeds.feedburner.com/~s/sfoskett?i=http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/" type="text/javascript" charset="utf-8"></script><hr />
<p><small>© sfoskett for <a href="http://blog.fosketts.net">Stephen Foskett, Pack Rat</a>, 2010. |
<a href="http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/">A High-Performance, Low-Memory Apache/PHP Virtual Private Server</a>
<br/>
This post was categorized as <a href="http://blog.fosketts.net/category/everything/computerhistory/" title="View all posts in Computer History" rel="category tag">Computer History</a>, <a href="http://blog.fosketts.net/category/everything/" title="View all posts in Everything" rel="category tag">Everything</a>, <a href="http://blog.fosketts.net/category/everything/personal/" title="View all posts in Personal" rel="category tag">Personal</a>. Each of my categories has its own feed if you'd like to filter out or focus on posts like this.<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<series:name><![CDATA[Web Hosting]]></series:name>
	</item>
		<item>
		<title>CloudStuff Versus Stuff in the Cloud</title>
		<link>http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/</link>
		<comments>http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:12:17 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Computer History]]></category>
		<category><![CDATA[Enterprise storage]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Virtual Storage]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[App Engine]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Barry Burke]]></category>
		<category><![CDATA[cloud compu]]></category>
		<category><![CDATA[cloud storage]]></category>
		<category><![CDATA[CloudCamp]]></category>
		<category><![CDATA[CloudNAS]]></category>
		<category><![CDATA[EBS]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[EMC]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Jungle Disk]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Mosso]]></category>
		<category><![CDATA[Nirvanix]]></category>
		<category><![CDATA[Rackspace]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://blog.fosketts.net/?p=2134</guid>
		<description><![CDATA[This world of cloud computing sure can seem cloudy. Last night at CloudCamp Columbus, I led a session outlining the incredible differences between the diverse offerings all called cloud storage. How can companies like Amazon, Nirvanix, Rackspace, EMC, and the rest use the same name for such vastly different products? Check out these detailed posts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.fosketts.net/wp-content/uploads/2009/06/logo_cloudcamp.png" ><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-2053" title="logo_cloudcamp" src="http://blog.fosketts.net/wp-content/uploads/2009/06/logo_cloudcamp.png" alt="logo_cloudcamp" width="308" height="70" /></a>This world of cloud computing sure can seem cloudy. Last night at CloudCamp Columbus, I led a session outlining <strong>the incredible differences between the diverse offerings all called cloud storage</strong>. How can companies like Amazon, Nirvanix, Rackspace, EMC, and the rest use the same name for such vastly different products?<span id="more-2134"></span></p>
<blockquote><p>Check out these detailed posts on cloud storage I wrote for my other blog, <a href="http://developer.nirvanix.com/blogs/strategies/default.aspx"  target="_blank">Enterprise Storage Strategies</a>:</p>
<ul>
<li><a href="http://developer.nirvanix.com/blogs/strategies/archive/2009/06/29/cloud-storage-storage-in-the-cloud-and-cloudy-storage-systems.aspx" >Cloud Storage, Storage in the Cloud, and Cloudy Storage Systems</a></li>
<li><a href="http://developer.nirvanix.com/blogs/strategies/archive/2009/06/19/what-makes-cloud-storage-different-from-traditional-san-and-nas.aspx" >What Makes Cloud Storage Different from Traditional SAN and NAS?</a></li>
</ul>
</blockquote>
<p>Eventually, it dawned on me: <strong>There&#8217;s a big difference between real cloudstuff and plain old stuff in the cloud!</strong></p>
<p>Lots of cloud computing offerings are <strong>startlingly conventional</strong>. They&#8217;re plain-jane IT infrastructure just like we all have today: Virtual servers, storage, and databases. Strip away the management API and self-service model and Amazon <a rel="nofollow" href="http://aws.amazon.com/ec2/"  target="_blank">EC2</a> and <a rel="nofollow" href="http://aws.amazon.com/ebs/"  target="_blank">EBS</a> looks an awful lot like the Xen-based virtual server infrastructure you might find at any old IT shop. The same goes for Rackspace&#8217;s <a href="http://www.rackspacecloud.com/cloud_hosting_products/servers"  target="_blank">Mosso Cloud Servers</a>: They&#8217;re extremely similar to Rackspace&#8217;s <a href="http://www.slicehost.com/"  target="_blank">Slicehost virtual private servers</a>!</p>
<p>This isn&#8217;t all bad, of course. As I discussed with EMC&#8217;s <a rel="nofollow" href="http://thestorageanarchist.typepad.com/"  target="_blank">Barry Burke</a> last week, <strong>you can theoretically run your ERP application on EC2</strong> without major gyrations. Try that with <a rel="nofollow" href="http://www.microsoft.com/azure/default.mspx"  target="_blank">Microsoft Azure</a> or <a rel="nofollow" href="http://code.google.com/appengine/"  target="_blank">Google App Engine</a>! And the management layers, especially those from companies like <a href="http://www.rightscale.com/"  target="_blank">RightScale</a>, turn these run-of-the-mill parts into something really extraordinary! VMware&#8217;s vCloud concept really hammers home this evolution-not-revolution mindset.</p>
<p><strong>Real cloudstuff is completely different</strong>. Comparing a Xen instance running Linux on some disk (a-la EC2) to a programmable platform like Azure is problematic. Just about the only thing they have in common (apart from the cloud name) is the fact that they&#8217;re hosted on multi-tenant servers and offered to the public on a pay-per-usage model. Cloudstuff is the IT revolution that application developers have dreamed of!</p>
<p>Of course, <strong>the problem with whole-cloth reinvention is that it&#8217;s slow to take hold</strong>. Although net-new apps can be built to take advantage of full-on cloud infrastructure today, it will literally be a decade before the corporate IT applications we all rely on will run there. The early adopters will be companies like Microsoft and Google, who have a vested interest in seeing the concept succeed and the development muscle to make it happen.</p>
<p>Then there are <strong>the bridges between today&#8217;s world and this cloudstuff future</strong>. Consider applications like <a href="http://www.nirvanix.com/products-services/standard-based-access/index.aspx"  target="_blank">Nirvanix CloudNAS</a> and <a href="http://www.jungledisk.com/"  target="_blank">Jungle Disk</a>: They hide the complexity of API-driven cloud storage behind the familiar face of file server or backup application. Once the data is loaded, cloud-aware applications can access it. <strong>This is where the magic happens!</strong></p>
<div id="crp_related"><h3>You might also want to read these other posts...</h3><ul><li><a href="http://blog.fosketts.net/2009/03/19/sun-cloud/"  rel="bookmark" class="crp_title">Sun Launches Their Own Cloud, But For Which Market?</a></li><li><a href="http://blog.fosketts.net/2009/09/22/zend-simple-cloud-api/"  rel="bookmark" class="crp_title">Zend Simple Cloud API = Freedom!</a></li><li><a href="http://blog.fosketts.net/2009/04/23/enterprise-storage-strategies-blog/"  rel="bookmark" class="crp_title">Introducing the Enterprise Storage Strategies Blog</a></li><li><a href="http://blog.fosketts.net/2009/07/24/boston-folks-cloudcamp/"  rel="bookmark" class="crp_title">Boston Folks: Come to CloudCamp!</a></li><li><a href="http://blog.fosketts.net/2010/02/01/commvault-cloud-storage-seat-adult-table/"  rel="bookmark" class="crp_title">CommVault Gives Cloud Storage A Seat At The Adult Table</a></li></ul></div><script src="http://feeds.feedburner.com/~s/sfoskett?i=http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/" type="text/javascript" charset="utf-8"></script><hr />
<p><small>© sfoskett for <a href="http://blog.fosketts.net">Stephen Foskett, Pack Rat</a>, 2009. |
<a href="http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/">CloudStuff Versus Stuff in the Cloud</a>
<br/>
This post was categorized as <a href="http://blog.fosketts.net/category/everything/computerhistory/" title="View all posts in Computer History" rel="category tag">Computer History</a>, <a href="http://blog.fosketts.net/category/everything/enterprisestorage/" title="View all posts in Enterprise storage" rel="category tag">Enterprise storage</a>, <a href="http://blog.fosketts.net/category/everything/personal/" title="View all posts in Personal" rel="category tag">Personal</a>, <a href="http://blog.fosketts.net/category/everything/virtualstorage/" title="View all posts in Virtual Storage" rel="category tag">Virtual Storage</a>. Each of my categories has its own feed if you'd like to filter out or focus on posts like this.<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setting Up a Multi-Server Web Hosting Environment</title>
		<link>http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/</link>
		<comments>http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 00:00:32 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[eaccelerator]]></category>
		<category><![CDATA[FriendConnect]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Rackspace]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[XCache]]></category>

		<guid isPermaLink="false">http://blog.fosketts.net/?p=2121</guid>
		<description><![CDATA[The last few weeks have been tough on my web servers. The release of iPhone OS 3.0 tripled my site traffic overnight as folks investigate the new Exchange integration features, and traffic to IT commentary site, Gestalt IT, which I also host, has been growing rapidly. Plus, Google just refreshed PageRank again, sending even more [...]]]></description>
			<content:encoded><![CDATA[<p>The last few weeks have been tough on my web servers. The release of <a href="http://blog.fosketts.net/2009/06/16/iphone-exchange-activesync-integration-30/"  target="_blank">iPhone OS 3.0</a> <strong>tripled my site traffic overnight</strong> as folks investigate the new Exchange integration features, and traffic to IT commentary site, <a href="http://gestaltit.com"  target="_blank">Gestalt IT</a>, which I also host, has been growing rapidly. Plus, <a href="http://blog.fosketts.net/2009/05/27/google-recalculated-pagerank/"  target="_blank">Google just refreshed PageRank</a> again, sending even more visitors my way.</p>
<p>I had <a href="http://blog.fosketts.net/2009/02/07/apologies-404s/"  target="_blank">switched from Dreamhost to Slicehost</a> back in February to improve reliability and performance, but the meagre 256 MB of RAM in my virtual private server (VPS) &#8220;slice&#8221; proved insufficient. The time had come to completely redo my core hosting infrastructure. After some experimentation, I have settled on <strong>a simple two-server configuration based on Ubuntu Linux, MySQL, and lighttpd</strong>. I thought it would be a good idea to document this new configuration, as well as my previous experiments, for posterity.</p>
<blockquote><p>If you&#8217;re interested in setting up a web site as outlined here, <a href="https://manage.slicehost.com/customers/new?referrer=31e5d9e0da4b70b80d0cb0bcc8efc95a"  target="_blank">I recommend Slicehost</a>. They&#8217;re not the cheapest, but their VPS servers are fast and reliable.</p></blockquote>
<h3>History</h3>
<p>My web hosting environment has transitioned over the past six months. I had relied on shared hosting from Dreamhost for almost a decade, with my servers sharing infrastructure and management with thousands of others. This worked fine until I began to see significant traffic increases since creating this blog. <strong>Shared hosting just didn&#8217;t cut it once I had more than a few thousand pageviews per day</strong>.</p>
<p>I tried Dreamhost&#8217;s interesting and very flexible virtual private server capabilities, but could never get them working reliably. Plus, the core networking and storage performance of the Dreamhost infrastructure left something to be desired. After much research I switched to Slicehost, an all-VPS provider that has recently been acquired by Rackspace. Although they are not the cheapest or most flexible, <strong>Slicehost is a very professional service with good support and excellent infrastructure and connectivity</strong>.</p>
<p>I had been using a single 256 MB slice to host my entire site, and had managed to get everything well with lighttpd and MySQL, but this configuration ran into serious performance issues once traffic built again. Once I passed 10,000 pageviews per day, which happened quicker than I hoped, it was again time to upgrade.</p>
<h3>Server Configuration</h3>
<p>My core question was whether to go with a single 512MB or two 256 MB slices. <strong>Would resource contention in a single server be outweighed by the extra available RAM?</strong> After consulting with the experts, I decided that it was time to separate the database and web servers.</p>
<div id="attachment_2122" class="wp-caption aligncenter" style="width: 451px;  border: 1px solid #dddddd; background-color: #f3f3f3; padding-top: 4px; margin: 10px; text-align:center; display: block; margin-right: auto; margin-left: auto;"><a href="http://blog.fosketts.net/wp-content/uploads/2009/06/Web-slice-setup.png" ><img class="size-full wp-image-2122 " title="Web slice setup" src="http://blog.fosketts.net/wp-content/uploads/2009/06/Web-slice-setup.png" alt="A multi-server setup delivers performance, reliability, and future capability." width="441" height="193" /></a><p style=' padding: 0 4px 5px; margin: 0;'  class="wp-caption-text">A multi-server setup delivers performance, reliability, and future capability.</p></div>
<p>As illustrated above, the database and web servers communicate via a high-speed private network, a standard Slicehost component. I created extremely restrictive iptables firewall policies to control access to both servers, disabling almost all communication. The database server in particular is inaccessible except from the web server, and even then only allows MySQL and public key ssh. Both servers are running bare-bones versions of Ubuntu 9.04.</p>
<h3>MySQL Configuration</h3>
<p><strong>MySQL is much happier on its own dedicated server</strong>. It makes excellent use of its own query cache and operating system buffers and has very little disk access at all. Query performance immediately jumped, and site performance noticeably improved.</p>
<p>My only change to my.cnf was to enable the query cache. This works great on my 256 MB slice:</p>
<pre># Enable query cache
query_cache_limit       = 2M
query_cache_size        = 32M</pre>
<p>I&#8217;m not a believer in security through obscurity. Sure, you can use a special high MySQL port, but by then you&#8217;ve probably lost anyway. Regardless, set up iptables to only allow access from your web server&#8217;s private interface using the -s parameter:</p>
<pre># Allow connections on our MySQL port
-A INPUT -p tcp --dport mysql -s 10.176.x.x -j ACCEPT</pre>
<p>It&#8217;s a pretty simple configuration, but it works well. MySQL is humming along without much paging at all, using the entirety of the 256 MB available for caching. I haven&#8217;t had to resort to any tricks to keep the performance up.</p>
<p>One more configuration suggestion: <strong>Use a unique username and password for each database application</strong> and <strong>grant access only to that user on the private network interface</strong>. That way, your risk is segmented to a single database should an intruder use a SQL injection or something similar.</p>
<p>For example, say you were configuring the database &#8220;myblog_wp&#8221; for the user &#8220;me_myblog&#8221; with the password &#8220;123456abcdef&#8221;. You use the web server&#8217;s private interface address, 10.176.x.x as well so it is harder to get in even if your firewall is breached.</p>
<pre>mysql -u root -p
Enter password:
mysql&gt; grant all on myblog_wp.* to 'me_myblog'@'10.176.x.x' identified by '123456abcdef';</pre>
<p>All set!</p>
<h3>Basic Lighttpd Configuration</h3>
<p>Back on the web server, we <strong>configure iptables to only allow connections to lighttpd on port 80 and ssh</strong> on whatever port you decide. Again, some suggest using a high port for ssh, but if you&#8217;ve configured sshd correctly then using an obscure port number is more likely to be a hassle for you than keep anyone out. Here are some good settings for /etc/ssh/sshd_config:</p>
<pre>PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
X11Forwarding no
UsePAM no
UseDNS no</pre>
<p>This forces all logins to use established public/private key pairs rather than passwords. <strong>Protect your keys</strong> and you&#8217;re in good shape. Key passphrases are a very good idea here! You&#8217;re also disallowing root in any case, since <strong>you&#8217;re using sudo for all administrative tasks</strong>, right?</p>
<p>Next we need to set up lighttpd. I&#8217;m using the basic packaged versions for ease of maintenance rather than building my own. I also loaded the stock versions of php5 and mysql-client which integrate nicely. I used to use eaccelerator but didn&#8217;t love having to recompile it myself and had some mysterious lockups with it running. So <strong>I went with XCache</strong>, which is developed by the same fine folks who created lighttpd.</p>
<pre>sudo aptitude install mysql-client lighttpd php5-xcache</pre>
<p>Why not use Apache? I actually tested Apache with my site before deciding to use lighttpd. I was able to tweak it to run in 256 MB of RAM by limiting the number of worker processes created to 4, but <strong>Apache just couldn&#8217;t handle the site load</strong>. Connections were stacking up and pageviews dropped as people gave up. <strong>Lighttpd with XCache is blindingly fast</strong> and fits in my 256 MB RAM envelope nicely.</p>
<p>The only real issue I have with lighttpd is that configuration is entirely different from Apache and remains less well-supported. It doesn&#8217;t use with .htaccess files, for example, and rewrites use a unique syntax.</p>
<h3>Lighttpd for WordPress</h3>
<p>Here&#8217;s a basic virtual server for /etc/lighttpd/lighttpd.conf for a WordPress domain:</p>
<pre>$HTTP["host"] =~ "^(blog\.)?yourdomain\.com$" {
  server.name = "yourdomain.com"
  server.document-root = basedir + server.name + "/blog"
  url.access-deny = ( "wp-config.php" )
  dir-listing.activate = "disable"
  url.rewrite-final = (
    # Exclude some directories from rewriting
    "^/(wp-admin|wp-includes|wp-content)/(.*)" =&gt; "$0",
    # Uncomment to exclude Google FriendConnect files
    # "^/(canvas.html|rpc_relay.html)" =&gt; "$0",
    # Exclude .php, robots.txt, favicon.*, and sitemap.xml files at root from rewriting
    "^/(.*.php|sitemap.xml|robots.txt|favicon.*)" =&gt; "$0",
    # Handle WordPress permalinks and feeds
    "^/(.*)$" =&gt; "/index.php/$1"
  )
  accesslog.filename = basedir + "/" + server.name + "/log/blog.access.log"
}</pre>
<p>This configuration accomplishes many of the important tasks of WordPress configuration. Most importantly, <strong>it works</strong>!</p>
<ol>
<li>Permalinks and feeds are correctly redirected so no ugly index.php is used</li>
<li>Critical directories like wp-admin and files like robots.txt still work</li>
<li>Your wp-config.php file is explicitly protected</li>
<li>Directory listings are disabled</li>
<li>A site-specific access log is used (like Apache)</li>
</ol>
<p><strong>I&#8217;d love feedback on this configuration! </strong>One weird thing I&#8217;ve not yet figured out is how to use a site-specific error log. I haven&#8217;t configured pretty MediaWiki links in lighttpd yet, but imagine a similar configuration would work there.</p>
<div id="crp_related"><h3>You might also want to read these other posts...</h3><ul><li><a href="http://blog.fosketts.net/2009/02/07/apologies-404s/"  rel="bookmark" class="crp_title">Apologies For The 404s!</a></li><li><a href="http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/"  rel="bookmark" class="crp_title">A High-Performance, Low-Memory Apache/PHP Virtual Private Server</a></li><li><a href="http://blog.fosketts.net/2009/06/29/tuning-lighttpd-linux/"  rel="bookmark" class="crp_title">Tuning Lighttpd For Linux</a></li><li><a href="http://blog.fosketts.net/2010/08/01/force-apache-redirect-canonical-hostnames-serveralias-friend/"  rel="bookmark" class="crp_title">How To Force Apache To Redirect To Canonical Hostnames, or ServerAlias Is Not Your Friend</a></li><li><a href="http://blog.fosketts.net/2009/11/30/configure-drobo-dashboard-email-gmail-google-apps/"  rel="bookmark" class="crp_title">How To Configure Drobo Dashboard Email for Gmail and Google Apps</a></li></ul></div><script src="http://feeds.feedburner.com/~s/sfoskett?i=http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/" type="text/javascript" charset="utf-8"></script><hr />
<p><small>© sfoskett for <a href="http://blog.fosketts.net">Stephen Foskett, Pack Rat</a>, 2009. |
<a href="http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/">Setting Up a Multi-Server Web Hosting Environment</a>
<br/>
This post was categorized as <a href="http://blog.fosketts.net/category/everything/personal/" title="View all posts in Personal" rel="category tag">Personal</a>. Each of my categories has its own feed if you'd like to filter out or focus on posts like this.<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<series:name><![CDATA[Web Hosting]]></series:name>
	</item>
		<item>
		<title>Apologies For The 404s!</title>
		<link>http://blog.fosketts.net/2009/02/07/apologies-404s/</link>
		<comments>http://blog.fosketts.net/2009/02/07/apologies-404s/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 16:04:50 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Everything]]></category>
		<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[Linode]]></category>
		<category><![CDATA[MediaWiki]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[VPS]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://blog.fosketts.net/?p=1401</guid>
		<description><![CDATA[I&#8217;ve been using Dreamhost as my hosting provider since 2000, mostly happily. But last year I began receiving enough traffic that I could no longer rely on shared hosting. Last Fall, I switched all of my domains to a virtual private server at Dreamhost &#8211; an easy upgrade that doubled my hosting bill but promised [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Dreamhost as my hosting provider since 2000, mostly happily. But last year I began receiving enough traffic that I could no longer rely on shared hosting. Last Fall, I switched all of my domains to a virtual private server at Dreamhost &#8211; an easy upgrade that doubled my hosting bill but promised all the performance I would need. Sadly, this was not the case.</p>
<p>Dreamhost never could get their flexible resource provisioning control panel to work right with my server, and their support staff was only slightly responsive. I limped along for three months, waiting for them to get everything working right and suffering through two unexplained multi-hour server outages. After losing my server for an hour and a half yesterday without any response or explanation whatsoever from Dreamhost support, I decided that enough was enough. After nine years as a customer, I am moving my sites elsewhere.</p>
<p>I looked around for a rock-solid Xen VPS/Linux provider with high performance and affordable prices. After checking into many that were recommended, I narrowed my search to two: Linode and Slicehost. Both differ from Dreamhost in that they offer unconfigured servers rather than point-and-click convenience and management. But after almost 20 years in UNIX administration, I figured I was up to the job.</p>
<p>After examining the two, I decided that <a href="https://manage.slicehost.com/customers/new?referrer=31e5d9e0da4b70b80d0cb0bcc8efc95a"  target="_blank">Slicehost</a>, which was recently acquired by Rackspace, offered the best solution for me. One deciding factor was Linode&#8217;s failure to offer backup services of any kind &#8211; that&#8217;s just bizarre! When all is done, I will be spending just $5 more per month than my Dreamhost VPS cost, and will hopefully get much better performance and stability.</p>
<blockquote><p>If you&#8217;re interested in setting up a web site as outlined here, <a href="https://manage.slicehost.com/customers/new?referrer=31e5d9e0da4b70b80d0cb0bcc8efc95a"  target="_blank">I recommend Slicehost</a>. They&#8217;re not the cheapest, but their VPS servers are fast and reliable.</p></blockquote>
<p>So I spent much of Friday evening setting up Ubuntu on my slice, copying data, configuring DNS, and installing lighttpd, php, MySQL, WordPress, Mediawiki, and the rest. After some teething issues, I believe that everything is now up and running properly on my new host! Please let me know (by clicking the &#8220;Email Me&#8221; link in the upper left corner) if you see any errors or issues!</p>
<div id="crp_related"><h3>You might also want to read these other posts...</h3><ul><li><a href="http://blog.fosketts.net/2009/06/26/multiserver-web-host-environment/"  rel="bookmark" class="crp_title">Setting Up a Multi-Server Web Hosting Environment</a></li><li><a href="http://blog.fosketts.net/2010/07/30/high-performance-memory-apache-php-virtual-private-server/"  rel="bookmark" class="crp_title">A High-Performance, Low-Memory Apache/PHP Virtual Private Server</a></li><li><a href="http://blog.fosketts.net/2009/07/01/cloudstuff-stuff-cloud/"  rel="bookmark" class="crp_title">CloudStuff Versus Stuff in the Cloud</a></li><li><a href="http://blog.fosketts.net/2009/06/29/tuning-lighttpd-linux/"  rel="bookmark" class="crp_title">Tuning Lighttpd For Linux</a></li><li><a href="http://blog.fosketts.net/2007/11/26/import-your-old-outlookexpress-psts-to-gmail/"  rel="bookmark" class="crp_title">Import your old Outlook/Express PSTs to Gmail</a></li></ul></div><script src="http://feeds.feedburner.com/~s/sfoskett?i=http://blog.fosketts.net/2009/02/07/apologies-404s/" type="text/javascript" charset="utf-8"></script><hr />
<p><small>© sfoskett for <a href="http://blog.fosketts.net">Stephen Foskett, Pack Rat</a>, 2009. |
<a href="http://blog.fosketts.net/2009/02/07/apologies-404s/">Apologies For The 404s!</a>
<br/>
This post was categorized as <a href="http://blog.fosketts.net/category/everything/" title="View all posts in Everything" rel="category tag">Everything</a>. Each of my categories has its own feed if you'd like to filter out or focus on posts like this.<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://blog.fosketts.net/2009/02/07/apologies-404s/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

