wesupport

Need help?

Our experts have had an average response time of 13.14 minutes in February 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

LIGHTY :The future in Web servers

by | Nov 23, 2006

Lighttpd is the Web server of choice if the goal is performance. Lighttpd consumes less resources and at the same time is powerful web server. With FastCGI and Xcache as performance boosters, lighttpd is the best solution for any webserver facing high CPU usage. This article is intended to present Lighttpd and few of its enhanced features. The article will give you steps for installing lighttpd in a fresh linux server and to compile php with fastcgi and finally install Xcache.

1. LIGHTTPD

Lighttpd is a secure,fast and very flexible websever that is much faster than apache and much much much more flexible/configurable/secure and its fcgi php support is simply great. It takes care of the cpu load and use very low memory compared to other webserver. Few of its advanced feature-set includes FastCGI,load balancing,protecting docroot,Xcache etc out which we are discussing briefly about fcgi and xcache here.

1.1 Why ‘lighty’?

Light footprint + httpd = LightTPD

You can call him ‘lighty’ if you feel as that is what the lighttpd lovers call .

1.2 Features

Lighttpd has got wide variety of advanced,php support and security features.Few are mentioned below for your knowledge.

Advanced Features:

  • *virtual hosts
  • * virtual directory listings
  • * URL-Rewriting, HTTP-Redirects automatic
  • * expiration of files Large File Support (64bit fileoffsets)
  • * gzip, bzip2 authentication backends:
  • * secure application controlled downloads
  • * Server Side Includes
  • * User Tracking FastCGI, CGI, SSI

PHP-Support:

  • * faster than apache + mod_php4
  • * it can spawn FastCGI processes (necessary for PHP 4.3.x) via FastCGI and CGI interface.
  • * load-balanced FastCGI (one webserver distributes request to multiple PHP-servers via FastCGI)

Security features:

  • * chroot(), set UID, set GID
  • * protecting docroot and
  • * strict HTTP-header parsing

1.3 .Install lighttpd

Download source file :
lighttpd-1.4.11
tar -xzvf lighttpd-1.4.11.tar.gz
cd lighttpd-1.4.11
./configure --enable-fastcgi --prefix=/usr/local/lighttpd-1.4.11
make
make install

Configuring conf file:

mkdir /etc/lighttpd/
cp -rp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/lighttpd.conf

and edit the following section:

server.document-root = "/var/www/html"

server.port = 80
server.username = "lighttpd"
server.groupname = "lighttpd"
server.bind                = "192.168.1.77"
server.tag ="lighttpd"

server.errorlog            = "/var/log/lighttpd/error.log"
accesslog.filename         = "/var/log/lighttpd/access.log"

Restart lighttpd:

/etc/rc.d/init.d/lightpd restart

2. FAST-CGI:

2.1 What is Fast-cgi?

F-cgi stands for Fast Common Gateway Interface. FastCGI is an interface which helps to connect webservers with new application where these applications can be static or dynamic in nature. Dynamic application allows us to deliver products, services, and messages whose shape varies according to the customer requirements.

2.2 Features:

  • * Performance:F-cgi can be reused to handle multiple request without creating new processes for each request.
  • * Simplicity:Can be easily migrated from existing CGI.
  • * Language independence: FCGI applications can be written in nearly any language
  • * Process isolation:A buggy FastCGI application cannot crash or corrupt the core server or other applications neither can they steal any secrets from the webserver.
  • * Architecture independence:Any webserver can include fcgi irrespective of any particular server architecture.
  • * Distributed computing:Fcgi has the ability to run remotely which helps in managing external websites and load distribution.

2.3 Compile PHP5 with Fast-cgi support

Download source file :

wget http://museum.php.net/php5/php-5.0.5.tar.gz
tar -xzf php-5.0.5.tar.gz
cd php-5.0.5
./configure --prefix=/usr/local/php5-fcgi --enable-fastcgi
--enable-force-cgi-redirect --disable-cli --enable-memory-limit
--with-layout=GNU --with-regex=php
make
make install

Edit lighttpd.conf file:

Now add the following to lightpd.conf

fastcgi.server = ( ".php" =>
                   ( "localhost" =>
                     ( "socket" => "/tmp/php5-fcgi.socket",
                       "bin-path" => "/usr/local/php5-fcgi/bin/php"
                     )
                   )
                 )

Restart lightpd and you should get the module in phpinfo.php page or should show something like this in command prompt:

PHP 5.0.5 (cgi-fcgi) (built: Oct 15 2006 11:34:04)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.5, Copyright (c)

3. XCACHE

3.1 What is Xcache?

Opcode cache is a tool which helps in eliminating inefficiency found in scripts. Opcode caches are very easy to deploy and that it significantly increases the performance of applications by eliminating the parsing process on every request.

XCache is a fast, stable PHP opcode which can be run in servers under high load.

3.2 Installing Xcache:

Download from the source:

wget http://210.51.190.228/pub/XCache/rc/1.0.3-rc1/xcache-1.0.3-rc1.tar.bz2
bunzip2 xcache-1.0.3-rc1.tar.bz2
cd xcache
mkdir ../xcache-build
cd ../xcache-build
./xcache/configure --enable-xcache --enable-xcache-coverager
make
make install

Edit php.ini file

cat xcache.ini >> /usr/local/lib/php.ini

replace the line in php.ini

:/usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so

with something like this as per the server configuration:

/usr/local/lib/php/extensions/no-debug-non-zts-20041030/xcache.so

Edit the following section:

[xcache]
xcache.size = 64M
xcache.mmap_path = "/tmp/xcache"
xcache.cacher = 1
zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20041030/xcach
e.so" # or
extension="xcache.so"

Restart lightpd and type php -v in the command prompt and should get something as shown below:

PHP 5.0.5 (cgi-fcgi) (built: Oct 15 2006 11:34:04)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.5, Copyright (c) 1998-2004 Zend Technologies
    with XCache v1.0.3-rc1, Copyright (c) 2005-2006,

Conclusion: It seems Apache 2.0.x has performance 50% greater to Apache 1.3.x but lighttpd is still 2-3 times faster.Transfer rate of data for lighttpd is found to be almost 1.5 times that of apache where as lighttpd + fastcgi is found to 25% more faster than apache + mod_php4. Now why not try out and feel for yourself how everything gets faster.

Reference: http://trac.lighttpd.net/xcache/wiki/
http://lighttpd.net
http://in.php.net/



Articles by Sindhu NAbout the author:
Sindhu N works as Tech Support engineer in Bobcares. She primarily works on administering cPanel servers.

0 Comments

Categories

Tags