[howto] lighttpd web server with PHP5 on Kamikaze
1. Intro
Instructions howto install and configure the lighttpd web server with PHP5 on Kamikaze. Lighttpd will listen on port 81
and OpenWrt's default web server (from BusyBox) will be on port 80.
Tested with Kamikaze (X86 [2.6]) in VMware and on Soekris net4801.
2. Select lighttpd and PHP5 in menuconfig to build the required packages.
- Network
- <M> lighttpd
- in lighttpd submenu select all modules to <M>
- Languages
- <M> PHP5
- in PHP5 submenu select all modules to <M>
3. Install the packages (lighttpd and PHP5)
ipkg install lighttpd lighttpd-mod-cgi php5 php5-cgi
4. Configure lighttpd
Change /etc/lighttpd.conf to:
#server.modules = (
[..]
# "mod_cgi",
[..]
#)
to
server.modules = (
[..]
"mod_cgi"
[..]
)
server.document-root = "/www/"
to
server.document-root = "/www_1/"
index-file.names = ( "index.html", "default.html", "index.htm", "default.htm" )
to
index-file.names = ( "index.html", "default.html", "index.htm", "default.htm", "index.php" )
#server.port = 81
to
server.port = 81
#### CGI module
#cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" )
to
#### CGI module
#cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl" )
cgi.assign = ( ".php" => "/usr/bin/php" )
Create a new www docroot for our webserver:
mkdir /www_1
Enable lighttpd on boot with /etc/init.d/lighttpd enable
5. Configure PHP5
Change /etc/php.ini
doc_root = /www
to
doc_root = /www_1
Create the file /www_1/phpinfo.php with the content:
<?php phpinfo(); ?>
For a first test (re)start lighttpd (/etc/init.d/lighttpd restart) and point your browser to
http://192.168.1.1:81/phpinfo.php. Now you should see the well known phpinfo page.
5.1. Install and enable PHP5 extensions (e.g. SQLite, GD)
5.1.1. SQLite extension
Install the SQLite extension. For some reson PHP5 is linked against SQLite v2.8.17.
ipkg install php5-mod-sqlite
Add or uncomment the following line in /etc/php.ini in section "Dynamic Extensions"
extension=sqlite.so
/www_1/sqlite-helloworld.php
<?php
if ($db = sqlite_open('mysqlitedb', 0666, $sqliteerror)) {
sqlite_query($db,'CREATE TABLE foo (bar varchar(10))');
sqlite_query($db,"INSERT INTO foo VALUES ('Hello, World!')");
$result = sqlite_query($db,'select bar from foo');
var_dump(sqlite_fetch_array($result));
} else {
die ($sqliteerror);
}
?>
Restart lighttpd web server
/etc/init.d/lighttpd restart
Open http://192.168.1.1:81/sqlite-helloworld.php in your browser and you should see this
array(2) { [0]=> string(13) "Hello, World!" ["bar"]=> string(13) "Hello, World!" }
5.1.2 GD extension
ipkg install php5-mod-gd
Add or uncomment the following line in /etc/php.ini in section [.....]
extension=gd.so
/www_1/gd-helloworld.php
<?php
header ("Content-type: image/png");
$im = @ImageCreate (200, 100)
or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 5, 5, 5, "Hello, world!", $text_color);
ImagePNG ($im);
?>
Restart lighttpd web server
/etc/init.d/lighttpd restart
Open http://192.168.1.1:81/gd-helloworld.php in your browser and you should see a generated PNG image (gd-helloworld.png).
It has a white background and a red text with the string "Hello, world!".
(Last edited by forum2006 on 25 Apr 2007, 20:58)