Installing Magento on Lighttpd 1.4.X via FastCGI

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

The following guide outlines the implementation of Magento on a Lighttpd 1.4.X server via FastCGI. This is somewhat different than a 1.5.X installation which requires the use of mod_proxy_core and mod_proxy_backend_fastcgi; please message PremierWeb for 1.5.X guidance.

First, PHP should be compiled in FastCGI mode with the following additional configuration parameters, omitting ‘–with-apxs2=’ (if it exists):

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

Lighttpd is configured and installed from source:

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

An example of Lighttpd compiled from source with SSL and the Fam/Gamin stat-cache-engine. The library path on x86_64 servers is ‘/usr/lib64/openssl’ :

  1.    $ yum install gamin-devel
  2.    $ yum install openssl
  3.    $ ./configure --prefix=/usr
  4.        --with-bzip2
  5.        --with-openssl
  6.        --with-openssl-includes=/usr/include/openssl
  7.        --with-openssl-libs=/usr/lib/openssl
  8.        --with-fam

Lighttpd does not support .htaccess (Apache directives), thus a standard Magento installation will not work. Never fear, for a few simple server configuration changes makes it all better. Essentially, this forwards all non-existent urls (404s) to index.php for routing. Simple.

  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. }

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 PHP directives directly into php.ini and not using htscanner.

Since Lighttpd does not properly parse the query string for requests, add the following to the top of Magento’s index.php to get the list/grid view and admin areas working. This modification should also work for almost any PHP script the parses query strings.

  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 partial 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 Lighttpd modules within your Lighttpd configuration file (mod_fastcgi, mod_compress, mod_rewrite, mod_expire, etc). Mod_expire should be listed first to prevent issues. Note: we do not run Lighttpd 1.4 extensively, so this may not be an ideal configuration as older browsers have issues with compression:

  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.         # NOTE: Older browsers have issues with compression!
  14.         compress.allowed-encodings = ("bzip2", "gzip", "deflate")
  15.         compress.cache-dir = "/<PATH_TO_MAGENTO>/var/lighttpd/"
  16.         compress.filetype = ("text/plain", "text/html")
  17.        
  18.         # Fooman Speedster rewrite
  19.         url.rewrite-once = ( "^(/index.php)?/minify/([^/]+)(/.*.(js|css))$" => "/lib/minify/m.php?f=$3&$2" )
  20. }
  21.  
  22. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  23. fastcgi.server = ( ".php" => ((
  24.     "bin-path" => "/<PATH TO PHP-CGI>/php-cgi",
  25.     "socket" => "/tmp/php.socket",
  26.     # 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
  27.     "max-procs" => 1,
  28.     "bin-environment" => (
  29.         "PHP_FCGI_CHILDREN" => "5",
  30.         "PHP_FCGI_MAX_REQUESTS" => "5000"
  31.     ),
  32.     "bin-copy-environment" => (
  33.         "PATH", "SHELL", "USER"
  34.     ),
  35.     "broken-scriptfilename" => "enable"
  36.     ))
  37. )
  38.  
  39. // make sure IE doesn't die on keep-alives
  40. $HTTP["useragent"] =~ "MSIE" {
  41.   server.max-keep-alive-requests = 0
  42. }



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs