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

<channel>
	<title>HostingFu &#187; drupal</title>
	<atom:link href="http://hostingfu.com/tag/drupal/feed" rel="self" type="application/rss+xml" />
	<link>http://hostingfu.com</link>
	<description>Web Hosting Blog by a Software Developer</description>
	<lastBuildDate>Mon, 19 Jul 2010 09:27:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>HostingFu Migrated to VPSLink/WordPress &amp; Some Updates</title>
		<link>http://hostingfu.com/article/hostingfu-migrated-to-vpslinkwordpress-some-updates</link>
		<comments>http://hostingfu.com/article/hostingfu-migrated-to-vpslinkwordpress-some-updates#comments</comments>
		<pubDate>Tue, 17 Nov 2009 11:33:53 +0000</pubDate>
		<dc:creator>scotty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[hostingfu]]></category>
		<category><![CDATA[slicehost]]></category>
		<category><![CDATA[vpslink]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://hostingfu.com/?p=221</guid>
		<description><![CDATA[Sorry about lack of updates here. A lot of happening in life and it has been quite a hectic year. I have also made some significant changes under the skin here at HostingFu. I said &#8220;under the skin&#8221; because I have actually kept the old theme and look &#38; feel of the site, but&#8230; From [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry about lack of updates here. A lot of happening in life and it has been quite a hectic year. I have also made some significant changes <em>under the skin</em> here at HostingFu. I said &#8220;under the skin&#8221; because I have actually kept the old theme and look &amp; feel of the site, but&#8230;</p>
<h3 id="toc-from-slicehost-to-vpslink">From SliceHost to VPSLink</h3>
<p style="text-align:center"><img src="http://hostingfu.com/files/images/slicehost-to-vpslink.png" width="369" height="50" alt="SliceHost to VPSLink"/></a></p>
<p>I have migrated from <a href="http://www.slicehost.com/">SliceHost</a>, i.e. the RackspaceCloud, to <a href="http://www.vpslink.com/">VPSLink</a> for hosting this blog. See my <a href="http://hostingfu.com/article/vpslink-xen-vps-2-weeks-review">previous VPSLink review here</a>.</p>
<p>SliceHost has served me <em>very well</em> <a href="http://hostingfu.com/article/slicehost-initial-impression">for the last 3 years</a>. In fact at one stage I had &gt; 450 days of uptime, before one of my Python script crashed the slice by using up too much memory. Performance has been great. Absolutely tops in stability. Highly recommended if you are looking for the &#8220;Rackspace of Xen VPS host&#8221; (which it literally is).</p>
<p><span id="more-221"></span></p>
<p>I am however switching to VPSLink for this site for a few reasons (together with about 10 other sites I run). Because,</p>
<ul>
<li>It costs me less. From heavy discount &amp; referral system, I am getting a Xen Link4 for ~$251/12 months ($29.36/month x 12 &#8211; 10% coupon code discount &#8211; $66 referral bonus), which has 512MB RAM, 20GB disk space &amp; 500GB/month data transfer. It&#8217;s actually <em>free</em> to me because of past referral credit.</li>
<li>Sydney to Seattle is around 20ms less than Sydney to St. Louis</li>
<li>VPSLink has 32bit templates, which <a href="http://hostingfu.com/article/32-or-64-bit-your-vps">saves memory for my LAMP stack</a>.</li>
<li>Accessing to all 8 cores of an Xeon E5420 rocks (not that I need it).</li>
<li>Did I say it&#8217;s free?</li>
</ul>
<p>So due to simple economics I made the change to migrate my sites from SliceHost to VPSLink. Thanks for the service!</p>
<h3 id="toc-from-drupal-to-wordpress">From Drupal to WordPress</h3>
<p style="text-align:center"><img src="http://hostingfu.com/files/images/drupal-to-wordpress.png" width="411" height="45" alt="Drupal to WordPress"/></a></p>
<p>Another big change that I have made is switching from <a href="http://drupal.org/">Drupal</a> to <a href="http://wordpress.org/">WordPress</a> as the blogging platform.</p>
<p>Man I love Drupal. It is flexible and very customisable. It is a developer&#8217;s dream CMS because of its flexibility. It is powering my main hobby site at the moment (which takes way too much of my time) serving over 4 million page views a month.</p>
<p>However what I am doing here is just <em>blogging</em>. I am not running a community, nor trying to organise some structured content. I am just posting things here a few times a month, and the flexibility of Drupal has actually became a curse. Drupal 7 is almost out, but I cannot even upgrade to Drupal 6 without heavily tweaks on my modules.</p>
<p>So I gave up. Might as well run WordPress and keep things simple.</p>
<p>I ended up spending a day developing a converter to migrate all my old posts + comments from Drupal to WordPress and retain all the permalinks. So far so good.</p>
<h3 id="toc-other-updates">Other Updates</h3>
<p>A few other updates around the place.</p>
<ul>
<li>Updated <a href="http://hostingfu.com/article/server-monitoring-cacti-serverstats">serverstats</a> to 0.2. Ended up rewriting the tokenizer to get rid of dependency on libpcre so it uses even less memory.</li>
<li>Updated <a href="http://hostingfu.com/article/keeping-your-php-fastcgi-processes-alive">phpmonitor.py</a> as Linode cleaned up their pastebin thus removed my code.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hostingfu.com/article/hostingfu-migrated-to-vpslinkwordpress-some-updates/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Drupal with Clean URL on Nginx or Lighttpd</title>
		<link>http://hostingfu.com/article/running-drupal-with-clean-url-on-nginx-or-lighttpd</link>
		<comments>http://hostingfu.com/article/running-drupal-with-clean-url-on-nginx-or-lighttpd#comments</comments>
		<pubDate>Wed, 17 Jan 2007 07:36:13 +0000</pubDate>
		<dc:creator>scotty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://hostingfu.com/?p=82</guid>
		<description><![CDATA[First of all, my previous post on Nginx vs. Lighttpd for a small VPS seems to be a &#8220;hit&#8221;. Thanks to Glenn for submitting it to programming.reddit.com, which got picked up by a few bloggers. Got around 1,000 unique visitors on the day where the post went live, which I guess is pretty good for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://drupal.org/"><img src="http://hostingfu.com/files/images/drupal-logo.png" alt="Drupal Logo" width="100" height="109" style="float:right;margin:0 0 1ex 1ex"/></a> First of all, my previous post on <a href="http://hostingfu.com/article/nginx-vs-lighttpd-for-a-small-vps">Nginx vs. Lighttpd for a small VPS</a> seems to be a &#8220;hit&#8221;. Thanks to <a href="http://blog.slaven.net.au/">Glenn</a> for submitting it to <a href="http://programming.reddit.com/">programming.reddit.com</a>, which got picked up by a few bloggers. Got around 1,000 unique visitors on the day where the post went live, which I guess is pretty good for this one-post-a-week site of mine.</p>
<p>Since I have briefly touched on the &#8220;URL rewrite-ability&#8221; of Nginx and Lighttpd in my previous post, I think it might actually be useful to have some examples showing how rewrite rules are written on these web servers to support clean URLs. I will take the open source CMS <a href="http://drupal.org/">Drupal</a> for example, as it is what <b>Hosting Fu</b> runs on. Btw, <a href="http://drupal.org/drupal-5.0">Drupal 5.0</a> has just been released and it rocks.</p>
<p><span id="more-82"></span></p>
<h3 id="toc-prerequisite">Prerequisite</h3>
<p>These are the things that I assume you would know before reading this article.</p>
<ul>
<li><strong>Why clean URL</strong>. Pick your reason. SEO or general dislike of query string.</li>
<li><strong>Setting up PHP</strong>. I won&#8217;t be talking about how to set up PHP/FastCGI on Nginx or Lighttpd. Here&#8217;s one for <a href="http://wiki.codemongers.com/NginxFcgiExample">Nginx</a> and one for <a href="http://trac.lighttpd.net/trac/wiki/TutorialLighttpdAndPHP">Lighttpd</a>.</li>
<li><strong>Installing Drupal</strong>. Check related section in <a href="http://drupal.org/node/258">Drupal handbook</a>.</li>
</ul>
<p>I am only going to discuss the rewriting rules needed to enable clean URL in Drupal on either Nginx or Lighttpd.</p>
<h3 id="toc-apaches-mod_rewrite">Apache&#8217;s Mod_Rewrite</h3>
<p>Like most open source PHP applications, Drupal came with a <code>.htaccess</code> file assuming Apache is serving the pages. We will use it as the reference on how the rewrite rules can be written for the other two web servers.</p>
<p>Here&#8217;s the bit in <code>.htaccess</code> that does rewrites:</p>
<pre class="code">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</pre>
<p>What it does is:</p>
<ul>
<li>If requested file exists, serve it.</li>
<li>If requested directory exists, serve it depending on how index option is configured.</li>
<li>Otherwise, send all requests to <code>index.php</code>, setting parameter &#8216;q&#8217; as the path of the original request, and then append the rest of the query string.</li>
</ul>
<p>Simple. Now let&#8217;s see how you can do the same with the other two web servers.</p>
<h3 id="toc-lighttpd">Lighttpd</h3>
<p>This site runs on <a href="http://www.lighttpd.net/">Lighttpd</a> 1.4.13, and there seems to be a lot of different ways to do clean URL with Drupal on Lighttpd. Although it came with its own &#8220;mod_rewrite&#8221;, but I found the functionality is very limited. The biggest problem I found is the lack of conditional rules to check whether a file or directory already exists. At the end you have to either (1) make lots of exceptions in Lighttpd&#8217;s rewrite rules, or (2) modify Drupal so it works better with Lighttpd.</p>
<p>I went with the second option.</p>
<p>Well, here are the steps.</p>
<ol>
<li>
<p>After Drupal has been installed and tested with clean URL disabled, add the following rules to lighty&#8217;s configuration file:</p>
<pre class="code">
server.error-handler-404 = "/index.php";
</pre>
<p>It basically makes <code>index.php</code> the 404 error handler, so any request that does is not handled by a local file or directory will be sent to Drupal.</p>
</li>
<li>
<p>Add the following PHP code to Drupal. I just append them to the end of <code>sites/default/settings.php</code>.</p>
<pre class="code">
if (strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) {
    $_lighty_url = $base_url.$_SERVER['REQUEST_URI'];
    $_lighty_url = @parse_url($_lighty_url);

    if ($_lighty_url['path'] != '/index.php' &amp;&amp; $_lighty_url['path'] != '/') {
        $_SERVER['QUERY_STRING'] = $_lighty_url['query'];
        parse_str($_lighty_url['query'], $_lighty_query);
        foreach ($_lighty_query as $key =&gt; $val)
            $_GET[$key] = $_REQUEST[$key] = $val;
        $_GET['q'] = $_REQUEST['q'] = substr($_lighty_url['path'], 1);
    }
}
</pre>
<p>Let me explain what it does:</p>
<ul>
<li>If we are behind lighty, turn on this hack (I use Nginx for my development box so this code does not apply).</li>
<li>Try to parse the <code>REQUEST_URI</code>. If invoked as 404 error handler, we will parse the <code>QUERY_STRING</code> ourselves and copy the values to PHP&#8217;s <code>$_GET</code> and <code>$_REQUEST</code> variables.</li>
<li>Also set the path bit of <code>REQUEST_URI</code> as query argument <code>q</code>.</li>
</ul>
<p>The reason why we have to parse <code>QUERY_STRING</code> is, Lighttpd <a href="http://trac.lighttpd.net/trac/wiki/FrequentlyAskedQuestions#Whatkindofenvironmentdoesserver.error-handler-404setup">deliberately</a> does not set <code>QUERY_STRING</code> if FastCGI is invoked as 404 error handler.</p>
</li>
<li>
<p>Restart lighty, go to Drupal to enable clean URL and see whether it works.</p>
</li>
</ol>
<p>Well, it has been working fine for me, but YMMV.</p>
<h3 id="toc-nginx">Nginx</h3>
<p><a href="http://nginx.net/">Nginx</a> comes with conditional code for rewrite rules so it is much easier. I basically have the following code in my Nginx configuration file to emulate Apache&#8217;s behaviour.</p>
<pre class="code">
if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?q=$1 last;
}
</pre>
<p>That&#8217;s it! Restarting Nginx, and you can now turn on clean URL in Drupal.</p>
<p><strong>However</strong>, Nginx is not perfect, and so far I have found one small issue with its rewrite engine. When you use regular expression in Nginx&#8217;s rewrite rules, it will try to encode the matches in the replacement URL. So far I have seen it broke Drupal&#8217;s search module. For example, if you search for &#8220;Hosting Fu&#8221;, Drupal will use the following URL:</p>
<pre class="code">
GET /search/node/Hosting+Fu HTTP/1.1
</pre>
<p>However, Nginx will rewrite that to:</p>
<pre class="code">
GET /index.php?q=search/node/Hosting%2BFu HTTP/1.1
</pre>
<p>Note it encoded &#8216;+&#8217; to &#8216;%2B&#8217;, which confuses Drupal, who thinks that you are actually searching the phrase &#8216;Hosting+Fu&#8217;. In case of Apache, &#8216;+&#8217; passed through rewrite rules untouched.</p>
<h3 id="toc-conclusion">Conclusion</h3>
<p>Many open source PHP applications that I have experience with always <strong>assume</strong> the existence of Apache, and provide clean URL to only Apache users. On the other hand, developers of other frameworks like Ruby on Rails, Django, Webpy, etc take clean URL for granted because it is something handled right inside the framework. It makes the life of the web server guy much easier &#8212; what rewrite? Just proxy or pass through the whole damn thing!</p>
<p>I am hoping more and more PHP applications will use simplified rewrite rules. Let applications themselves take care of parsing the <code>REQUEST_URI</code>, instead of generating a million lines of Apache mod_rewrite rules and dumping them into <code>.htaccess</code> files.</p>
<p>Meanwhile, Nginx users will have much easier time porting those rules then the Lighttpd users.</p>
]]></content:encoded>
			<wfw:commentRss>http://hostingfu.com/article/running-drupal-with-clean-url-on-nginx-or-lighttpd/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>
