Difference between revisions of "Lighttpd"

From ArchWiki
Jump to: navigation, search
m (Ruby on Rails)
(Use filename template, misc capitalization fixes.)
Line 12: Line 12:
 
The lighttpd configuration file is: {{Filename|/etc/lighttpd/lighttpd.conf}}. By default it should produce a working test page.  
 
The lighttpd configuration file is: {{Filename|/etc/lighttpd/lighttpd.conf}}. By default it should produce a working test page.  
  
To check your lighttpd.conf for bugs you can use this command - helps finding misconfigurations very fast:
+
To check your {{filename|lighttpd.conf}} for bugs you can use this command - helps finding misconfigurations very fast:
  
 
  $ lighttpd -t -f /etc/lighttpd/lighttpd.conf
 
  $ lighttpd -t -f /etc/lighttpd/lighttpd.conf
Line 39: Line 39:
 
{{Box Note | New default user and group: Instead of group "nobody" lighttpd now runs as user/group "http" by default.}}
 
{{Box Note | New default user and group: Instead of group "nobody" lighttpd now runs as user/group "http" by default.}}
  
The following needs adding to the config file, /etc/lighttpd/lighttpd.conf
+
The following needs adding to the config file, {{filename|/etc/lighttpd/lighttpd.conf}}
  
 
<pre>
 
<pre>
Line 69: Line 69:
 
</pre>
 
</pre>
  
For php or Ruby on Rails see the next sections.
+
For PHP or Ruby on Rails see the next sections.
  
==php==
+
==PHP==
 
Install php and required modules,
 
Install php and required modules,
 
  # pacman -S php php-cgi
 
  # pacman -S php php-cgi
  
Check that php-cgi is working
+
Check that php-cgi is working {{codeline|php-cgi --version}}
''php-cgi --version''
 
  
 
  PHP 5.3.1 with Suhosin-Patch (cgi-fcgi) (built: Nov 23 2009 21:12:29)
 
  PHP 5.3.1 with Suhosin-Patch (cgi-fcgi) (built: Nov 23 2009 21:12:29)
Line 84: Line 83:
 
If you get a similar output then php is installed correctly.
 
If you get a similar output then php is installed correctly.
  
'''Note''': Please keep in mind if you receive errors like ''No input file found'' after attempting to access your php files then make sure /etc/php/php.ini has the directives enabled:
+
'''Note''': Please keep in mind if you receive errors like ''No input file found'' after attempting to access your php files then make sure {{filename|/etc/php/php.ini}} has the directives enabled:
 
  cgi.fix_pathinfo=1
 
  cgi.fix_pathinfo=1
 
  open_basedir = /home/:/tmp/:/usr/share/pear/:/another/path:/second/path
 
  open_basedir = /home/:/tmp/:/usr/share/pear/:/another/path:/second/path
Line 93: Line 92:
 
Considering you want to use Ruby on Rails I assume you have ruby installed. If not do so.
 
Considering you want to use Ruby on Rails I assume you have ruby installed. If not do so.
  
We need rubygems and ruby-fcgi. Check the AUR!
+
We need rubygems and ruby-fcgi. Check the [[AUR]]!
  
 
Rubygems  
 
Rubygems  
Line 124: Line 123:
 
For documentation how to use Ruby on Rails please consult [http://rubyonrails.org].
 
For documentation how to use Ruby on Rails please consult [http://rubyonrails.org].
  
=TroubleShooting=
+
=Troubleshooting=
  
 
== Lighttpd downloads .php files ==
 
== Lighttpd downloads .php files ==
  
If lighttpd downloads ''.php'' files instead of "initializing" them you probably missed to add these lines to your {{Filename|/etc/lighttpd/lighttpd.conf}}.
+
If lighttpd downloads {{filename|.php}} files instead of "initializing" them you probably missed to add these lines to your {{Filename|/etc/lighttpd/lighttpd.conf}}.
  
 
<pre>
 
<pre>

Revision as of 16:16, 3 July 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Introduction

lighttpd is a secure, fast, compliant, and very flexible web-server that has been optimized for high-performance environments. It has a very low memory footprint compared to other webservers and takes care of cpu-load. Its advanced feature-set (FastCGI, CGI, Auth, Output-Compression, URL-Rewriting and many more) make lighttpd the perfect webserver-software for every server that suffers load problems.
Source: The lighttpd website.

Installation

Lighttpd is available in the extra repository so:

# pacman -S lighttpd

Configuration

Basic Setup

The lighttpd configuration file is: Template:Filename. By default it should produce a working test page.

To check your Template:Filename for bugs you can use this command - helps finding misconfigurations very fast:

$ lighttpd -t -f /etc/lighttpd/lighttpd.conf

The default configuration file specifies Template:Filename as the document directory served.

It may be necessary to add a user and group for http if you don't already have one. That user seems to need to have permissions to write to the Template:Filename as well, so we'll make it the owner of that folder.

# groupadd http
# adduser http
# chown -R http /var/log/lighttpd

To test the install

# /etc/rc.d/lighttpd start
# touch /srv/http/index.html
# chmod 755 /srv/http/index.html
# echo 'TestMe!' >> /srv/http/index.html

Then point your browser to localhost, and you should see the test page.

You may want to add lighttpd to the daemons list in Template:Filename to start the server on boot.

FastCGI

Install fcgi

# pacman -S fcgi

Now you have lighttpd with fcgi support. If it was that what you wanted you're all set. People that want Ruby on Rails and/or PHP should continue. Template:Box Note

The following needs adding to the config file, Template:Filename

server.modules = (
    "mod_access",
    "mod_fastcgi",
    "mod_accesslog"
)

server.indexfiles = ( "dispatch.fcgi", "index.php" ) #dispatch.fcgi if rails specified

server.error-handler-404   = "/dispatch.fcgi" #too
fastcgi.server = (
".fcgi" =>
  ( "localhost" =>
    (
      "socket" => "/tmp/rails-fastcgi.socket",
      "bin-path" => "/path/to/rails/application/public/dispatch.fcgi"
    )
  ),
".php" =>
  ( "localhost" =>
    (
      "socket" => "/tmp/php-fastcgi.socket",
      "bin-path" => "/usr/bin/php-cgi"
    )
  )
)

For PHP or Ruby on Rails see the next sections.

PHP

Install php and required modules,

# pacman -S php php-cgi

Check that php-cgi is working Template:Codeline

PHP 5.3.1 with Suhosin-Patch (cgi-fcgi) (built: Nov 23 2009 21:12:29)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

If you get a similar output then php is installed correctly.

Note: Please keep in mind if you receive errors like No input file found after attempting to access your php files then make sure Template:Filename has the directives enabled:

cgi.fix_pathinfo=1
open_basedir = /home/:/tmp/:/usr/share/pear/:/another/path:/second/path

And that the files are world readable,

# chmod -R 755

Ruby on Rails

Considering you want to use Ruby on Rails I assume you have ruby installed. If not do so.

We need rubygems and ruby-fcgi. Check the AUR!

Rubygems

$ sudo pacman -S rubygems

ruby-fcgi (Keep in mind you will need base-devel installed for the package to build correctly)

$ wget http://aur.archlinux.org/packages/ruby-fcgi/PKGBUILD
$ makepkg
$ sudo pacman -U ruby-fcgi-x.x.x-x-xxx.pkg.tar.gz

Now we have rubygems. Let's get rails!

$ sudo gem install rails --include-dependencies
$ sudo gem install fcgi --include-dependencies
If this fails, run
# pacman -S fcgi
or get [1] and compile it yourself.
$ wget http://fastcgi.com/dist/fcgi.tar.gz
$ tar zxvf fcgi.tar.gz
$ cd fcgi-2.4.0
$./configure
$ make
# make install

And repeat the gem install.

Check if you have more than one fcgi.so

$ find /usr -name fcgi.so

If you have two, delete the one that doesn't have "/site_ruby/" in its path.

For documentation how to use Ruby on Rails please consult [2].

Troubleshooting

Lighttpd downloads .php files

If lighttpd downloads Template:Filename files instead of "initializing" them you probably missed to add these lines to your Template:Filename.

server.modules = (
                   "mod_fastcgi",
                 )

fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/bin/php-cgi", #depends where your php-cgi has been installed. Default here.
                     "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"
                 )))

Styles (CSS) not working properly

The default lighttpd config does not include a mimetype definition for CSS so when standards compliant browsers get text/html instead of text/css they get confused and nothing displays properly. To fix this add an entry for CSS.

mimetype.assign	= (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".css" => "text/css"
)

New lines are not needed and are only used here for readability.