TutorialLighttpdAndPHP » History » Revision 18
« Previous |
Revision 18/91
(diff)
| Next »
silverjam, 2006-02-17 12:17
= Setting up PHP with Lighttpd =
Introduction
Lighttpd supports PHP through both CGI and FastCGI. As the name suggests, FastCGI is preferable.
PerformanceIn all our tests it has shown better performance than Apache 1.3.x + mod_php4. See http://www.lighttpd.net/benchmark/ for the results.
Does it support Code-Caches like APC, TurckMM and friends?YES! Even if their docs say they do not work in CGI. Under lighttpd, PHP is usually run as FastCGI which supports those code caches like mod_php4 in Apache.
- http://pear.php.net/apc
- http://eaccelerator.net/ (Successor of Turck mmCache)
(more to add)
You might be interested in reading the [http://sourceforge.net/forum/forum.php?thread_id=1205624&forum_id=416741 Support for FASTCGI mode?] thread from eAccelerator Open Discussion Forum.
= Installation =
'''Startingpoint:''' Lighttpd is already [wiki:TutorialInstallation installed and working]
First of all you need a PHP which is providing FastCGI support. Depending on yourdistribution you might already have it: === ArchLinux ===
Read http://wiki.archlinux.org/index.php/Fastcgi_and_lighttpd === MeawNIX === {{{
- cd /pkg
- milk install php.meaw
}}} === FreeBSD === {{{
$ cd /usr/ports/www/php-cgi
$ make install clean
}}} === Gentoo ===
Add the USE flag 'fastcgi' to compile php with fastcgi support. {{{ - emerge php-cgi
}}} === Debian ===
Debian provides (at least in Sarge) a fastcgi enabled version - though it's called php4-cgi. {{{ - apt-get install php4-cgi
}}} === Others ===
Download a source tar-ball from http://www.php.net/ and configure it with at least this settings: {{{
$ ./configure \
--enable-fastcgi \
--enable-discard-path \
--enable-force-redirect
}}}
If you want to have the same PHP as you are using in a mod_php configuration somewhere else call {{{
}}} - copy the configure options from the output of the script
- remove the ``--with-apxs`` and ``--with-apxs2`` options
- add the three options from above.
Build PHP now by callings ``make`` and ``make install`` and see if you can find a php binary which is responding: {{{
$ php -v
PHP 5.0.3 (cgi-fcgi) (built: Dec 21 2004 12:59:18)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
with eAccelerator v0.9.3, Copyright (c) 2004-2005 eAccelerator, by eAccelerator
}}}
or something like this. The ``(cgi-fcgi)`` is the important part. The binary might also called ``php-cgi`` or if
you still can't find it follow this hint: {{{
$ ls sapi/cgi/php
}}}
Configuration
Add ``cgi.fix_pathinfo = 1`` to you ``php.ini`` and add this basic section to you ``lighttpd.conf``: {{{
fastcgi.server = ( ".php" => ((
"bin-path" => "/path/to/php-cgi",
"socket" => "/tmp/php.socket",
)))
}}}
A little bit more advance is this setting which tries the tune some more options. If you need PATH_INFO the broken-scriptfilename is
for you. {{{
fastcgi.server = ( ".php" => ((
"bin-path" => "/path/to/php-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 2,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)))
}}}
Please read the configuration section for more background * http://www.lighttpd.net/documentation/configuration.html * http://www.lighttpd.net/documentation/fastcgi.html
and use
http://trac.lighttpd.net/trac/file/branches/lighttpd-1.3.x/doc/lighttpd.conf
as starting point for the configuration.
Updated by silverjam about 19 years ago · 91 revisions