Note: You are currently viewing documentation for Moodle 3.1. Up-to-date documentation for the latest stable version of Moodle is probably available here: lighttpd.

lighttpd: Difference between revisions

From MoodleDocs
No edit summary
 
(updated to recent Fedora in combination with Moodle 1.9.x requirements)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[http://www.lighttpd.net/ Lighttpd] (aka Lighty) is a lightweight webserver program with a small memory footprint. It is an alternative to Apache and IIS, which is particularly suited to systems which are low on resources, especially RAM. Lighttpd is ideal for people using VPS hosting. Even oh hosts with plenty of resources, Lighty is apparently just as fast as Apache and sometimes faster, so is well worth considering.
[http://www.lighttpd.net/ Lighttpd] (a.k.a. Lighty) is a lightweight webserver with a small memory footprint that works well with PHP accelerators like [http://eaccelerator.net/ eAccelerator] and [http://us2.php.net/apc Alternative PHP Cache (APC)]. It is an alternative to Apache and IIS particularly well suited to systems with low resources, especially RAM -- ideal when using virtual private server (VPS) hosting services. Even on hosts with plenty of resources, Lighty is as fast as Apache if not faster and worth considering.


Installation varies according to your platform, so check the instructions [http://trac.lighttpd.net/trac/wiki/TutorialInstallation here].
Lighttpd meets all the base requirements for Moodle and provides most common webserving features; however, it is not intended to replace Apache feature for feature. If your needs extend further than Moodle, be aware of lighttpd's differences and limitations as well as level of knowledge and support necessary and available. Be certain it meets all of your needs before deploying in a production environment.


You will also need to install php (maybe with an accelerator) as fast-cgi according to [http://trac.lighttpd.net/trac/wiki/TutorialLighttpdAndPHP these] instructions.
Installation varies according to platform, if the following example doesn't apply to your server configuration, check the official instruction page [http://trac.lighttpd.net/trac/wiki/TutorialInstallation here].  You will also need to install PHP (preferably with an accelerator) and FastCGI according to [http://trac.lighttpd.net/trac/wiki/TutorialLighttpdAndPHP these] instructions.
 
===Fedora 9, 10 & 11 Example===
Lighttpd is a part of the official repository and can be installed using yum to meet all of Moodle's base requirements, including the PHP accelerator [http://us2.php.net/apc Alternative PHP Cache (APC)], using the following command.
<pre>
yum install lighttpd lighttpd-fastcgi mysql php php-mysql \
php-pecl-apc php-gd php-mbstring php-xmlrpc php-pdo ;
</pre>
Under the respective sections, edit /etc/lighttpd/lighttpd.conf to point to the Moodle root directory, uncomment the FastCGI module and the ''fastcgi module'' section; be sure the ''bin-path'' points to the PHP FastCGI executable:
<pre>
## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_fastcgi",
## a static document-root example
server.document-root        = "/home/moodle-1.9/"
#### fastcgi module
fastcgi.server            = ( ".php" =>
                              ( "localhost" =>
                                (
                                  "socket" => "/tmp/php-fastcgi.socket",
                                  "bin-path" => "/usr/bin/php-cgi"
                                )
                              )
                            )
</pre>
Client cache control and expiry is very flexible, uncomment the expiration module directive and add the following into /etc/lighttpd/lighttpd.conf for expiry control of common types of static files, change the number of days to meet your needs.
<pre>
## modules to load
# Module load order is important, the mod_expire should be listed before mod_compress when both are active.
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_expire",
## Client cache control section.
# mod_expire - image files expire 2 days after first access
$HTTP["url"] =~ "\.(gif|GIF|jpg|JPG|png|PNG|swf|SWF|ico|ICO)$" {
    expire.url = ( "" => "access 2 days" )
}
# mod_expire - includes expire 1 day after first access
$HTTP["url"] =~ "\.(css|CSS|js|JS)$" {
    expire.url = ( "" => "access 1 days" )
}
# Some versions of lighttpd may require the following directives for full functionality, uncomment if needed.
# etag.use-inode = "enable"
# etag.use-mtime = "enable"
# etag.use-size = "enable"
# static-file.etags = "enable"
</pre>
Since Moodle maintains its own logs and reporting tools, you can disable lighttpd's server-level logging by commenting out the following lines in /etc/lighttpd/lighttpd.conf, as follows under the respective sections.
<pre>
## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
# "mod_accesslog"
#### accesslog module
#accesslog.filename          = "/var/log/lighttpd/access_log"
</pre>
If your server has CPU cycles to spare, enabling compression improves network speed and students' perceived response time, especially for off-campus and distance learners.  Compression should be separated at the HTTP and PHP levels to maximize CPU cycles (especially on multiple-CPU and multi-core systems).  First uncomment the compression module in /etc/lighttpd/lighttpd.conf, create a directory for the compressed file temporary store (in this example, it's /tmp/compress.tmp) and enter it along with the types of files to compress (do not include PHP mimetypes here), as follows under the respective sections:
<pre>
## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_compress"
#### compress module
compress.cache-dir        = "/tmp/compress.tmp/"
compress.filetype          = ("text/plain", "text/javascript", "text/css", "text/xml")
</pre>
Second, edit /etc/php.ini to enable compression on the PHP output and consider increasing the maximum server submission size (individual courses can still be limited lower than and up to this limit within Moodle itself, if needed). 
<pre>
zlib.output_compression = On
post_max_size = 32M
</pre>
Finally, the standard memory pool setting of 32MB for [http://us2.php.net/apc Alternative PHP Cache (APC)] is fairly low for Moodle, edit /etc/php.d/apc.ini and increase it to 64 or 128 depending on server load and total available memory.  Increasing this setting can increase the speed of page generation made from within the opcode cache on even modest equipment.
<pre>
apc.shm_size=128
</pre>
 
==See Also==
* [http://tracker.moodle.org/browse/MDL-14638 Networking issue related to lighttpd]
* [http://en.wlmp-project.net/downloads.php WLMP project downloads for Windows packages]
* [http://moodle.org/mod/forum/discuss.php?d=126176  Debian/Ubuntu configuration, performance comparison vs apache2]

Latest revision as of 19:15, 11 August 2009

Lighttpd (a.k.a. Lighty) is a lightweight webserver with a small memory footprint that works well with PHP accelerators like eAccelerator and Alternative PHP Cache (APC). It is an alternative to Apache and IIS particularly well suited to systems with low resources, especially RAM -- ideal when using virtual private server (VPS) hosting services. Even on hosts with plenty of resources, Lighty is as fast as Apache if not faster and worth considering.

Lighttpd meets all the base requirements for Moodle and provides most common webserving features; however, it is not intended to replace Apache feature for feature. If your needs extend further than Moodle, be aware of lighttpd's differences and limitations as well as level of knowledge and support necessary and available. Be certain it meets all of your needs before deploying in a production environment.

Installation varies according to platform, if the following example doesn't apply to your server configuration, check the official instruction page here. You will also need to install PHP (preferably with an accelerator) and FastCGI according to these instructions.

Fedora 9, 10 & 11 Example

Lighttpd is a part of the official repository and can be installed using yum to meet all of Moodle's base requirements, including the PHP accelerator Alternative PHP Cache (APC), using the following command.

yum install lighttpd lighttpd-fastcgi mysql php php-mysql \
php-pecl-apc php-gd php-mbstring php-xmlrpc php-pdo ;

Under the respective sections, edit /etc/lighttpd/lighttpd.conf to point to the Moodle root directory, uncomment the FastCGI module and the fastcgi module section; be sure the bin-path points to the PHP FastCGI executable:

## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_fastcgi",
## a static document-root example
server.document-root        = "/home/moodle-1.9/"
#### fastcgi module
fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/php-fastcgi.socket",
                                   "bin-path" => "/usr/bin/php-cgi"
                                 )
                               )
                            )

Client cache control and expiry is very flexible, uncomment the expiration module directive and add the following into /etc/lighttpd/lighttpd.conf for expiry control of common types of static files, change the number of days to meet your needs.

## modules to load
# Module load order is important, the mod_expire should be listed before mod_compress when both are active.
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_expire",
## Client cache control section.
# mod_expire - image files expire 2 days after first access
$HTTP["url"] =~ "\.(gif|GIF|jpg|JPG|png|PNG|swf|SWF|ico|ICO)$" {
     expire.url = ( "" => "access 2 days" )
}
# mod_expire - includes expire 1 day after first access
$HTTP["url"] =~ "\.(css|CSS|js|JS)$" {
     expire.url = ( "" => "access 1 days" )
}
# Some versions of lighttpd may require the following directives for full functionality, uncomment if needed.
# etag.use-inode = "enable"
# etag.use-mtime = "enable"
# etag.use-size = "enable"
# static-file.etags = "enable"

Since Moodle maintains its own logs and reporting tools, you can disable lighttpd's server-level logging by commenting out the following lines in /etc/lighttpd/lighttpd.conf, as follows under the respective sections.

## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
# "mod_accesslog"
#### accesslog module
#accesslog.filename          = "/var/log/lighttpd/access_log"

If your server has CPU cycles to spare, enabling compression improves network speed and students' perceived response time, especially for off-campus and distance learners. Compression should be separated at the HTTP and PHP levels to maximize CPU cycles (especially on multiple-CPU and multi-core systems). First uncomment the compression module in /etc/lighttpd/lighttpd.conf, create a directory for the compressed file temporary store (in this example, it's /tmp/compress.tmp) and enter it along with the types of files to compress (do not include PHP mimetypes here), as follows under the respective sections:

## modules to load
# NOTE: a comma (,) is necessary when other active modules follow this one,
# unnecessary when this is the final active module in the server.modules directive
"mod_compress"
#### compress module
compress.cache-dir         = "/tmp/compress.tmp/"
compress.filetype          = ("text/plain", "text/javascript", "text/css", "text/xml")

Second, edit /etc/php.ini to enable compression on the PHP output and consider increasing the maximum server submission size (individual courses can still be limited lower than and up to this limit within Moodle itself, if needed).

zlib.output_compression = On
post_max_size = 32M

Finally, the standard memory pool setting of 32MB for Alternative PHP Cache (APC) is fairly low for Moodle, edit /etc/php.d/apc.ini and increase it to 64 or 128 depending on server load and total available memory. Increasing this setting can increase the speed of page generation made from within the opcode cache on even modest equipment.

apc.shm_size=128

See Also