System & Software Specification
===============================
- Debian GNU/Linux Sarge (stable)
- Kernel 2.6.8-2-686
- Lighttpd 1.4.8
- PHP 4.3.10
- Oracle Instant Client (basic, devel & sqlplus) 10.2.0.1

About Lighttpd
==============
Security, speed, compliance, and flexibility–all of these describe LightTPD which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. With a small memory footprint compared to other web-servers, effective management of the cpu-load, and advanced feature set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) LightTPD is the perfect solution for every server that is suffering load problems. And best of all it’s Open Source licensed under the revised BSD license.
(http://www.lighttpd.net)

Lighttpd FastCGI Interface
==========================
Lighttpd provides an interface to a external programs that support the FastCGI interface. The FastCGI Interface is defined by http://www.fastcgi.com/ and is a platform-independent and server independent interface between a web-application and a webserver.
This means that FastCGI programs that run with the Apache Webserver will run seamlessly with lighttpd and vice versa.

FastCGI is removes a lot of the limitations of CGI programs. CGI programs have the problem that they have to be restarted by the webserver for every request which leads to really bad performance values.

FastCGI removes this limitation by keeping the process running and handling the requests by this always running process. This removes the time used for the fork() and the overall startup and cleanup time which is necessary to create and destroy a process.

While CGI programs communicate to the server over pipes, FastCGI processes use Unix-Domain-Sockets or TCP/IP to talk with the webserver. This gives you the second advantage over simple CGI programs: FastCGI don’t have to run on the Webserver itself but everywhere in the network.

Lighttpd takes it a little bit further by providing a internal FastCGI load-balancer which can be used to balance the load over multiple FastCGI Servers. In contrast to other solutions only the FastCGI process has to be on the cluster and not the whole webserver. That gives the FastCGI process more resources than a e.g. load-balancer+apache+mod_php solution.

If you compare FastCGI against a apache+mod_php solution you should note that FastCGI provides additional security as the FastCGI process can be run under different permissions that the webserver and can also live a chroot which might be different than the one the webserver is running in.
(http://www.lighttpd.net)

Installing Lighttpd
===================
You can not find lighttpd package from Official Debian repository because of its incompatibility license against GPL (lighttpd use revised BSD license). You can get it from another Debian repository like below. So put one of these lines to your sources.list.
deb http://apt.utsl.gen.nz/debian stable all
deb http://debian.bougyman.com unstable main

Download server packages list to your box :
# apt-get update

Now you ready to install lighttpd :
# apt-get install lighttpd

Preparing PHP as a FastCGI Program with Oracle Support
======================================================
PHP4 official package from Debian, by default doesn’t have Oracle support. So, it must be rebuilt from source. Oracle Instant Client (OIC) also needed in this process. So you must install it first. You can download OIC from oracle technology network site : http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html. Get RPM package and then convert it to DEB with alien. Now, you can install it using dpkg. You need to do this as root.
# dpkg -i oracle-instantclient-basic_10.2.0.1-2_i386.deb
# dpkg -i oracle-instantclient-devel_10.2.0.1-2_i386.deb
# dpkg -i oracle-instantclient-sqlplus_10.2.0.1-2_i386.deb
Three steps above will install OIC on /usr/lib/oracle.

Create tnsnames.ora if needed by your application. For quickstart, you can simply adopt from example lines below :
—————————————————————————–
BILLPM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.23.154.8)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = billpm)
)
)
—————————————————————————–

You need to tell the system where OIC library can be found. In order to do this, add this line below to file /etc/ld.so.conf :
—————————————————————————–
/usr/lib/oracle/10.2.0.1/client/lib
—————————————————————————–
Then, tell ld to update its cache :
# ldconfig

Create new environment variable which may be needed by your application to connect to Oracle via OIC library. Add these variables to /etc/profile as global profile for all users.
—————————————————————————–
LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.1/client/lib:$LD_LIBRARY_PATH
TNS_ADMIN=/usr/lib/oracle
export LD_LIBRARY_PATH TNS_ADMIN
—————————————————————————–

Now you can continue your step to enable PHP as FastCGI program. In order to do this, you must rebuild PHP from source. Get the source using apt-get and save it anywhere you want. I like to do this in /usr/src.
# cd /usr/src
# apt-get source php4
You need libssl-dev package also for this. So install it :
# apt-get install libssl-dev

If you already have a working PHP installation, you can create simple PHP script contains :
< ? phpinfo(); ?>
Browse that script via your web browser. You can get the configure parameters on top section of the web page. Use that configure parameters as the base for the compilation. You have to remove all occurences of –with-apxs, –with-apxs2, –with-config-file-path=/etc/php4/apache2 and the like which would build PHP with Apache support. Then add parameters below for configure script :
–enable-fastcgi
–enable-force-cgi-redirect
–with-oci8-instant-client
–with-config-file-path=/etc/php4/lighttpd
Now, the complete version of your configure parameters maybe like below :
–enable-fastcgi –enable-force-cgi-redirect –with-oci8-instant-client –prefix=/usr –with-config-file-path=/etc/php4/lighttpd –enable-memory-limit –disable-debug –with-regex=php –disable-rpath –disable-static –with-pic –with-layout=GNU –with-pear=/usr/share/php –enable-calendar –enable-sysvsem –enable-sysvshm –enable-sysvmsg –enable-track-vars –enable-trans-sid –enable-bcmath –with-bz2 –enable-ctype –with-db4 –with-iconv –enable-exif –enable-filepro –enable-ftp –with-gettext –enable-mbstring –with-pcre-regex=/usr –enable-shmop –enable-sockets –enable-wddx –disable-xml –with-expat-dir=/usr –with-xmlrpc –enable-yp –with-zlib –without-pgsql –with-kerberos=/usr –with-openssl=/usr –with-zip=/usr –enable-dbx –with-mime-magic=/usr/share/misc/file/magic.mime –with-exec-dir=/usr/lib/php4/libexec –without-mm –without-mysql –without-sybase-ct

Run buildconf on top of PHP source directory with –force to force regenerate config :
# ./builconf –force
# rm -f *.cache
# ./configure –enable-fastcgi –enable-force-cgi-redirect –with-oci8-instant-client –prefix=/usr –with-config-file-path=/etc/php4/lighttpd –enable-memory-limit –disable-debug –with-regex=php –disable-rpath –disable-static –with-pic –with-layout=GNU –with-pear=/usr/share/php –enable-calendar –enable-sysvsem –enable-sysvshm –enable-sysvmsg –enable-track-vars –enable-trans-sid –enable-bcmath –with-bz2 –enable-ctype –with-db4 –with-iconv –enable-exif –enable-filepro –enable-ftp –with-gettext –enable-mbstring –with-pcre-regex=/usr –enable-shmop –enable-sockets –enable-wddx –disable-xml –with-expat-dir=/usr –with-xmlrpc –enable-yp –with-zlib –without-pgsql –with-kerberos=/usr –with-openssl=/usr –with-zip=/usr –enable-dbx –with-mime-magic=/usr/share/misc/file/magic.mime –with-exec-dir=/usr/lib/php4/libexec –without-mm –without-mysql –without-sybase-ct

And now you can start compiling :
# make
If nothing wrong happen, you can simply install new PHP version :
# make install

Play with Configuration
=======================
Modify file /etc/lighttpd/lighttpd.conf in section server.modules and activate fastcgi module (”mod_fastcgi”). If you want to use PATH_INFO and PHP_SELF in you PHP scripts you have to configure php and lighttpd. The /etc/php4/lighttpd/php.ini (you can copy php.ini if it not exist there, from /etc/php4/apache2 if you have a working installation before) needs the option:

cgi.fix_pathinfo = 1

and the option broken-scriptfilename in your /etc/lighttpd/lighttpd.conf at fastcgi.server section :
—————————————————————————–
fastcgi.server = ( “.php” =>
( “localhost” =>
( “socket” => “/tmp/php-fastcgi.socket”,
“bin-path” => “/usr/bin/php”,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “16″,
“PHP_FCGI_MAX_REQUESTS” => “10000″
),
“bin-copy-environment” => (
“PATH”, “SHELL”, “USER”
),
“broken-scriptfilename” => “enable”
)
)
)
—————————————————————————–

Why this ? the cgi.fix_pathinfo = 0 would give you a working PATH_INFO but no PHP_SELF. If you enable it, it turns around. To fix the PATH_INFO –enable-discard-path needs a SCRIPT_FILENAME which is against the CGI spec, a broken-scriptfilename. With cgi.fix_pathinfo = 1 in php.ini and broken-scriptfilename => “enable” you get both.

End of Work
===========
If you already running apache or apache2 before, you have to shutdown it first :
# /etc/init.d/apache stop
or
# /etc/init.d/apache2 stop

Then start lighttpd :
# /etc/init.d/lighttpd start

Well …everything has been done completely !