Installing Magento on Lighttpd 1.4.X via FastCGI

Last modified by PremierWeb on Thu, June 24, 2010 15:21
Source|Old Revisions  

This is an old revision of the document!


If you are familiar with Lighttpd, it does not support .htaccess, thus a standard Magento installation will not work. Never fear, for a few simple server configuration changes makes it all better.

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

Essentially, this forwards all non-existent urls to index.php for routing. Simple.

Next, install the htscanner PHP extension and add it to your php.ini to properly override the PHP configuration parameters (memory_limit, max_execution_time, etc.) specified in Magento’s .htaccess files. Note: As of this writing, we were experiencing issues with htscanner properly setting php.ini values; you may want to consider moving Magento’s .htaccess settings directly into php.ini and not using htscanner.

Since Lighttpd does not properly parse the query string, add the following to the top of index.php to get the list/grid view and admin areas working.

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

Here is an example of a Lighttpd 1.4x Fast-CGI configuration, including the use of the Fooman Speedster Magento Extension. Be sure to enable the pre-requisite modules within your Lighttpd configuration file (mod_fastcgi, mod_compress, mod_rewrite, mod_expire, etc):

  1. $HTTP["host"] =~ "^(www.)?example.com$" {
  2.         server.name     = "www.example.com"
  3.         server.document-root  = "/var/www/example.com/magento/"
  4.         server.error-handler-404 = "/index.php"
  5.         index-file.names            = ( "index.php", "index.html" )
  6.        
  7.         // Content-Expiration / Not-Modified Headers
  8.         $HTTP["url"] =~ "^/(media|skin|js)/" {
  9.             expire.url = ( "" => "access 1 years" )
  10.         }
  11.  
  12.         // compress static files to Magento's /var directory
  13.         compress.allowed-encodings = ("bzip2", "gzip", "deflate")
  14.         compress.cache-dir = "/<PATH_TO_MAGENTO>/var/lighttpd/"
  15.         compress.filetype = ("text/plain", "text/html")
  16.        
  17.         url.rewrite-once = ( "^(/index.php)?/minify/([^/]+)(/.*.(js|css))$" => "/lib/minify/m.php?f=$3&$2" )
  18. }
  19.  
  20. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  21. fastcgi.server = ( ".php" => ((
  22.     "bin-path" => "/usr/local/bin/php-cgi",
  23.     "socket" => "/tmp/php.socket",
  24.     "max-procs" => 1,
  25.     "bin-environment" => (
  26.         "PHP_FCGI_CHILDREN" => "5",
  27.         "PHP_FCGI_MAX_REQUESTS" => "5000"
  28.     ),
  29.     "bin-copy-environment" => (
  30.         "PATH", "SHELL", "USER"
  31.     ),
  32.     "broken-scriptfilename" => "enable"
  33.     ))
  34. )
  35.  
  36. // make sure IE doesn't die
  37. $HTTP["useragent"] =~ "MSIE" {
  38.   server.max-keep-alive-requests = 0
  39. }

We run several Magento sites fully on Lighttpd 1.5.X, which allows the use mod_deflate (mod_compress in Lighttpd 1.4.X doesn’t gzip dynamic PHP pages). Mod_fastcgi is no longer part of Lighttpd 1.5.X, so mod_proxy_backend_fastcgi is utilized instead. As this sort of installation is too complex to detail here, please message me for guidance.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs