<?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>Guy Rutenberg &#187; Lighttpd</title>
	<atom:link href="http://www.guyrutenberg.com/tag/lighttpd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing Lighttpd-1.4.22 on Ubuntu 8.04</title>
		<link>http://www.guyrutenberg.com/2009/05/31/installing-lighttpd-1422-on-ubuntu-804/</link>
		<comments>http://www.guyrutenberg.com/2009/05/31/installing-lighttpd-1422-on-ubuntu-804/#comments</comments>
		<pubDate>Sun, 31 May 2009 19:43:19 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=371</guid>
		<description><![CDATA[I had some problems with the lighttpd-1.4.19 that comes with Ubuntu 8.04, mainly it&#8217;s problems of handling the HTTP header Expect: 100-continue (which older versions of Lighttpd return error 417). The problem was fixed in Lighttpd-1.4.21, but 1.4.22 is the newest version so I&#8217;ve decided to install it.
As I mentioned before, Ubuntu doesn&#8217;t have lighttpd-1.4.22 [...]]]></description>
			<content:encoded><![CDATA[<p>I had some problems with the lighttpd-1.4.19 that comes with Ubuntu 8.04, mainly it&#8217;s problems of handling the HTTP header <code>Expect: 100-continue</code> (which older versions of Lighttpd return error 417). The problem was fixed in Lighttpd-1.4.21, but 1.4.22 is the newest version so I&#8217;ve decided to install it.</p>
<p>As I mentioned before, Ubuntu doesn&#8217;t have lighttpd-1.4.22 for 8.04, and it&#8217;s also not available in the updates or backports repositories. Fortunately, I&#8217;ve found that the package is available from Debuian Sid (unstable). Here are some instructions on how to install it.<br />
<span id="more-371"></span><br />
Start By downloading the following packages.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">wget http://ftp.de.debian.org/debian/pool/main/l/lighttpd/lighttpd_1.4.22-1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/main/p/pcre3/libpcre3_7.8-2_amd64.deb</pre></div></div>

<p>You can statisfy using the offical repositories all the dependencies of lighttpd-1.4.22 except the libpcre3, which is also available from Debian Sid. So start by installing it.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo dpkg -i libpcre3_7.8-2_amd64.deb
sudo aptitude markauto libpcre3</pre></div></div>

<p>You statisfy the rest of the dependencies by using <code>apt-get</code> and the official repositories. In case you encounter the following problem when starting lighttpd:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/usr/sbin/lighttpd: Symbol `FamErrlist' has different size in shared object, con
sider re-linking</pre></div></div>

<p>it can be solved easiliy by installing <code>libfam3</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo apt-get install libfam3</pre></div></div>

<p>(don&#8217;t worry if it complains about needing to remove <code>libgamin0</code>). You should be done now, and you can start enjoying your shining lighttpd-1.4.22.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/05/31/installing-lighttpd-1422-on-ubuntu-804/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Review: Lighttpd by Andre Bogus</title>
		<link>http://www.guyrutenberg.com/2009/05/22/book-review-lighttpd-by-andre-bogus/</link>
		<comments>http://www.guyrutenberg.com/2009/05/22/book-review-lighttpd-by-andre-bogus/#comments</comments>
		<pubDate>Fri, 22 May 2009 08:09:55 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[Lighttpd]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=343</guid>
		<description><![CDATA[As an avid user of Lighttpd, I was glad to receive a copy of the &#8220;Lighttpd&#8221; book by Andre Bogus (Packt publishing) for reviewing. I&#8217;ve been using Lighttpd extensively for production over a year now and I&#8217;m very satisfied. However, I remember that as a new user I had my share of frustration. In his [...]]]></description>
			<content:encoded><![CDATA[<p>As an avid user of Lighttpd, I was glad to receive a copy of the &#8220;<a href="http://www.packtpub.com/lighttpd/book/mid/080409rdxmpu">Lighttpd</a>&#8221; book by Andre Bogus (Packt publishing) for reviewing. I&#8217;ve been using Lighttpd extensively for production over a year now and I&#8217;m very satisfied. However, I remember that as a new user I had my share of frustration. In his book, Andre Bogus, tries ease the process for those that decided to move to Lighttpd.<br />
<span id="more-343"></span><div class="wp-caption alignright" style="width: 310px"><a href="http://www.packtpub.com/lighttpd/book/mid/080409rdxmpu"><img alt="Lighttpd books front cover" src="https://www.packtpub.com/images/full/1847192106.jpg" title="lighttpd_book_cover" width="300" /></a><p class="wp-caption-text">Lighttpd book&#39;s front cover</p></div></p>
<p>The book starts with a introduction and installation guide for Lighttpd. Bogus starts by describing how to install via a package-manager. This is pretty straight forward and should be good for any user of a modern Linux distribution (although I did find it strange that he ignored the automatic dependency handling in every distribution except Gentoo). Bogus doesn&#8217;t stop at the obvious, he goes on to describe the installation from source procedure, for both Lighttpd 1.4 and 1.5. I find it convinient because not always the package-manager installed on the server has the latest stable and development versions of Lighttpd (as matter of fact Ubuntu 8.04LTS has Lighttpd-1.4.19 while the latest stable is 1.4.22). Choosing to describe both 1.4 and 1.5 installation is beneficial for the user. While currently 1.5 is under development, it will one day become stable and by addressing it, Bogus insures that his book will remain relevant after that too.</p>
<p>After the installation process, Bogus describes the basic configuration of a Lighttpd server. He includes a nice regular-expressions tutorial, and thus save the reader time by not having to read and learn the subject elsewhere. Having a regex tutorial together with the url rewriting and selectors sections is indeed useful and serves as a nice reference to experienced users too.</p>
<p>After the basic configurations are covered the book moves on to more advanced ones. Covering CGI the book describes both 1.4 and 1.5 ways for running CGI scripts and related technologies such as Fast-CGI and SCGI used in Lighttpd for running PHP, Python and Ruby (as well as other) applications. Once again the decision to describe both 1.4 and 1.5 is great in my opinion. The book continues to more advanced stuff, like configuring Lighttpd for streaming and SSL encryption, which will be relevant for some users.</p>
<p>The next chapters (7-9) cover securing and optimizing the Lighttpd installation. They describe methods that are important to every Lighttpd user, whether he a single user or a system admin managing many corporate servers. Focusing on security is important for todays web-applications that many times contains users&#8217; sensitive data and are focused by malicious activity.</p>
<p>Chapter 10 gives a migration guide from Apache. Many new Lighttpd users switch over from Apache, and this chapter eases the migration. The chapter is useful even for those not familiar with Apache at all, because some popular applications are designed with only Apache in mind, and thus require the user to configure on his own any other web-server he might use. By understanding the migration process from Apache to Lighttpd, a potential user will have less problems installing applications designed for Apache later on.</p>
<p>In chapters 11 the author overviews installation of many popular applications such as Ruby on Rails, Wordpress, MediaWiki, Trac, AWStat and AjaxTerm. While the overview guides you through the basic installation, I felt that sometimes it doesn&#8217;t go all the way. For example, in the WordPress overview, the users is ends of WordPress installed but without clean urls, an important feature in my opinion. While clean urls for WordPress under Lighttpd is well documented in the internet (when I&#8217;ve moved my blog to Lighttpd I&#8217;ve wrote about <a href="/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/">configuring WordPress permalinks using mod_rewrite</a>), I think it could have been better to describe it too in the book itself, or at least give a reference to some other guide.</p>
<p>Chapters 12 and 13 cover more advanced topics like server-side scripting with Lua and writing custom Lighttpd modules. While I&#8217;m not sure if the average user will find this topics of interest, they surely be of help to more advanced users looking to extend Lighttpd&#8217;s features.</p>
<p>Overall, I&#8217;ve found this book to be a nice reference and manual for Lighttpd. It goes through from basic setup to more the advanced topics of custom modules. While I think it will be more appropriate for novices, I believe advanced users and system admins may find it beneficial too, even as only a reference to Lighttpd. Packt publishing offers the book in two forms: a regular old fashioned paperback and a DRM-free eBook (in PDF) allowing both printing and copy-pasting. I found the eBook a nice way to read, especially since it provides a simple way to copy and paste the configuration and code examples from the book.</p>
<p><em>Disclosure: I receive a 12% percent referral commission for every Lighttpd book sold through the above links.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/05/22/book-review-lighttpd-by-andre-bogus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configuring Lighttpd for CakePHP</title>
		<link>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/</link>
		<comments>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 21:38:09 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Lighttpd]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=252</guid>
		<description><![CDATA[I tried a few days ago to install a CakePHP project of mine on a lighttpd web-server. As expected, it&#8217;s clean URLs didn&#8217;t work, so I set out to find a solution.
One possible solution is the one oulined in the CakePHP manual. The solution uses the mod_magnet module (which basically runs a Lua script to [...]]]></description>
			<content:encoded><![CDATA[<p>I tried a few days ago to install a <a href="http://www.cakephp.org">CakePHP</a> project of mine on a <a href="http://www.lighttpd.net">lighttpd</a> web-server. As expected, it&#8217;s clean URLs didn&#8217;t work, so I set out to find a solution.</p>
<p>One possible solution is the <a href="http://book.cakephp.org/view/782/Lighttpd-and-mod_magnet">one</a> oulined in the CakePHP manual. The solution uses the <code>mod_magnet</code> module (which basically runs a Lua script to do the rewriting), and I found it an overkill. I was looking for a simple solution based only on <code>mod_rewrite</code>, something like the <a href="/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/">solution for Wordpress</a>.<br />
<span id="more-252"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$HTTP[&quot;host&quot;] =~ &quot;^(www\.)?example.com&quot; {
        server.document-root = &quot;/home/guy/example.com/app/webroot/&quot;
        url.rewrite = (
                &quot;(css|files|img|js)/(.*)&quot; =&gt; &quot;/$1/$2&quot;,
                &quot;^([^\?]*)(\?(.+))?$&quot; =&gt; &quot;/index.php?url=$1&amp;$3&quot;,
        )
}</pre></div></div>

<p>I will go line by line over the solution. The first line defines a vhost for the site. This is a simple vhost that uses conditional configurations. The second line sets the server&#8217;s document root to my app&#8217;s webroot directory (you&#8217;ll need to change the path accordingly). The next section is the URL rewriting which is the most important part. The first line of the rewriting rules takes care of the static files you serve from the document root, e.g. CSS, JavaScript, image etc. You can add to the begining of the rule (the <code>css|files|img|js</code> any other directory you would like to sever static files from). The next line takes care of Cake&#8217;s clean URLs. It&#8217;s important to capture any query string explicitly, if exists, and pass it in appropriate way so GET variables will be passed correctly.</p>
<p>I hope other CakePHP users who want to develop their apps on lighttpd will find this &#8220;lightweight&#8221; solution helpful. Don&#8217;t hesitate to ask question and post your comments about this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/01/24/configuring-lighttpd-for-cakephp/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin + Lighttpd in Gentoo</title>
		<link>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/</link>
		<comments>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 16:14:57 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Lighttpd]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=248</guid>
		<description><![CDATA[Usually installing software in Gentoo is a piece of cake. Just emerge what you want and (with the right USE flags) and everything will be ready for you. However, as today I&#8217;ve found out today, installing phpMyAdmin with Lighttpd isn&#8217;t trivial as it should be.
In this post I&#8217;ll try to walk you through the necessary [...]]]></description>
			<content:encoded><![CDATA[<p>Usually installing software in Gentoo is a piece of cake. Just <code>emerge</code> what you want and (with the right USE flags) and everything will be ready for you. However, as today I&#8217;ve found out today, installing phpMyAdmin with Lighttpd isn&#8217;t trivial as it should be.</p>
<p>In this post I&#8217;ll try to walk you through the necessary steps to install phpMyAdmin with Lighttpd in Gentoo.<br />
<span id="more-248"></span></p>
<h3>Installing Lighttpd and PHP</h3>
<p>Before installing Lighttpd and PHP you&#8217;ll need to enable some USE flags. For Lighttpd you&#8217;ll need to at least enable the <code>php</code> and <code>fastcgi</code> USE flags. For PHP enable the <code>cgi</code>, <code>crypt</code>, <code>ctype</code>, <code>pcre</code>, <code>session</code>, <code>unicode</code>. The first one is required for working with Lighttpd, while the others are required for phpMyAdmin.</p>
<p>See the <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&#038;chap=2">handbook</a> for information about enabling USE flags.</p>
<p>Now install the packages</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av lighttpd php</pre></div></div>

<p>After installation is complete, start the Lighttpd process</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/etc/init.d/lighttpd start</pre></div></div>

<p>and you should have a working Lighttpd server with PHP support.</p>
<h3>Installing phpMyAdmin</h3>
<p>phpMyAdmin depends on a package called <code>webapp-config</code>. While usually we let Portage take care of dependencies, this time we&#8217;ll have to install <code>webapp-config</code> manually before we install phpMyAdmin, so we can change its configuration for suit Lighttpd.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av --oneshot webapp-config</pre></div></div>

<p>After installation is done edit using your favourite editor the <code>/etc/vhosts/webapp-config</code> and change the line:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vhost_server=&quot;apache&quot;</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">vhost_server=&quot;lighttpd&quot;</pre></div></div>

<p>Now we are ready to install phpMyAdmin.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">emerge -av phpmyadmin</pre></div></div>

<p>After installation is complete, you&#8217;ll need to create a phpMyAdmin configuration file</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cp /var/www/localhost/htdocs/phpmyadmin/config.sample.inc.php /var/www/localhost/htdocs/phpmyadmin/config.inc.php</pre></div></div>

<p>Now open the newly created configuration file and edit the line with the <code>blowfish_secret</code> (at the top of the file) as explained in it. An easy way to generate the password would be to use <a href="http://www.guyrutenberg.com/2008/05/04/spass-11-secure-password-generator/"><code>spass</code></a>.</p>
<p>Now if you use the default Lighttpd configurations you&#8217;re done. You can access the phpMyAdmin via <code>http://localhost/phpmyadmin</code>. If however you&#8217;ve changed the document root, there is one more step for you. Enable the <code>mod_alias</code> module in <code>/etc/lighttpd/lighttpd.conf</code> and append to the file</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">alias.url += (&quot;/phpmyadmin&quot; =&gt; &quot;/var/www/localhost/htdocs/phpmyadmin&quot;)</pre></div></div>

<p>and don&#8217;t forget to restart the Lighttpd server after making the changes.</p>
<p>You should have by now everything installed and configured to work. If you have any further questions don&#8217;t hesitate to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2009/01/20/phpmyadmin-lighttpd-in-gentoo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating URL List from Access Log (access_log)</title>
		<link>http://www.guyrutenberg.com/2008/08/10/generating-url-list-from-access-log-access_log/</link>
		<comments>http://www.guyrutenberg.com/2008/08/10/generating-url-list-from-access-log-access_log/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 19:28:25 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Lighttpd]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=64</guid>
		<description><![CDATA[I had to parse an access_log of a website, in order to generate a sitemap. More precisely, a list of all URLs in the site. After playing around I&#8217;ve found a solution using sed, grep, sort and uniq. The good thing that each of this tools is available by default on most Linux distributions.

I had [...]]]></description>
			<content:encoded><![CDATA[<p>I had to parse an access_log of a website, in order to generate a sitemap. More precisely, a list of all URLs in the site. After playing around I&#8217;ve found a solution using <code>sed</code>, <code>grep</code>, <code>sort</code> and <code>uniq</code>. The good thing that each of this tools is available by default on most Linux distributions.<br />
<span id="more-64"></span><br />
I had the access log file under <code>access_log</code> (if you have it under different name/location just substitute it in the following code. My first attempt parsed out all the URLs which where accessed by POST or GET and sorted the output.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;s/.*(GET|POST) (.*?) HTTP.*/\2/&quot;</span> access_log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span></pre></div></div>

<p>After doing so, I turned out that I don&#8217;t need the the query string (the part after the &#8216;?&#8217; in the url) and I can discard URLs consisting only of &#8216;/&#8217;. So I altered the code to be:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;s/.*(GET|POST|HEAD|PROPFIND) ([^\?]*?)(\?.*?)? HTTP.*/\2/&quot;</span> \
access_log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^/$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span></pre></div></div>

<p>This time I also took care of URLs access by other ways than just POST and GET.</p>
<p>After I got this list, I thought it would be nice to have all the duplicate URLs stripped out. A quick search turned out that there is a nice command-line utility called <code>uniq</code> that does just that and is part of the <code>coreutils</code> package.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;s/.*(GET|POST|HEAD|PROPFIND) ([^\?]*?)(\?.*?)? HTTP.*/\2/&quot;</span> \
access_log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^/$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-u</span></pre></div></div>

<p>So the final solution uses <code>sed</code> to take out the URL part that I wanted. <code>grep</code> discards URLs consisting of only &#8216;/&#8217;. <code>sort</code> and <code>uniq</code> sort out the results and dumps all the duplicate lines.</p>
<p>It&#8217;s nice how one can integrate different command line utilities to do this task in one-liner.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/08/10/generating-url-list-from-access-log-access_log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean URLs (Permalinks) for WordPress on Lighttpd</title>
		<link>http://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/</link>
		<comments>http://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/#comments</comments>
		<pubDate>Sat, 24 May 2008 07:43:21 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Lighttpd]]></category>

		<guid isPermaLink="false">http://www.guyrutenberg.com/?p=58</guid>
		<description><![CDATA[I&#8217;ve moved my blog in the last few days to a new bigger dedicated server (as well as some other sites I own). After doing some benchmarks (I plan to post those soon) I&#8217;ve decided to switch to Lighttpd. While the exact migration notes are the topic of another post, I can say that I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve moved my blog in the last few days to a new bigger dedicated server (as well as some other sites I own). After doing some benchmarks (I plan to post those soon) I&#8217;ve decided to switch to <a href="http://trac.lighttpd.net/">Lighttpd</a>. While the exact migration notes are the topic of another post, I can say that I&#8217;m fairly satisfied with the move.</p>
<p>After setting up the server, I started moving the blog. Importing the files and the database was pretty straight forward. But when I thought every thing is ready and I transfered the domain to the new server I&#8217;ve found out that none of my inner pages are accessible. The reason, as it turned up pretty quickly, is that the Wordpress depends on Apache&#8217;s <code>mod_rewrite</code> to create the clean URLs (the so called permalinks). This actually posed two problems:</p>
<ol>
<li>Wordpress depends on Apache&#8217;s <code>mod_rewrite</code>.</li>
<li>Wordpress used <code>.htaccess</code> files for the clean URLs configuration</li>
</ol>
<p><span id="more-58"></span></p>
<p>Luckily, Lighttpd has its own <a href="http://trac.lighttpd.net/trac/wiki/Docs:ModRewrite"><code>mod_rewrite</code></a>, however it operates a bit differently. The Wordpress generated <code>.htaccess</code> has the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;</pre></div></div>

<p>This rules tells Apache to check if the requested URL is a file or directory that exist on the server, otherwise append the requested URL to <code>index.php</code>. The last statement can be written in Lighttpd&#8217;s <code>mod_rewrite</code> syntax as</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&quot;^/(.+)/?$&quot; =&gt; &quot;/index.php/$1&quot;</pre></div></div>

<p>If we only use this rule, the posts will load up fine, but all static files will not be available, that includes CSS files and images which isn&#8217;t desired. Apache handles this by checking if the requested URL exist as a file or directory. Unfortunately Lighttpd&#8217;s <code>mod_rewrite</code> has no way to check if a file exists. I&#8217;ve found out that a possible workaround for this is to use <code>mod_magent</code> which allows to embed LUA code in Lighttpd, and use it to check if files exist and handle the clean URLs. This seemed to me an overkill, and as some people noted it has some performance hit which I wanted to avoid.</p>
<p>I&#8217;ve figured out that I shouldn&#8217;t just translate the rewrite rules, instead I need to adapt them. In Apache we check if a file exist in order to be able to serve the static files. The directories are checked so the server would be able to list them. The problem is now to achieve those objectives in Lighttpd. First we don&#8217;t really need to allow the directories to be listed (actually I&#8217;ve planed to block this option in my blog a long time ago). So the rule about the directories can be fully ignored. All the static files that need to be served have an extension, this includes all the files I&#8217;ve uploaded. We note that Wordpress generated permalinks never have a dot (&#8216;.&#8217;) in their URLs. So we can exploit this behavior to achieve our goal. The following condition uses regular expressions to check if a given url has an extension, and if so serves it.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&quot;^/(.*)\.(.+)$&quot; =&gt; &quot;$0&quot;</pre></div></div>

<p>The only difference from the Apache configuration is that the web-server itself returns the 404 message when a requested file is missing, instead of passing it to Wordpress and letting it return the error.</p>
<p>To sum everything up, our <code>mod_rewrite</code> configuration should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">url.rewrite = (
	&quot;^/(.*)\.(.+)$&quot; =&gt; &quot;$0&quot;,
	&quot;^/(.+)/?$&quot; =&gt; &quot;/index.php/$1&quot;
)</pre></div></div>

<p>As I noted before (the second problem), there is no equivalent to <code>.htaccess</code> files in Lighttpd. So this configuration has to go directly into the main configuration file in <code>/etc/lighttpd/lighttpd.conf</code> (or where it exists in your server). Make sure you&#8217;ve enabled <code>mod_rewrite</code>, as this is required. You can enable it by putting the following line some where above the <code.url.rewrite</code> block.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">server.modules += (&quot;mod_rewrite&quot;)</pre></div></div>

<p>If you have multiple sites hosted, you should use include the <code>url.rewrite</code> block inside a conditional statement. For example my configuration looks like this</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$HTTP[&quot;host&quot;] =~ &quot;(www.)?guyrutenberg.com&quot; {
	url.rewrite = (
		&quot;^/(.*)\.(.+)$&quot; =&gt; &quot;$0&quot;,
		&quot;^/(.+)/?$&quot; =&gt; &quot;/index.php/$1&quot;
	)
&nbsp;
	[...other unrelated configurations...]
}</pre></div></div>

<p>And I've enabled the <code>mod_rewrite</code> at the top of the <code>/etc/lighttpd/lighttpd.conf</code> file.</p>
<p>This workaround works well, as you can read this post now. If you run into problems, or have any question about why or how I did soemthing, don't hesitate to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guyrutenberg.com/2008/05/24/clean-urls-permalinks-for-wordpress-on-lighttpd/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.757 seconds -->
