TutorialLighttpdAndPHP » History » Revision 35
Revision 34 (Anonymous, 2006-08-02 08:12) → Revision 35/91 (Anonymous, 2006-08-02 22:26)
= Setting up PHP with Lighttpd = == Introduction == Lighttpd supports PHP through both CGI and FastCGI. As the name suggests, FastCGI is preferable. == Performance == In 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 opcode cachers like APC, TurckMM, XCache 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 opcode cachers like mod_php4 in Apache. * http://pear.php.net/apc * http://eaccelerator.net/ (Successor of Turck mmCache) * [/xcache XCache], [/xcache/wiki/GettingSource Installing XCache] (new, well tested, running with FastCGI) (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 your distribution you might already have it: === ArchLinux === Read http://wiki.archlinux.org/index.php/Fastcgi_and_lighttpd === FreeBSD === {{{ #!ShellExample $ cd /usr/ports/www/php-cgi $ make install clean }}} === Gentoo === Make sure the USE flag 'cgi' is enabled. {{{ #!ShellExample $ emerge -pv dev-lang/php }}} If it is not, then add it to make.conf or just to php. {{{ #!ShellExample # echo dev-lang/php cgi >> /etc/portage/package.use }}} Emerge php. {{{ #!ShellExample # emerge dev-lang/php }}} === Debian / Ubuntu === Debian/Ubuntu provides a fastcgi enabled version. {{{ #!ShellExample # apt-get install php4-cgi }}} === DragonFlyBSD === DragonFlyBSD uses pkgsrc to build it's packages. If you don't want IPV6 you need to use the deprecated USE_IPV6=NO. {{{ #!ShellExample # cd /usr/pkgsrc/www/php4 # bmake PKG_OPTIONS.php="fastcgi ssl" PKG_DEFAULT_OPTIONS="fastcgi ssl" install clean }}} === Others === Download a source tar-ball from http://www.php.net/ and configure it with at least this settings: {{{ #!ShellExample $ ./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 {{{ #!php <?php phpinfo(); ?> }}} * 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: {{{ #!ShellExample $ 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 be called ``php-cgi``. so do something like php-cgi -v to see the (cgi-fcgi) banner. {{{ #!ShellExample $ php-cgi -v PHP 4.4.2 (cgi-fcgi) (built: Jul 21 2006 15:45:58) Copyright (c) 1997-2006 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies }}} If you still can't find it follow this hint: {{{ #!ShellExample $ ls sapi/cgi/php }}} == Configuration == Add this line: {{{ cgi.fix_pathinfo = 1 }}} to your you ``php.ini``. And make sure mod_fastcgi is loaded in your ``lighttpd.conf``: loaded: {{{ server.modules = ( "mod_fastcgi", ) }}} Then add this basic section to the same file: 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" ))) }}} If you're using any php opcode cacher, it is important to keep '''"max-procs" => 2''' low (1 or 2), unless you want to eat up so much memory. 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. == Per directory PHP Config == If you're used to use Apache .htaccess files to set PHP options for each directory, see HowToPhpHtaccess : ''When using a cgi version of php (plain old cgi or fast-cgi) apache can't pass any php settings from htaccess files it parses. This can be solved by giving each user it's own php.ini file, but I didn't like that solution. This extension parses these configuration files (in most cases .htaccess) and changes the settings. It will search all directories for a configuration file from the docroot until the directory where the request scripts is found.'' [http://files.zoeloelip.be/htscanner/ Download htscanner]