On The Web by Ircmaxell
GNU/GPL PageCache Joomla! APC php5 Lighttpd! Redhat
Home arrow Articles arrow Lighttpd and Joomla - A How To
Tuesday, 06 January 2009
 
 
Featured Site
Main Menu
Home
Articles
Services
Portfolio
Version Information
Bug Tracker
F.A.Q.
Downloads
Forum
Contact Us
Text Link Ads
Latest Version
Feed Icon Page Cache 1.0.8 stable
Release Date: 2007-06-11
Donate!
Login
Syndicate
Lighttpd and Joomla - A How To
User Rating: / 0
PoorBest 
Written by ircmaxell   
Sunday, 29 April 2007

    If you read my other article about Lighttpd, you may be wondering how to set up a server to use Lighttpd instead of Apache.  There are really two ways to set Lighttpd up.  You can use is as a proxy to Apache (and let apache deal with dynamic pages), or use PHP as FastCGI, which is just as fast, and even more reliable.  To see what a difference Lighttpd made check this out...  The spikes are the maximum amount of page views with my server running at its resouce limit!

 

Alexa Traffic Change
 

 

     When you look at that graph, you may be wondering what that is.  That graph is pulled from Alexa's Page Views tab.  I can tell you that during every spike you see, my server was running at its limit, and could not handle any more traffic.  Also, the only change I made in March, was switching over to Lighttpd.  Still interested?  Read on... 

Installing Lighttpd

    No matter how you want to set Lighttpd up (as a proxy, or with FastCGI), you need to install Lighttpd first.  To make life easier, I have found that you need to use LUA to allow for SEF URL's when using FastCGI, so lets just install it anyway.  The first step is downloading the source for LUA from http://www.lua.org.  Then install the latest version of LUA using ./configure, make, and make install.  Once LUA is installed, locate the path to lua.pc.  Now, download Lighttpd from http://www.lighttpd.net.  Extract Lighttpd, and go into the extracted directory.  There, run the following commands (replace path/to/lua with he path to lua.pc WITHOUT the file name):

  • ./configure --with-lua PKG_CONFIG_PATH=/path/to/lua/
  • sudu
  • make
  • make install

 

 

 

    That's it.  Lighttpd is now installed on your machine.  Before we can start it, we need to set up a configuration file.  

 Configuration

    Ok, locate the default configuration file for Lighttpd (on my install, lighttpd.conf was located in /etc/lighttpd).  Here are my recommended settings (where changes should be made):

 server.modules              = (
                                "mod_rewrite",
                                "mod_alias",
                                "mod_access",
                                "mod_auth",
                                "mod_status",
                                "mod_fastcgi",
                                "mod_proxy",
                                "mod_evhost",
                                "mod_accesslog",
                                "mod_magnet" )

url.rewrite-once = ( "^(.*)mosConfig_(.*)$" => "/403.php",
                                   "^base64_encode.*\(.*\)" => "/403.php" ,
                                   "(\<|%3C).*script.*(\<|%3E)" => "/403.php" ,
                                   "GLOBALS(=|\[|\%[0-9A-Z]{0,2})" => "/403.php" ,
                                   "_REQUEST(=|\[|\%[0-9A-Z]{0,2})" => "/403.php")

evhost.path-pattern        = "/home/www/%0/public_html/"   -- (this will make the home directory for www.test.com to /home/www/test.com/public_html... You can symlink that to your real directory)

Lighttpd as a Proxy

    Add these lines to your config (substituting for your domain name)

$HTTP["host"] =~ "myhost\.com" {
$HTTP["url"] =~ "^.*(html|php|cgi|/|\?|\?.*)$" {
proxy.server  = ("" => ( (
                 "host" => "127.0.0.1",
                 "port" => 8080 ) ) )
}
}

    The only change you'll really need to make to Apache is changing the port it runs on.  Change the port number to 8080.  Restart Apache, then start up Lighttpd.  That's all you need to do!  From then on, Lighttpd will be running your front end, with Apache running the back end.

Lighttpd Standalone!

       Well, from here on out, you need to do a few more things.  The first thing you need to do is download PHP and install PHP as FastCGI.  For more information about installing PHP for Lighttpd, check out this article.  Once PHP is installed, add these lines to allow for SEF URL's.  

Add these lines to your config (substituting for your domain name)

$HTTP["host"] =~ "engineeringonline\.org" {
$HTTP["url"] =~ "^.*(html|php|/).*$" {
magnet.attract-physical-path-to = ("/etc/lighttpd/joomla.lua")
}

    Now, you need to make a file called joomla.lua in that directory.  Basically, this file will do what .htaccess does for Apache with modRewrite.  Here's what you want your joomla.lua file to look like:

if (not lighty.stat(lighty.env["physical.path"])) then
        lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. "index.php"
end

    Now, once you have Lighttpd configured, you can stop Apache, and start up Lighttpd.  That's all you need to do to start serving pages efficiently.

A word on performance

    Right out of the box, Lighttpd blew Apache away in terms of throughput.  The problem with it is that it uses a LOT of CPU power.   Durring the past high traffic event, my server was averaging around 50 hits/second while using 100% of dual - dual core Xeons.  Then I came across two directives, server.event-handler and server.network-backend.  You will have to set these based on your OS, as seen here , but what a difference.  Once I restarted Lighttpd, I saw average traffic jump to over 125 hits/second, with a CPU time of 25% and under.  What a difference!  The switch to Lighttpd can be a lot of work, and a headache at times, but it's WELL worth it for speed and performance!

Trackback(0)
Comments (8)Add Comment
Good work - one question
written by Adam, September 12, 2008
Hey anthony, I found out that someone copied/pasted your work and claimed it as his own. http://xpcpro.singular-cy.com/...4&Itemid=1
Anyhow, I am testing lighttpd on my servers with Joomla but I get a problem with the server's session.save_path when I am trying to install Joomla. I tried 4-5 solutions that I found but still, I get the error
Sure it does...
written by ircmaxell, November 07, 2007
It's simple. server.error-handler-404 doesn't run php properly. I tried it that way first, and some pages wound up failing (because of improper parsing of $_GET variables if I remember correctly). Using lua lets it send 404's just fine... error-handler-404 doesn't let you send 404's prior to 1.4.17 http://trac.lighttpd.net/trac/...404Details... Not to mention, that Lua is a much slicker way of dealing with it (It uses the cached stat call from Lighttpd to check the file, so there's no extra disk seeks)... If you want to talk about it more, feel free to post to the forums at http://www.joomlaperformance.com
404 handler
written by waleed gadelkareem, November 07, 2007
I wonder why you're using lua instead of
server.error-handler-404 = "/index.php"
it doesn't let lighty send any 404 headers to browser either
Thank U
written by Anish T S, June 08, 2007
Its working fine...
...
written by ircmaxell, May 03, 2007
Yeah, that should work... Lets take this to the forums. Paste your lighttpd config file in a new topic (use the Lounge).
Question about the port number.. .
written by linuxpenguin, May 02, 2007
I hate to ask. . . but is there anything magical about port 8080 that I can't use another port?

For the testing, I set up lighttpd to use port 81 and kept Apache at port 80. (I was testing it by connecting through the LAN by typing in "http://192.168.0.120:81"* in Firefox.) My impression is that this should work, at least for local PCs until I'm done testing and ready to switch my whole site to lighttpd.

*That's not my server's actual IP, I just made one up for an example.
Re...
written by ircmaxell, May 02, 2007
It's not sending the request back to apache. There are two things you need to do. Make sure this line is in there
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
And make sure Apache is working on port 8080. Make a post in the forums for more help!
...
written by linuxpenguin, May 02, 2007
I am trying to do the proxy but, for example when I go to my PHP pages, I'm getting a download dialog! Any ideas?

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security code
Write the displayed characters


busy
Last Updated ( Sunday, 29 April 2007 )
 
< Prev   Next >
Debt Consolidation - Arizona Pools - Internet Marketing - Loans
 
Top! Top!
Generated in 0.52292490005493 Seconds