OpenWrt Forum Archive

Topic: [howto] lighttpd web server with PHP5 on Kamikaze

The content of this topic has been archived on 11 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

[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)

Thanks for the tutorial,
I did everything what u wrote, but if I open the php-file phpinfo.php, gd-helloworld.php or sqlite-helloworld.php in my browser I get:

500 - Internal Server Error

Then the error.log gives me:

2007-04-16 15:42:40: (log.c.135) server stopped
2007-04-16 15:42:41: (log.c.75) server started
2007-04-16 15:44:44: (mod_cgi.c.553) cgi died, pid: 3181
2007-04-16 15:44:49: (mod_cgi.c.553) cgi died, pid: 3182

Maybe it is because I did not compiled all the files myselve? I got every file from http://www.ipkg.be/ .

(Last edited by Oconnor on 16 Apr 2007, 17:04)

Oconnor wrote:

I got every file from http://www.ipkg.be/ .

LOL. Sorry, but I'm not wasting my time. It's easy to build your own package repository using the Kamikaze build-system.

YOU *MUST* BUILD THE PACKAGES BY YOURSELF.

(Last edited by forum2006 on 16 Apr 2007, 18:13)

Hi, now I compiled the files myselve and almost everythink is workging, great!

The phpinfo.php and gd-helloworld.php page are working. But the sqlite-helloworld.php page isn't working, I get:

Warning: sqlite_open() [function.sqlite-open]: disk I/O error in /tmp/sda1/www/test/sqlite-helloworld.php on line 2
disk I/O error

instead of

array(2) { [0]=> string(13) "Hello, World!" ["bar"]=> string(13) "Hello, World!" }

I gave the file /tmp/sda1/www/test/mysqlitedb the rigths 777, but I still can't write in the DB.

(Last edited by Oconnor on 17 Apr 2007, 20:24)

I found PHP SQLite Admin it is working like php Myadmin. In order to install it you have to:


Session extension

ipkg install php5-mod-session_5.1.6-1_mipsel.ipk

Add or uncomment the following line in /etc/php.ini in section "Dynamic Extensions"

extension=session.so

Restart lighttpd web server

/etc/init.d/lighttpd restart

Download sqllite admin and untare it.


But I still can't write in the sqlite DB.

(Last edited by Oconnor on 17 Apr 2007, 20:24)

Sorry for trippel posting! I finaly got it working! I installed the wrong libsqlite.so.0.8.6 libary, because of that it didn't worked. Now it is working! That is great!

I tried to install PunBB forum and that is working too on my wgt634u!  smile smile smile

Thanks a million!

do you know how to add different ports with the same ip/url. for example add port 82 for test web server?

Thank you.

Can this howto be moved to "Howto" section, please?
In this way it's more easy to retrieve it.
Thanks.

Some questions here:

1) why is lighttpdphp running on port 81? Can't busybox httpd simply be disabled and thttpd take over all functions?

2) Why the www_1 directory?

3) Why does using these instructions cause mozilla to want to save the output of the php script instead of displaying it? This sounds like some mime-type mismatch to me

4) php embedded in html doesn't seem to work.

5) will enabling SSL work?

Seems PHP5 is broken at the moment sad

Fatal error: Balloc() allocation exceeds list boundary in /www/phpinfo.php on line 2

(Last edited by forum2006 on 19 Aug 2007, 21:11)

OK, so getting apache running w/ DSO is a mess, and lighttpd / php5 is broken, the question is, where to start hacking away? I need to get this working. If anyone else is seeing the problem I am seeing, or is having everything work fine, please tell me the specifics of your setup and I'll try to figure out where the hangup is.

Ok. Seems PHP 5.2.3 now only works on routers with >= 32 MiB RAM. 16 MiB seems to be to less to run PHP5.

(Last edited by forum2006 on 2 Sep 2007, 11:13)

You may try to decrease the number of FCGI children to 1, it will save some ram.

Anael

can i use functions like mcrypt_cbc and base64_encode in PHP scripts, with Kamikaze ?

has anyone now managed to run lighttpd with php5 on our kamikaze boxes of around 16MB Ram?

Hi,

I tried this perfect tutorial.
I tried with both php example files but received an error 403 Forbidden.
Then I tried with a simple classic index.htm and works perfectly.

Can somebody tell me what's wrong with those error ? How to solve it ?

Sincerely thanks,

Have a nice day,

Miguipda ;-)

I believe you have to set permissions for the php file to run.  I manage to set this up long ago on the hopes of serving up movies for my pinnacle showcenter however it just won't serve them up.  Neither did cherokee.

Anyone mind giving me any tips on if you can set that up to serve video files for swisscenter/oxyl/etc.  I'm thinking it is missing something that apache has but I have no clue.

(Last edited by loguser on 27 Oct 2008, 11:36)

Hi,

with an htm file it works (it display it) but for php files it doesn't display it.
Here are the files rights :

-rw-r--r--    1 root     root        53713 Jan  1 02:05 index.htm
-rwxrwxrwx    1 root     root           20 Jan  1 01:31 phpinfo.php
-rw-r--r--    1 root     root          317 Jan  1 01:46 sqlite-helloworld.php

How to solve it ?

Sincerely thanks.

Miguipda ;-)

Hi,

please I really need to solve this problem (error 403 forbidden for both example php files).

Have a nice day.

Miguipda ;-)

miguipda

What does your lighttpd log say?

Hi,

sorry I didn't have a look to. I will in fact have a look to know what's happend.

Have a nice day.

Miguipda ;-)

Thanks fo this very clear howto.

Lighttpd works with html files.
unfortunately, my phpinfo.php gives a blankpage.

My Lighttpd log says
"
2000-01-01 01:00:33: (log.c.75) server started
2009-03-03 14:22:48: (mod_cgi.c.1231) cgi died ?
"

I have :

lighttpd                1.4.18-2   
lighttpd-mod-cgi   1.4.18-2
php5                   5.0.5-1   
php5-cgi              5.0.5-1   
php5-mod-sqlite   5.0.5-1
libsqlite2              2.8.17-1   
libsqlite3              3.4.2-1

Any idea of wrong config ?

I have 2 different Libsqlite installed.
Libsqlite2 is depended upon by packages: php5-mod-sqlite
whereas Libsqlite3 is depended upon by packages: lighttpd.
Would this be the source of problems ?
Shall I uninstall one of them ?

(Last edited by nicolo on 3 Mar 2009, 15:43)

nicolo wrote:

Lighttpd works with html files.
unfortunately, my phpinfo.php gives a blankpage.

Most likely, you have an error in your lighttpd.conf. Check the name of the executable (it should be php-cgi and the right path), and for simple typos.
Also, try to run php-cgi -m from command line and make sure you don't get any errors

Good luck

Thanks ymhee_bcex

I am having a first look.

I am not sure to find a reference to an executable in the the lighttpd.conf file

There is the CGI section. I stated as mentioned in the tuto above the follwing
cgi.assign = ( ".php" => "/usr/bin/php" )
and the /usr/bin/php does exist (1.4MB)

I also noticed that in the lighttpd.conf file there was a reference to a file that I don't have.
## to help the rc.scripts
server.pid-file = "/var/run/lighttpd.pid"

But I don't know if it has ot been created yet or if it should exist already.

Soory to bother you with my dumb question. I would be very happy to see it work.

Cheers


PS. as soon as I can SSh the machine i will try un php-cgi -m from command line

The discussion might have continued from here.