Authentication with lighttpd on CentOS

To enable authentication in lighttpd is easy. We can follow this reference to set up a functional environment: Module mod_auth – Using Authentication. However, it is a tragedy in my new CentOS 6 box with lighttpd 1.4.31, due to the separated configuration files.

After I enable mod_auth in modules.conf, set up my authentication functions in conf.d/auth.conf and restart the service, the function seems no work. The issue is on a lost include command in main configuration file – lighttpd.conf, then configuration will not be loaded.

The solution is adding include "conf.d/auth.conf" into lighttpd.conf and everything works fine. What a stupid problem. Enjoy it. 🙂

Pretty permalinks and search urls for WordPress on lighttpd

To make a blog Search Engine (SE) friendly, one feasible way is to make all requested URIs permanently. It is easier for Apache web service than lighttpd, because there are more resources and technical notes on the Net. This post is about how to set up the pretty permalinks and to introduce a partial solution for the unfriendly search URIs for WordPress 3.3 on lighttpd.

First, for pretty permalinks, the reference is Using Permalinks. I want to use the Day and Name format as an SEO friendly URI. Unfortunately, except for Apache’s rewrite rules, there always exist index.php as a bridge for processing. Then the format seems


. To eliminate the bridge string, we can still use Custom Structure and set up rewrite ules on lighttpd.

There are ways to write proper rewrite rules within lighttpd. Based on the references: lighttpd rewrite rule for wordpress 3 and other resources from Google (keywords: lighttpd, wordpress, permalinks), the final configuration is very simple. We only need to add

server.error-handler-404 = "/index.php"

into lighttpd. This rule indicate that the request will be passed into the index page when the page (or URI) is not exist physically. It is depend on the truth that almost all of the requests are handled by the index page (like the posts, pages, feeds).

Second, to fix the unfriendly search URIs, we can use plugins or to add a redirect rule into lighttpd. The search URIs are formatted as


and we want to replace it into


. It is SEO friendly and is VERY IMPORTANT when we use 404 handler as rewrite rule. For example, if there are more than one page for the search term T, the first result page’s URI is


where the second result page is


. Because the request of page 2 is not exist physically, the request will be passed into index.php and the search term (?s=T) will be ignored. The reason for why search will be ignored remains unknown.

To make the search and paged view work, we can set a redirect rule to fix it by adding

url.redirect = ( "^/\?s=(.*)" => "/search/$1" )

into configuration on lighttpd.

Finally, the URIs are all search engine friendly and work correctness. Enjoy it. 🙂

Use PHP 5.3 and Lighttpd on CentOS 5

The default packages built-in my CentOS box are Apache HTTP Server 2.2 and PHP 5.1. If we want to replace them with Lighttpd and PHP 5.3, we need some modification to the system. This post is an annotation of the procedure.

1. The Lighttpd package is not provided by official repository. We need to add the support via EPEL x86_64 repository (I’m using 64-bit CentOS): # rpm -Uvh

2. After update, we can install lighttpd: # yum install lighttpd lighttpd-fastcgi

3. Update PHP from 5.1 to 5.3, first we need to list all installed 5.1 packages: # rpm -qa | grep php and then to remove them all.

4. Install the PHP53 and related packages we need: # yum install php php-cli php-mysql.
Note: The PHP53 packages also install httpd packages which we cannot removed individually.

5. Enable fastcgi support for Lighttpd in /etc/lighttpd/lighttpd.conf as this reference: lighttpd + FastCGI in CentOS.
Note: The cgi.fix_pathinfo=1 configure is installed by default in /etc/php.d/lighttpd.ini and we can skip to set it up.

6. Finally, the most important step for some application use sessions. We need to set up the permissions by: # chown -R root:lighttpd /var/lib/php because the web server we use is not httpd. If we do not set this, some application like phpMyAdmin we raise error while login.

7. Restart the Lighttpd and enjoy it. 🙂