Join over 10,000 ecommerce enthusiasts who receive free updates
Get email updates
Build A "Smarter"
Magento Store
Magik Extra Fees Create unlimited number & types of extra fees and charges to drive increased revenue per order.
$199  $99

Most popular posts

How To Install Magento On Lighttpd 1.4.X With FastCGI

 

Magento on Lighttpd 1.4.x

When speed is one of the primary criteria for web applications & stores, you can’t simply rely on non-configured server setup. Apache is heavy unless you use the real power of it. Why not use some lightweight web servers like Ngnix or Lighttpd version 1.4.x. Although, these web servers are pretty light weight still they are powerful enough to cater large audience yet keep very small memory footprint.

What is Lighttpd

Lighttpd is a lightweight web server which is secure, designed and optimized for high performance environments. Lighttpd is effective in management of the cpu-load, with awesome feature set i.e FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more. In simple words Lighttpd is the perfect solution for every server that is suffering load problems.

Lighttpd Requirements for Magento

One of the primary requirements for Lighttpd is that PHP needs to be compiled in FastCGI mode. Moreover, followingn configuration parameters needs to be set omitting –with-apxs2= (if it exists): .

1
2
3
    '--enable-fastcgi'
    '--enable-discard-path'
    '--enable-force-cgi-redirect'

Lighttpd needs to sit on source and configured like this

1
2
3
      $ ./configure --prefix=/usr --with-bzip2
      $ ./make
      $ ./make install

Those who rely heavily on .htaccess should note that Lighttpd does not support it. So standard Magento installation will not work on Lighttpd. Fortunately, you can make certain changes in server configuration to run Magento on Lighttpd. Forwarding all non-existing URLs to index.php is easy. Just take a look at the following code:

1
2
3
4
5
    $HTTP["host"] =~ "^(www.)?mysite.com$" {
            server.name     = "www.mysite.com"
            server.document-root  = "/var/www/mysite.com/"
            server.error-handler-404 = "/index.php"
    }

htscanner PHP extension needs to be added to your php.ini which essentially will override default PHP configuration parameters i.e. max_execution_time or memory_limit etc. Since, many developers have faced issues configuring htscanner with php.ini you can safely move .htaccess directives into your php.ini file (i am assuming you not running other non-Magento sites on the same server).

On other note, Lighttpd ignores query strings in requests you need to make additional modifications in your Magento’s index.php file.

1
2
3
4
5
6
7
8
9
10
11
    if(empty($_GET) && FALSE !== strpos($_SERVER['REQUEST_URI'], '?'))
    {
        $tmp = parse_url($_SERVER['REQUEST_URI']);
        $_SERVER['QUERY_STRING'] = $tmp['query'];
        unset($tmp);
        // populate $_GET array
        parse_str($_SERVER['QUERY_STRING'], $_GET);
        // populate $_REQUEST array
        foreach ($_GET as $key => $val)
            $_REQUEST[$key] = $val;
    }

Look at the following Lighttpd configuration file and ensure that you have the pre-requisite Lighttpd modules are installed and loaded i.e. mod_fastcgi, mod_compress, mod_rewrite, mod_expire. To prevent any issue just list Mod_expire at the top.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    $HTTP["host"] =~ "^(www.)?mysite.com$" {
            server.name     = "www.mysite.com"
            server.document-root  = "/var/www/mysite.com/"
            server.error-handler-404 = "/index.php"
            index-file.names            = ( "index.php", "index.html" )
 
            # Content-Expiration / Not-Modified Headers
            $HTTP["url"] =~ "^/(media|skin|js)/" {
                expire.url = ( "" => "access 1 years" )
            }
 
 
    }
 
    static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
    fastcgi.server = ( ".php" => ((
        "bin-path" => "/<PATH TO PHP-CGI>/php-cgi",
        "socket" => "/tmp/php.socket",
        # If using APC, XCache, etc, don't set this higher than 1; doing so will waste RAM duplicating the memory caching spaces; instead increase the PHP_FCGI_CHILDREN count
        "max-procs" => 1,
        "bin-environment" => (
            "PHP_FCGI_CHILDREN" => "5",
            "PHP_FCGI_MAX_REQUESTS" => "5000"
        ),
        "bin-copy-environment" => (
            "PATH", "SHELL", "USER"
        ),
        "broken-scriptfilename" => "enable"
        ))
    )
 
    // make sure IE doesn't die on keep-alives
    $HTTP["useragent"] =~ "MSIE" {
      server.max-keep-alive-requests = 0
    }

You may also like

How To Configure Magento On Lightweight Ningx Web Server

As per your setup there may be some additional tasks which you may need to perform to make Magento run smoothly on Lighttpd 1.4.x. Please leave us a comment and share your experiences with us.

 
Enjoyed this Post?
Then you can follow us here:

Subscribe to RSS
Follow us on Twitter
Follow us on Facebook

Ashish Nayyar

Chief Product Officer & Architect. MagikCommerce.com

Build A "Smarter" Magento Store
Magik Extra Fees Magik Extra Fees is the #1 extention for creating unlimited number & types of extra fees and charges to drive increased revenue per order.
  • Extra Fee for Products
  • Extra Fee for Categories
  • Extra Fee for Shipping
  • Multiple Additional Charges
$199  $99