Light-weight web server Lighttpd

Introduction

Setup

Ubuntu

(source)

  1. apt-get install lighttpd
  2. apt-get install php5-cgi
  3. vi /etc/php5/cgi/php.ini

    cgi.fix_pathinfo = 1
     
  4. vi /etc/lighttpd/lighttpd.conf

    Uncomment or add:

    "mod_fastcgi"
     
  5. Uncomment or add:

    fastcgi.server = ( ".php" => ((
    "bin-path" => "/usr/bin/php5-cgi",
    "socket" => “/tmp/php.socket”
    )))
     
  6. vi /var/www/test.php

    <?php phpinfo(); ?>

  7. Install common PHP5 modules: apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite sqlite php5-tidy php5-xmlrpc php5-xsl php5-common
  8. /etc/init.d/lighttpd restart
  9. Aim our browser to the server
  10. Test that the script runs as expected

CentOS

(source)

  1. rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
  2. rpm -Uvh http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
  3. yum install lighttpd
  4. chkconfig lighttpd on
  5. mkdir -p /var/run/lighttpd/
  6. chown lighttpd.lighttpd /srv/www/lighttpd/ ; chown lighttpd.lighttpd ./.
  7. chown lighttpd.lighttpd /var/run/lighttpd
  8. service httpd status
  9. service lighttpd start
  10. netstat -tap | grep lighttpd

The directory root (where to put your website files) is at /srv/www/lighttpd/, the config file is /etc/lighttpd/lighttpd.conf, and the log files are located in /var/log/lighttpd/.

Now, let's install Lighttpd FastCGI, PHP5, and the PDO database interface:

  1. yum install lighttpd-fastcgi php-cli
  2. vim /etc/php.ini

    cgi.fix_pathinfo = 1
    ; End:
     
  3. vim /etc/lighttpd/lighttpd.conf

    uncomment the "mod_fastcgi" module
    uncomment the fastcgi.module section: Make sure that the line "bin-path" =>  "/usr/bin/php-cgi" instead of "bin-path" =>  "/usr/local/bin/php
     
  4. lighttpd -t -f /etc/lighttpd/lighttpd.conf
  5. service lighttpd restart
  6. vim /srv/www/lighttpd/info.php

    <?php
    phpinfo();
    ?>
     
  7. http://localhost/info.php

    The page should show you php settings and display "Sever API – CGI/FastCGI" to show that php is working through FastCGI
     
  8. yum install php-pdo
  9. service lighttpd restart
  10. vim /srv/www/lighttpd/sqlite.php

    try {
        $dbh = new PDO("sqlite:db.sqlite");

        $dbh->exec("CREATE TABLE IF NOT EXISTS customer (id INTEGER PRIMARY KEY, name VARCHAR(255))");
        $dbh->exec("INSERT INTO customer (name) VALUES ('Dummy')");

        $sql="SELECT name FROM customer";
        foreach ($dbh->query($sql) as $row) {
            print $row['name'] . "<p>\n";

        $dbh = null;

    } catch(PDOException $e) {
        echo $e->getMessage();
    }

Done!

Resources