≡ Menu

Lighttpd

Q. I'm using lighttpd under CentOS 5 and getting the following error:
...can't handle '$HTTP[url] =~ …' as you compiled without pcre support.

My question is What is pcre support, and how do I solve this problem?

A. Pcre is nothing but Perl-compatible regular expression library. PCRE has its own native API, but a set of "wrapper" functions that are based on
the POSIX API are also supplied in the library libpcreposix. You must compile lighttpd with pcre to support lighttpd regex style config option. pcre-devel package provides the development files (Headers, libraries for static linking, etc) for pcre. Install the following package and rebuild your lighttpd:
# yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

Now change directory to lighttpd source code and recompile Lighttpd with pcre option:
# make clean
# ./configure
# make
# make install

Now restart lighttpd and it should support pcre style config options.

Q. How do I configure lighttpd web server as virtual host for serving multiple web site from a single public IP address (name-based virtual hosting)?

A. Virtual hosting is a method that servers such as webservers use to host more than one domain name on the same server, sometimes on the same IP address.

There are two basic methods of accomplishing virtual hosting .
(A) name-based virtual hosting : You use multiple host names for the same webserver IP address. For example domain nixcraft.com and theos.in uses same IP address called 65.111.211.111.

(B) ) IIP address / ip-based virtual hosting

How do I configure Lighttpd for name-based virtual hosting?

Let us say your setup is as follows:

  • Public IP address: 72.12.5.10
  • Domain names: domain1.com and domain2.net
  • Default Document Root: /home/lighttpd/default/http
  • Default Document Root for domain1.com: /home/lighttpd/domain1.com/http
  • Default Document Root for domain2.net: /home/lighttpd/domain2.net/http

First, create required directories:
# mkdir -p /home/lighttpd/default/http
Next, open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf
Setup default document root:
server.document-root = "/home/lighttpd/default/http/"
Setup public IP address:
server.port = 80
server.bind = "72.12.5.10"

At the bottom of the file, add:
include "domain1.com.conf"
include "domain2.net.conf"

Save and close the file.

Create domain1.com virtual host configuration

Create required directories:
# mkdir -p /home/lighttpd/domain1.com/http
# mkdir -p /home/lighttpd/domain1.com/logs

Open /etc/lighttpd/domain1.com.conf file:
# vi /etc/lighttpd/domain1.com.conf
Add following configuration directive:

$HTTP["host"] =~ "domain1\.com" {
            server.document-root = "/home/lighttpd/domain1.com/http"
            accesslog.filename         = "/home/lighttpd/domain1.com/logs/access.log"
}

Save and close the file.

Create domain2.net virtual host configuration

Create required directories:
# mkdir -p /home/lighttpd/domain2.net/http
# mkdir -p /home/lighttpd/domain2.net/logs

Open /etc/lighttpd/domain2.net.conf file:
# vi /etc/lighttpd/domain2.net.conf
Add following configuration directive:

$HTTP["host"] =~ "domain2\.net" {
            server.document-root = "/home/lighttpd/domain2.net/http"
            accesslog.filename         = "/home/lighttpd/domain2.net/logs/access.log"
}

Save and close the file.

Restart the lighttpd web server:
# /etc/init.d/lighttpd restart

Make sure document root is owned by your web server user such as www-data or lighttpd:
# chown -R lighttpd:lighttpd /home/lighttpd/

I would like to see my php or apache web server log files in real time. How do I see a log file in real time including all incoming logs on Linux using ssh based session?
[click to continue…]

How do I test php installation with a phpinfo() page under UNIX / Linux Apache / nginx / lighttpd web server?
[click to continue…]

Run shell script from web page

Q. How do I run a shell script from a web server or a web page under Apache or Lighttpd websever?

A. In order to run a shell script from a web page you need Apache web server configured with cgi access. Apache CGI allows documents/files in cgi-bin directory treated as application and run by server when requested rather than as documents sent to the client.. It means if you put shell script in cgi-bin directory then you are able to execute them from a web page. However, you cannot simply run shell script from a web. You need to send or print the MIME type before outputting data to the web browser from shell script. You need to add following line to script before you get output back to browser:

echo "Content-type: text/html"
echo ""

Here is the script that can displays today's date and other information related to your shell script:

#!/bin/bash
# get today's date
OUTPUT="$(date)"
# You must add following two lines before
# outputting data to the web browser from shell
# script
 echo "Content-type: text/html"
 echo ""
 echo "<html><head><title>Demo</title></head><body>"
 echo "Today is $OUTPUT <br>"
 echo "Current directory is $(pwd) <br>"
 echo "Shell Script name is $0"
 echo "</body></html>"

Save the script in your cgi-bin directory and execute it from web page.

See also:

=> For more examples see how to: Run Linux / UNIX commands from a web page.