Lighttpd (español)

100k files

lighttpd
backend throughput requests/s
writev 6.11MByte/s 59.77
linux-sendfile 6.50MByte/s 63.62
posix-aio 12.88MByte/s 125.75
gthread-aio 15.04MByte/s 147.08
linux-aio-sendfile 15.56MByte/s 151.95
others
litespeed 3.0rc2 (writev) 4.35MByte/s 42.78
litespeed 3.0rc2 (sendfile) 5.49MByte/s 53.68
apache 2.2.4 15.04MByte/s 146.93

For small files you can gain around 140% more throughput.

without no-atime

To show the impact of the we compare the output for the output
with and without :

With enabled:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 1 62 506300   9192  20500 470064    0    0 12426     5 7005  6324  3 27  7 63
 0 63 506300  10188  19768 469732    0    0 14154     2 8252  7614  3 30  0 67
 0 64 506300  10488  19124 470492    0    0 13589     0 8261  7483  3 27  0 69
 0 64 506300  10196  17952 473092    0    0 13062     8 7388  6560  3 25  8 65
 0 64 506300  10656  16836 474720    0    0 11790     0 6378  5074  2 23 11 64

With disabled:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0 21 506300  10408  15452 491680    0    0 10515   326 5362  1619  2 22 19 57
 3  7 506300  11116  17888 487588    0    0 11020   493 6056  2400  7 25 10 58
 0  0 506300  10200  19704 488004    0    0  8840   365 4506  1622  2 20 29 49
 2 14 506300  10460  21624 485288    0    0 12422   428 6464  1986  2 26 11 60
 0  1 506300   9436  24116 485316    0    0 12640   513 7159  2109  3 28  2 67
 0 21 506300  11864  25768 481588    0    0  8760     5 4436  1571  2 19 39 41
 0 21 506300  10352  24892 483412    0    0 11941   339 6005  1913  3 24 12 6

You see how the (blocks out) goes up and how (blocks in) goes down in the same way. As you usually don’t need the (file access file), you should either mount the file-system with or use the setting . By default this setting is disabled to be backward compatible.

Types of Virtual Hosting:

There are two types of virtual hosting, namely.

IP Based – The website can be accessed using IP Address. The limitation is that you can host only one website per IP Address.

Name Based – Website will be accessible only when we use FQDN (ex. www.itzgeek.local). Shared hosting providers use this method for hosting multiple websites on a single server.

In our previous article, we looked into the installation of Lighttpd server on CentOS / Debian / Ubuntu.

READ: How to Install Lighttpd on CentOS 7 / RHEL 7READ: How to Install Lighttpd on Debian 9READ: How to Install Lighttpd on Ubuntu 16.04

Here, we focus on implementing Name Based virtual hosting on Lighttpd server.

3.- Install Lighttpd

The easiest and most direct way to install Lighttpd on Ubuntu 18.04 is to do it from the official repositories.

:~# apt install lighttpd

4.- This is the easiest way to install Lighttpd

And then you enable the service to start with the system.

:~# systemctl enable lighttpd
:~# systemctl start lighttpd

5.- Enabling lighttpd service

In order to avoid problems between Lightppd and the firewall, run:

:~# ufw allow 80/tcp
:~# ufw reload
:~# ufw enable

6.- Setting some firewall rules

To check the installation, go to your web browser and try to access to . If you see this then everything is OK.

7.- lighttpd default page

100k files

lighttpd
backend throughput requests/s
writev 6.11MByte/s 59.77
linux-sendfile 6.50MByte/s 63.62
posix-aio 12.88MByte/s 125.75
gthread-aio 15.04MByte/s 147.08
linux-aio-sendfile 15.56MByte/s 151.95
others
litespeed 3.0rc2 (writev) 4.35MByte/s 42.78
litespeed 3.0rc2 (sendfile) 5.49MByte/s 53.68
apache 2.2.4 15.04MByte/s 146.93

For small files you can gain around 140% more throughput.

without no-atime

To show the impact of the we compare the output for the output
with and without :

With enabled:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 1 62 506300   9192  20500 470064    0    0 12426     5 7005  6324  3 27  7 63
 0 63 506300  10188  19768 469732    0    0 14154     2 8252  7614  3 30  0 67
 0 64 506300  10488  19124 470492    0    0 13589     0 8261  7483  3 27  0 69
 0 64 506300  10196  17952 473092    0    0 13062     8 7388  6560  3 25  8 65
 0 64 506300  10656  16836 474720    0    0 11790     0 6378  5074  2 23 11 64

With disabled:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0 21 506300  10408  15452 491680    0    0 10515   326 5362  1619  2 22 19 57
 3  7 506300  11116  17888 487588    0    0 11020   493 6056  2400  7 25 10 58
 0  0 506300  10200  19704 488004    0    0  8840   365 4506  1622  2 20 29 49
 2 14 506300  10460  21624 485288    0    0 12422   428 6464  1986  2 26 11 60
 0  1 506300   9436  24116 485316    0    0 12640   513 7159  2109  3 28  2 67
 0 21 506300  11864  25768 481588    0    0  8760     5 4436  1571  2 19 39 41
 0 21 506300  10352  24892 483412    0    0 11941   339 6005  1913  3 24 12 6

You see how the (blocks out) goes up and how (blocks in) goes down in the same way. As you usually don’t need the (file access file), you should either mount the file-system with or use the setting . By default this setting is disabled to be backward compatible.

Running Scripts with mod_fastcgi

If you need your web server to execute dynamic content, the preferred way to accomplish this with lighttpd is to run these scripts using FastCGI. To run a script, FastCGI externalizes the interpreter for the script for dynamic web applications from the web server rather than running the scripts “inside” the web server. This is in contrast to the common Apache-based approaches such as mod_perl, mod_python, and mod_php. If you’re familiar with Apache this might seem foreign and/or antiquated, but in high-traffic situations doing things this way is often more efficient and effective.

To set up FastCGI you need to make sure that an interpreter is installed on your system that is capable of running your scripts. Perl version 5.14.2 is included in Ubuntu by default. Issue one of the following commands:

You will almost certainly need to install and set up a database system of some sort as well, depending on the software you intend to run.

Lighttpd will send CGI requests to CGI handlers on the basis of file extensions, and every file extension can be forwarded individual handlers. You may also forward requests for one extension to multiple servers, and Lighttpd will automatically load balance these FastCGI connections.

If you install the php5-cgi package and enable mod_fastcgi with then a default FastCGI handler will be configured in the file . Though the handler will likely require specific customization for your use cases, it serves as an effective example:

/etc/lighttpd/conf-enabled/10-fastcgi.conf

You can map more than one file extensions to a single FastCGI handler by adding the following entry to your config file:

/etc/lighttpd/conf-enabled/10-fastcgi.conf

Again, mod_fastcgi supports creating multiple handlers, and even adding multiple FastCGI back ends per-handler.

Install Lighttpd

Install the server from the Ubuntu package repository:

Once the server is installed, make sure that it’s running and is enabled. Visit in your browser, replacing with your Linode’s IP address. If you configured lighttpd to run on an alternate port for testing, be sure to replace with this port. You’ll see a placeholder page for lighttpd that contains some important information:

  • Configuration files are located in .
  • By default, the “DocumentRoot” (where all HTML files are stored) is located in the directory. You’ll be able to configure this later.
  • Ubuntu provides helper scripts to enable and disable server modules without directly editing the config file: and .

Virtual Host Setup with Enhanced Vhost

Enhanced virtual hosting works slightly differently than Simple by building the document root based on a pattern containing wildcards. Be sure that all other virtual hosting modules are disabled before beginning.

  1. Run the following command to enable the enhanced virtual hosting module:

  2. Restart lighttpd to load the configuration changes:

  3. To accomplish the same directory structure with as with above, you need to modify the file:

    /etc/lighttpd/conf-available/10-evhost.conf
  4. Modify the in the main lighttpd configuration file:

    /etc/lighttpd/lighttpd.conf

    With the configuration you set in Steps 3 and 4, if is requested, and is found, that directory becomes the document root when serving requests. The in the path pattern specifies that a request will be checked against host files named in the format of domain and Top Level Domain (TLD). The directive specifies a default host that is used when a matching directory does not exist.

  5. Restart lighttpd to load the configuration changes:

The naming convention for these virtual hosts is derived from the domain names. Take the following web address as an example: We read domain names from highest level on the right, to lowest on the left. So is the TLD, is the domain, is the subdomain 1 name, and is the subdomain 2 name.

To modify the host directory format lighttpd recognizes, define the pattern that gets passed to the directory in which the content lives. The following table shows what host directory format is used as the document root for each pattern. It also shows which host file will be used to serve content, using the above URL as an example request:

Pattern Host Directory Format Document Root Path
%0 Domain name and TLD /var/www/html/example.com/htdocs
%1 TLD only /var/www/html/com/htdocs
%2 Domain name without TLD /var/www/html/example/htdocs
%3 Subdomain 1 name /var/www/html/exampleSub/htdocs
%4 Subdomain 2 name /var/www/html/exampleSub2/htdocs
%_ Full domain name /var/www/html/exampleSub2.exampleSub.example.com/htdocs

Virtual Hosting Best Practices

The way you set up virtual hosting on your web server depends upon what kind of sites you host, their traffic, the number of domains, and their workflows. We recommend hosting all of your domains in a centralized directory (e.g., ) and then symbolically linking these directories into more useful locations.

For instance, you can create a series of “web editor” user accounts. You may then link the document root of each domain into a folder in the home folder of the editor for that domain. For the user account that manages the site:

You can also use symbolic links to cause multiple virtually hosted domains to host the same files. For example, to get to point to ’s files, create the following link:

No matter what you decide, we recommend developing a systematic method for organizing virtual hosting to simplify any modifications to your system.

Installing MySQL

Finally, install the MySQL database server; run the following command:

sudo aptitude install mysql-server

You will be then asked to provide a password for the MySQL root user. Activate it with the following command:

sudo mysql_install_db

Then run the secure installation script:

sudo /usr/bin/mysql_secure_installation

Provide the root user password you’ve just set (or leave empty if you have not set one) and then you will be asked if you want to change that password. Feel free to choose No and continue.

After this, it’s recommended to choose Yes to the following questions as they deal with removing some test databases and users and most importantly, removing privileges over your databases for anonymous users.

And then you are done! You can start using your new LLMP based web server.

Article Submitted by: Danny

Behavior Change

lighttpd now performs strict URL parsing and normalization on HTTP requests. This is configurable, but the defaults are now strict unless explicitly configured otherwise.

Enabling strict URL parsing and normalization by default provides more consistent behavior for mod_redirect and mod_rewrite, which match against the (url-encoded) URL request. However, decoding %2F by default, while generally desirable for consistency, is potentially a breaking change for those encoding URLs in the url-path and relying on the literal ‘/’ as a delimiter. For those uses, “url-path-2f-decode” => “disable” will need to be explicitly set in the lighttpd config.

https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_http-parseoptsDetails

The recommended settings for server.http-parseopts are the following, unless specific use requires looser settings:

4.- Install PHP

A web server needs a programming language to interpret and execute the applications built, so install PHP.

:~# apt install php7.2 php7.2-fpm php7.2-mysql php7.2-cli php7.2-curl php7.2-xml

8.- Installing PHP

Next, edit the file

:~# nano /etc/php/7.2/pool.d/www.conf

Change the line”listen” to 127.0.0.1:9000.

9.- Editing the PHP file configuration

Next, edit the file too.

:~# nano /etc/lighttpd/conf-available/15-fastcgi-php.conf

And change:

"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",

To:

"host" => "127.0.0.1",
"port" => "9000",

10.- Editing the PHP configuration file for PHP CGI

Finally, enable the FastCGI and FastCGI-PHP modules:

:~# lighty-enable-mod fastcgi
:~# lighty-enable-mod fastcgi-php

11.- Enabling the PHP modules

Restart Lighttpd:

:~# systemctl restart lighttpd

Virtual Host Setup with Simple Vhost

This section covers configuration for simple virtual hosting. The module allows you to set up virtual hosts with respective document roots in user-defined folders named for the domains, below a server root. Ensure that all other virtual hosting modules are turned off before proceeding.

  1. Begin by enabling :

  2. Restart lighttpd to load your changes:

  3. Modify the following settings in your file:

    /etc/lighttpd/conf-available/10-simple-vhost.conf

    The defines the base directory under which all virtual host directories are created.

    The defines the subdirectory under the host directory that contains the pages to be served. This is comparable to the directory in some Apache configurations, but is called in the above configuration.

    If lighttpd receives a request and cannot find a matching directory, it serves content from the .

    In the above configuration, requests are checked against existing directory names within . If a directory matching the requested domain exists, the result is served from the corresponding . If it doesn’t exist, content is served from within the directory.

    To clarify this concept, suppose that contains only the directories and , both of which contain folders with content:

    • If a request is made for the URL , content will be served from .
    • If a request is made for a URL which resolves to the server, but does not have a directory, content will be served from , since is the default host.

    For subdomains, create host directories for each subdomain in the same way. For instance, to use as a subdomain of , create a directory called with a directory for content. Be sure to add DNS records for any subdomains you plan to use.

  4. Restart the web server again to reload changes:

For more examples, consult the lighttpd official documentation.

file pool

On the machine which supposed to be tested we generate 2 sets of 10Gbyte files. One is of 100,000 files of 100kbyte size, and the other is 1.000 files of 10MByte size.

The file-pool is 10 times larger than the available RAM on the server-host. Based on this disk layout we generate the list of URLs for http_load.

The same commands are executed for the 10MByte files to generate a file-set which check the performance for large files.

hardware

The test-network is made up of:

  • Netgear GS108, a 8-port Gigabit Switch
  • client:
    • OS: WinXP Prof. 64-bit
    • CPU: AMD64 X2 (dual core) 4200+
    • Network: Intel Pro/1000
  • server:
    • OS: Linux 2.6.16.21-0.25-default x86_64 (OpenSuse 10.1)
    • CPU: AMD64 3000+
    • Network: Intel Pro/1000
    • Modules: stock, but ip_conntrack is ‘ed
    • Disks: 2 SATA disks as RAID1 via the md-driver

The disks are:

Configure Lighttpd

The main lighttpd configuration file is located at . This file provides a list of server modules to be loaded and allows you to change global settings for the web server.

The first directive in the configuration is , which lists modules to be loaded upon starting or reloading the lighttpd server. To disable a module, add a at the beginning of the corresponding line to comment it out. Remove the to enable the module. Modules can also be added to this list. For example, in the default file, you can enable the (rewriting URL requests) module by uncommenting the appropriate line, or add to enable the authentication module. Note that these modules will be loaded in the order they appear.

Following the block is a list of other settings to configure the server and its modules. Most directives are self-explanatory, but not all available options are listed by default and you may want to add them, depending on your needs. A few performance settings you may want to add yourself include:

  • — Specifies how many concurrent connections will be supported
  • — Sets the maximum number of requests within a keep alive session before the connection is terminated
  • — Specifies the number of worker processes to spawn. If you’re familiar with Apache, a worker is analogous to a child process.
  • — Defines the IP address, hostname, or path to the socket lighttpd will listen on. Multiple lines can be created to listen on different IP addresses. The default setting is to bind to all interfaces.

Some settings depend on certain modules. For example, requires that be enabled because it is specific to that module. However, for ease of use, most modules have their own configuration files and can be enabled and disabled via command line rather than by editing the configuration file.

Enable and Disable Modules via Command Line

For ease of use, you may wish to enable and disable modules via the command line. Lighttpd provides a simple method to do this, so the configuration doesn’t need to be edited every time a new module is needed.

Run from the command line to see a list of available modules and a list of already enabled modules, as well as a prompt to enable a module. This can also be accomplished in one line. For example, to enable the authentication module:

This command creates a symbolic link to the module’s configuration file in , which is read by a script in the main configuration file. To edit the configuration for a specific module, look for its file in .

There are many additional modules that are included in separate Ubuntu packages. Some useful ones are:

  • — Manages virtual hosts using a MySQL database. This module works well when you need to manage a large number of virtual hosts
  • — Supports WebDAV extensions to HTTP for distributed authoring of HTTP resources
  • — Controls the request handling module

When you have installed these packages you will be able to enable them using .

Restart lighttpd to load changes:

For a comprehensive list of available options and modules, refer to the lighttpd project’s documentation on configuration options.

Step 4 — Configuring Lighttpd to Serve PHP Applications

In this step you will configure Lighttpd to use FastCGI and PHP-FPM. This will enable PHP on Lighttpd and give fast and efficient PHP support.

First, enable the FastCGI module. Open the Lighttpd modules configuration file:

Locate the following section:

/usr/local/etc/lighttpd/modules.conf

Uncomment the line by removing the symbol. If you don’t find that line, add it to the end of the file.

/usr/local/etc/lighttpd/modules.conf

Save the file and exit the editor.

Next, edit the FastCGI configuration file:

This file has several examples, commented out. Add the following configuration lines to the end of the file, which configures Lighttpd to serve PHP files with FastCGI and PHP-FPM:

/usr/local/etc/lighttpd/conf.d/fastcgi.conf

Next, enable Lighttpd to start at boot. This way Lighttpd will start automatically whenever the web server is restarted:

Then start the service:

Now that PHP is ready to go, let’s make sure everything works.

STEP 7: CHANGE WORDPRESS CONTENT FILE PERMISSIONS

After configuring WordPress settings, your next step will be to change the directory permissions so WordPress can function properly. To do that, run the below commands

Finally, restart Lighttpd webserver and open your browser and go to the server IP address or hostname.

Disable Apache2 web server so it never runs.

Open your browser and go to the server hostname and you should see WordPress default setup page.

http://localhost

Continue with WordPress wizard to setup your new site.

Continue with the setup wizard and create a WordPress administration to manage the site online. Don’t forget to name the site appropriately.

Click Install WordPress when done.

Step 1 — Installing Lighttpd

There are a couple options for installing Lighttpd, but in this tutorial, you’ll use packages for installation. This method is faster than installing from source or via Ports, and software installed with this method is easy to update.

To install Lighttpd with its package, first update the repository information to ensure you have the latest list of available packages:

Next, download and install the package:

Confirm the installation by typing . Lighttpd will install.

With this default configuration, you’ll see this error when you start the server:

This is because the default Lighttpd configuration isn’t completely configured to support IPv6. To avoid surprises later, edit Lighttpd’s configuration file and disable support for IPv6, since you won’t need it to complete this tutorial. You can enable it in the future if you decide to use it:

Locate this section:

/usr/local/etc/lighttpd/lighttpd.conf

Change to :

/usr/local/etc/lighttpd/lighttpd.conf

Next, locate this line at the very end of the configuration file:

/usr/local/etc/lighttpd/lighttpd.conf

Comment it out, as it’s unnecessary when we’re not using IPv6:

/usr/local/etc/lighttpd/lighttpd.conf

Then save the file and exit the editor.

Let’s configure MySQL next.

Step 5 — Testing the Server Setup

To test the newly configured Lighttpd server, first create the folder , which is where Lighttpd will look for web pages to serve.

Then create an in the folder. This file will test that PHP is working and let you review information about the webserver setup in a web browser:

Add this code to the file:

/usr/local/www/data/info.php

Save the file and exit the editor.

Visit in your web browser. You’ll see a a page that looks like this:

This page shows information about your operating system, web server, and how your web server handles PHP files. It also verifies that your web server can serve PHP files correctly.

If you don’t see this page, and instead see Error 503 Service Not Available, ensure that the service started correctly in the previous step.

Once you’ve verified that things are working, remove the page, as it exposes information about your server that you should keep private:

The web server is now fully configured and ready to go. Place your files in to serve them.

Устанавливаем PHP

С сайта php.net беру последнюю стабильную версию, кладу в /install и извлекаю из архива, после чего доустанавливаю все необходимое:

apt-get build-dep php5

cd /install/php-5.3.1

./buildconf —force

./configure —disable-debug —disable-ftp —disable-inline-optimization —disable-magic-quotes —disable-mbstring —enable-wddx=shared —enable-xml —with-regex=system —with-jpeg-dir=/usr/lib —with-zlib-dir=/usr/lib —with-zlib —without-pdo-sqlite —without-iconv —without-sqlite —enable-shared

make

make install

Все 🙂

Если все прошло по плану, то PHP установлен в каталог /usr/local/bin

Дальше инструкция по установке велит копировать файл php.ini по месту его постоянной дислокации (cp /install/php-5.3.1/php.ini-development /usr/local/lib/php.ini), однако опытным путем установлено, что пока этого делать не надо.

Пока создадим пустой файл php.ini по тому же пути.

cat /dev/null > /usr/local/lib/php.ini

В результате, PHP работает в конфигурации по умолчанию. Если какой-либо параметр необходимо изменить-  просто дописываем его в php.ini. Например, у меня файл имеет такой вид:

Включаюмодуль fast-cgi и simple-vhost: (для обработки php-сценариев при помощи внешнего обработчика и поддержки виртуалхостов)

Основной конфиг lighttpd – файл /etc/lighttpd/lighttpd.conf

В том же каталоге кроме lighttpd.conf лежат 2 подкаталога:  conf-available и conf-enabled

Первый – список всех возможных дополнительных конфигов. Второй – линки на те, что действительно будет использоваться

Создаем нужные линки:

Файл конфига содержит примерно такой код:

Здесь надо изменить путь к php-cgi, он должен быть таким: /usr/local/bin/php-cgi

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *