Lighttpd with PHP5-CGI and SQLite

seiler.IT > English Version > Projects > Alix Board 3D3 > Lighttpd with PHP5-CGI and SQLite

Software Download

First you have to download all necessary software packages. As I am running voyage linux (a debian derivate) it is really simple by using apt-get.

apt-get update
apt-get install lighttpd
apt-get install php5-cgi
apt-get install sqlite
apt-get install php5-sqlite

Configuration

First of all you have to add the fast_cgi-module to the lighty configuration file (/etc/lighttpd/lighttpd.conf). Add "mod_fastcgi" to the "server.modules =()"-part. After that I aded the following code right to the end of the same file to get php5 recognised by lighttpd. I also disabled "mod_accesslog" by commenting this module out, as I do not need any logging. Also the logs-files must be commented out, as shown below.
fastcgi.server = ( ".php" => ((
                     "bin-path" => "/usr/bin/php5-cgi",
                     "socket" => "/tmp/php.socket"
                 )))
## where to send error-messages to
#server.errorlog            = "/var/log/lighttpd/error.log"

#### accesslog module
#accesslog.filename         = "/var/log/lighttpd/access.log"
The last step is cleaning up the environment for lighty. Logs can be erased.
cp -a /rw/var/log/lighttpd /ro/var/log/lighttpd
rm /ro/var/log/lighttpd/*

Test your installation

Now we can recheck our installation by adding a new PHP-file to /var/www.
Just copy and paste the following code to a file called db.php.
Save, and point your browser to http://{your_Alix_IP}/db.php.
<?php
// Create an SQLite DB in the file test.sqlite
  $db = new SQLiteDatabase("test.sqlite");
  $db->query("BEGIN;
          CREATE TABLE dbtest(id INTEGER PRIMARY KEY, article CHAR(50),price FLOAT(10));
          INSERT INTO dbtest (article,price) VALUES('Book1','12.99');
          INSERT INTO dbtest (article,price) VALUES('Book2','15.23');
          COMMIT;");
  $result = $db->query("SELECT * FROM dbtest");

  // Read and show the DB we created
  echo "<PRE>";
  printf("+------------+------------------------------------------+\n");
  printf("| Price       | Article                              |\n");
  printf("+------------+------------------------------------------+\n");
  while ($result->valid()) {
    $row = $result->current();
    printf("| %10s | %-40s |\n",$row['price'],$row['article']);
    $result->next();
  }
  printf("+------------+------------------------------------------+\n");
  echo "</PRE>";
  unset($db);
 phpinfo();
?>
Alix Board running lighttpd, PHP5 and SQLite
Alix Board running lighttpd, PHP5 and SQLite
I hope, everything works fine by you.
Please eMail me, if you have any suggestions

Go back