PDA

Bekijk de volledige versie : lighttp and php tutorial



theboy50
10-05-2006, 16:03
I will do this i quick steps.

Install Lighttpd:

ipkg install lighttpd

Install Fast-CGI


ipkg install php-fcgi

Then you edit /opt/etc/lighttpd/lighttpd.conf
(I Use Joe editor so if you havnet install it do it by: "
ipkg install joe")

joe /opt/etc/lighttpd/lighttpd.conf

now start removing the # from

# "mod_fastcgi",


Change
server.document-root
to something like:

server.document-root = "/opt/share/www/"

change the accesslog.filename
to something like:
#### accesslog module

accesslog.filename = "/opt/share/www/log/access.log"

Add ".sqlite" to:

url.access-deny = ( "~", ".inc",".sqlite" )

Now the most importent thing is to change the FastCGI setting to this:


fastcgi.server = ( ".php" =>
((
"host" => "192.168.1.1",
"port" => 1026,
))
)

Hit
ctrl-k-x to save and exit

Next thing is to create the file
/opt/etc/init.d/S45php

So you make the file by doing

joe /opt/etc/init.d/S45php

and you put the following in it:


#!/bin/sh

export PHP_FCGI_CHILDREN=1
PORT=1026
BIN=/opt/bin/php-fcgi
#/opt/etc/php.d

case $1 in
start)
$BIN -b $PORT &
;;
stop)
kill Pidof phpM ;;
*)
echo "usage: $0 (start|stop)"
exit 1
esac
Save and exit: "
Ctrl-k-x"

Change the permission on it to make it executable:

chmod +x S45php

Now you can start it by:

./S45php start

or it will start when you reboot the next time


Thanks goes to Macsat for helping me to get it working on my unit

mmX
14-05-2006, 10:20
Hi theboy50,

thanks for this tutorial. I tried to get the lighttpd run with php support.
I did what you've explained in your tutorial, but everytime when I start
the lighttpd-server, the fast-cgi process was killed.

Then I tried to start the fast-cgi directly with the lighttpd:


fastcgi.server = (".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/opt/bin/php-fcgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "1",
"PHP_FCGI_MAX_REQUESTS" => "5000"
)
)
)
)


ps ax tells my that everything works fine:


168 admin 704 S /opt/sbin/lighttpd -f /opt/etc/lighttpd/lighttpd.conf
169 admin 1048 D /opt/bin/php-fcgi
170 admin 1048 D /opt/bin/php-fcgi
171 admin 1048 D /opt/bin/php-fcgi
172 admin 1048 D /opt/bin/php-fcgi


But after a few seconds ps ax tells me this:


168 admin 624 S /opt/sbin/lighttpd -f /opt/etc/lighttpd/lighttpd.conf
169 admin Z [php-fcgi]
170 admin Z [php-fcgi]
171 admin Z [php-fcgi]
172 admin Z [php-fcgi]


It seams that the motherprocess died and the child processes form php-fcgi are running as
zombies.


When I try to load a php file from the document-root I get the following error-message in the
error-log-file form the lighttpd:


2006-05-14 11:08:36: (mod_fastcgi.c.1739) connect failed: Connection refused on

unix:/tmp/php-fastcgi.socket-3
2006-05-14 11:08:36: (mod_fastcgi.c.2851) backend died, we disable it for a 5 seconds and send the request

to another backend instead: reconnects: 0 load: 1
2006-05-14 11:08:36: (mod_fastcgi.c.2624) child signaled: 10
2006-05-14 11:08:38: (mod_fastcgi.c.2430) unexpected end-of-file (perhaps the fastcgi process died): pid:

178 socket: unix:/tmp/php-fastcgi.socket-3
2006-05-14 11:08:38: (mod_fastcgi.c.3172) child signaled: 10
2006-05-14 11:08:38: (mod_fastcgi.c.3215) response not received, request sent: 862 on socket:

unix:/tmp/php-fastcgi.socket-3 for /index.php , closing connection


Any Idea why the fast-cgi process get killed after a few seconds?

I've installed the following packages, perhaps there is a package which makes trouble with fast-cgi:


Package: bash
Version: 2.05b-5
Depends: ncurses
Status: install user installed
Architecture: mipsel

Package: bzip2
Version: 1.0.3-5
Status: install user installed
Architecture: mipsel

Package: coreutils
Version: 5.2.1-9
Conflicts: busybox-links
Status: install user installed
Architecture: mipsel

Package: cron
Version: 4.1-4
Status: install user installed
Architecture: mipsel

Package: ctorrent
Version: 1.3.4-2
Depends: libstdc++, openssl
Status: install user installed
Architecture: mipsel

Package: esmtp
Version: 0.5.1-2
Depends: libesmtp
Conflicts: postfix
Status: install user installed
Architecture: mipsel

Package: expat
Version: 1.95.8-3
Status: install ok installed
Architecture: mipsel

Package: fontconfig
Version: 2.3.2-1
Depends: expat, freetype, gconv-modules
Status: install ok installed
Architecture: mipsel

Package: freetype
Version: 2.1.10-1
Depends: zlib
Status: install ok installed
Architecture: mipsel

Package: gconv-modules
Version: 2.2.5-5
Status: install ok installed
Architecture: mipsel

Package: gdbm
Version: 1.8.3-2
Status: install ok installed
Architecture: mipsel

Package: ipkg
Version: 0.99.149-2
Status: install user installed
Essential: yes
Architecture: mipsel

Package: less
Version: 394-1
Depends: ncurses
Status: install user installed
Architecture: mipsel

Package: libbt
Version: 1.05-4
Depends: libcurl, openssl, zlib
Status: install user installed
Architecture: mipsel

Package: libcurl
Version: 7.15.3-1
Status: install user installed
Architecture: mipsel

Package: libdb
Version: 4.2.52-3
Status: install user installed
Architecture: mipsel

Package: libesmtp
Version: 1.0.4-1
Status: install user installed
Architecture: mipsel

Package: libgd
Version: 2.0.33-2
Depends: libpng, libjpeg, freetype, fontconfig
Status: install ok installed
Architecture: mipsel

Package: libjpeg
Version: 6b-2
Status: install ok installed
Architecture: mipsel

Package: libpng
Version: 1.2.8-5
Depends: zlib
Status: install ok installed
Architecture: mipsel

Package: libstdc++
Version: 0.1.12-3
Depends: libuclibc++
Status: install ok installed
Architecture: mipsel

Package: libuclibc++
Version: 0.1.12-3
Status: install ok installed
Architecture: mipsel

Package: libxml2
Version: 2.6.23-1
Depends: zlib
Status: install user installed
Architecture: mipsel

Package: libxslt
Version: 1.1.15-5
Depends: libxml2
Status: install user installed
Architecture: mipsel

Package: lighttpd
Version: 1.4.11-2
Depends: pcre, zlib
Suggests: bzip2, libmemcache, lua, memcached, mysql, openldap, openssl
Status: install user installed
Architecture: mipsel

Package: lzo
Version: 1.08-2
Status: install ok installed
Architecture: mipsel

Package: mc
Version: 4.1.35-2
Depends: ncurses
Status: install user installed
Architecture: mipsel

Package: microperl
Version: 5.8.6-3
Status: install user installed
Architecture: mipsel

Package: ncurses
Version: 5.5-1
Status: install user installed
Architecture: mipsel

Package: openssl
Version: 0.9.7d-4
Status: install user installed
Architecture: mipsel

Package: pcre
Version: 5.0-5
Status: install ok installed
Architecture: mipsel

Package: php
Version: 5.1.4-1
Depends: bzip2, openssl, zlib, libxml2, libxslt, gdbm, libdb
Status: install user installed
Architecture: mipsel
Conffiles:
/opt/etc/php.ini 211ce782fa34ea1da50a564a63094fe3
Installed-Time: 1147542320

Package: php-fcgi
Version: 5.1.4-1
Depends: php (5.1.4), pcre
Status: install user installed
Architecture: mipsel

Package: php-mysql
Version: 5.0.3-13
Depends: php, mysql
Status: install user not-installed
Architecture: mipsel

Package: php-mysql
Version: 5.0.3-12
Depends: php, mysql
Status: install user not-installed
Architecture: mipsel

Package: php-thttpd
Version: 2.25b-5.0.3-5
Depends: php
Conflicts: thttpd
Status: install user not-installed
Architecture: mipsel

Package: php-thttpd
Version: 2.25b-5.1.4-1
Depends: php (>= 5.0.3-8), libxml2
Conflicts: thttpd
Status: install user installed
Architecture: mipsel

Package: poptop
Version: 1.2.1-1
Status: install user installed
Architecture: mipsel

Package: readline
Version: 5.0-2
Status: install ok installed
Architecture: mipsel

Package: screen
Version: 4.0.2-2
Depends: termcap
Status: install user installed
Architecture: mipsel

Package: termcap
Version: 1.3.1-2
Status: install ok installed
Architecture: mipsel

Package: torrent
Version: 1.3-8
Depends: libbt, coreutils
Status: install user installed
Architecture: mipsel

Package: vsftpd
Version: 2.0.1-7
Status: install user installed
Architecture: mipsel

Package: xinetd
Version: 2.3.13-4
Status: install user installed
Architecture: mipsel

Package: zlib
Version: 1.2.2-2
Status: install user installed
Architecture: mipsel


Thankx.

Best regards

mmX

theboy50
16-05-2006, 13:20
I'm sorry. I don't know why that is.
People are saying that php has ben updated and there are some proplems with it. Meaby thats the reason.

Japie
16-05-2006, 20:04
hmm i think i had the same problem a while ago.
the solution was to change the socket path to a directory within the /opt directory.
hope this helps you!


"socket" => "/opt/tmp/php-fastcgi.socket"

mmX
17-05-2006, 19:23
I'd already tried to change the socket-path into the /opt area, but it doesn't help. After a few minutes the fcgi process becomes zombies.:rolleyes:

A also reinstalled all necessary packages.

Any ideas? :confused:

Thanks.

mmX

NLBADB0Y
24-06-2006, 16:20
Ok i did everything as described in the tutorial but lighttpd won't start. What am I doing wrong?? I already tried changing the S80lighttpd config file to what is on the mascat page but this also did not help.

What do I need to change ???



[NLBADB0Y@WL500g root]$ ps ax
PID Uid VmSize Stat Command
1 NLBADB0Y 416 S /sbin/init
2 NLBADB0Y SW [keventd]
3 NLBADB0Y RWN [ksoftirqd_CPU0]
4 NLBADB0Y SW [kswapd]
5 NLBADB0Y SW [bdflush]
6 NLBADB0Y SW [kupdated]
7 NLBADB0Y SW [mtdblockd]
39 NLBADB0Y 276 S telnetd
44 NLBADB0Y 452 S httpd eth1
48 NLBADB0Y 312 S syslogd -m 0 -O /tmp/syslog.log -S -l 7
49 NLBADB0Y 288 S klogd
52 nobody 380 S dnsmasq
54 NLBADB0Y 248 S nas /tmp/nas.lan.conf /tmp/nas.lan.pid lan
57 NLBADB0Y SW [khubd]
67 NLBADB0Y 184 S lpd
69 NLBADB0Y 188 S p9100d -f /dev/usb/lp0 0
71 NLBADB0Y 188 S p9101d -f /dev/printers/0 1
74 NLBADB0Y 240 S waveservermain
78 NLBADB0Y SW [usb-storage-0]
79 NLBADB0Y SW [scsi_eh_0]
84 NLBADB0Y 280 S infosvr br0
85 NLBADB0Y 428 S watchdog
89 NLBADB0Y 268 S ntp
95 NLBADB0Y SW [kjournald]
102 NLBADB0Y 4116 S /opt/bin/php-fcgi -b 1026
120 NLBADB0Y 356 S udhcpc -i eth1 -p /var/run/udhcpc0.pid -s /tmp/udhcpc
126 NLBADB0Y 4208 S /opt/bin/php-fcgi -b 1026
132 NLBADB0Y 496 S upnp -D -L br0 -W eth1
134 NLBADB0Y 528 S -sh
137 NLBADB0Y 388 R ps ax
[NLBADB0Y@WL500g root]$

VidJa
12-07-2006, 11:39
I see that you have libgd installed. It kills my thttpd server (actually anything that works with libgd) So if you have your scripts accessing libgd that might be the problem (firmware 7e)

LinusW
07-12-2006, 19:35
Hi, thanks for the great guide

I have a problem though, since changing from thttpd to lighttpd, .cgi pages have stopped working. PHP support works excellent. When trying to access a cgi page, firefox asks if I want to save the file and ie goes 500-internal server error. I have no idea on how to fix this, please help.

MMCM
08-12-2006, 11:24
Hi, thanks for the great guide

I have a problem though, since changing from thttpd to lighttpd, .cgi pages have stopped working. PHP support works excellent. When trying to access a cgi page, firefox asks if I want to save the file and ie goes 500-internal server error. I have no idea on how to fix this, please help.

Maybe the CGI script does not return valid http headers?

Install "Live http headers" for firefix and see what it returns.

I'm using lighttpd with cgi shell scripts without a problem.

LinusW
10-12-2006, 19:49
Was not able to check headers in firefox, since it only wants to d/l the file. However, in ie, the headers seem to be proper, but as far as i can see, the cgi-script doesn't work.

wkwong
04-03-2007, 09:31
I also had this issue after install lighttpd. In my case, change ".cgi" => "/bin/sh" in CGI module section in ligthttpd.conf solve the problem.

#### CGI module
cgi.assign = ( ".pl" => "/opt/bin/perl",
".cgi" => "/bin/sh" )

Hope this help.

sarlacc
06-06-2007, 14:44
I have lighttp + php + MySQL working on Asus wl-500gP except PHP sessions.
Directory
/opt/var/lib/php/session exists and contains some session files but I can't use session in web browser. What item should I check in php.ini and/or lighttpd.conf?
I prefer
session.use_cookies =0 but ...

php.ini session part:

[Session]
; Handler used to store/retrieve data.
session.save_handler = files

; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
session.save_path = /opt/var/lib/php/session

; Whether to use cookies.
session.use_cookies = 1

; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1

; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = /

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php

; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.

session.gc_probability = 1
session.gc_divisor = 1000

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning separately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.

session.bug_compat_42 = 1
session.bug_compat_warn = 1

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public,} to determine HTTP caching aspects.
; or leave this empty to avoid sending anti-caching headers.
session.cache_limiter = nocache

; Document expires after n minutes.
session.cache_expire = 180

; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = 0

; The URL rewriter will look for URLs in a defined set of HTML tags.
; form/fieldset are special; if you include them here, the rewriter will
; add a hidden <input> field with the info which is otherwise appended
; to URLs. If you want XHTML conformity, remove the form entry.
; Note that all valid entries require a "=", even if no value follows.
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentr y"

sarlacc
21-06-2007, 23:17
I can see session variables stored in files (like sess_xxxxxxxxxxxx...) in
/opt/var/lib/php/session/ - it seems to be ok, but when I want do use them (on other php page for instance) nothing happens; content of variables isn't displayed with echo command.


There is everything ok on my local testing Xampp web server, so I hope php code is correct. I really don't know. Any idea? Maybe permissions? Please.

sarlacc
30-06-2007, 00:46
Nobody uses php sessions? !!Please help me set up lighttp to work with cookies - thats the problem!!!
It works with SID in URL. with cookies not.Thanks

raas
21-09-2007, 11:29
@sarlacc,


did you ever solve this problem?
right now i'm experiencing the same problem.
I have a CMS running on the webserver with a mysql-db. however. when i want to log into the admin section of that cms. it refuses. because the session variable isn't filled with the admin flag.

It seems to me that this problem is solved when the session variables work.

i've tried chmod 777 /opt/var/lib/php/session but that didn't work.

TIA

raas
27-09-2007, 22:20
Hi..

i've solved the problem (at least my case)

I've set register_globals to on in php.ini
restarted webserver.
and the sessions worked.

now the cms allows me to log in.

Aramaki
27-10-2007, 14:12
Hi..

i've solved the problem (at least my case)

I've set register_globals to on in php.ini
restarted webserver.
and the sessions worked.

now the cms allows me to log in.

that's bad cms that works only with register_globals=on

MMCM
27-10-2007, 14:41
Hi..

i've solved the problem (at least my case)

I've set register_globals to on in php.ini
restarted webserver.
and the sessions worked.

now the cms allows me to log in.

Enabling register_globals is a serious security threat to every web site.
Don't do that.

There are various exploits based on having register_globals on.

fungo
30-10-2007, 13:27
I installed lighttpd some days ago and it works fine on my asus wl 500g but now I tried to add the php-fcgi extension.

Installation runs fine but while I am starting the server I get get a php error concerning the libiconv.so.2 file. Looking for solutions I found to install the ipkg package libiconv but this one is no more available. So what to do? I tried everything but how to get this file?

Thanks

raas
04-11-2007, 19:56
Enabling register_globals is a serious security threat to every web site.
Don't do that.

There are various exploits based on having register_globals on.

Ok... didn't know that.. more of a M$ person here..

Is there another way to get the session variables working?

TIA

Aramaki
05-11-2007, 10:21
Ok... didn't know that.. more of a M$ person here..

Is there another way to get the session variables working?

TIA

As i wrote - take another CMS. modx for example, or typo3, nx-system etc.

raas
05-11-2007, 16:01
@Aramaki,


ok.. thank you.. I will look into that !
(I hope they perform as good as the one I have now)

Anyway.

Thank you all for the heads-up !!
(I thought I was learning linux a bit and was quite happy when I 'solved' the problem and got the CMS running.. However.. I have not realised the security threats which came along, but that's why you gurus are here.. many thanks again.)

Aramaki
06-11-2007, 16:55
@Aramaki,
ok.. thank you.. I will look into that !
(I hope they perform as good as the one I have now)


these 3 are the best from opensource (freeware). IMHO. But I chose modx

And they ALL need some stuff to learn - it's not a 5 minute tutorial to get all power from it.

typo3 is too complex for user and irrational for programmer

nx is very nice but updates not very frequently and has some inconvenient points

emes
07-11-2007, 09:13
I followed the tutorial and ran into a problem.


>> php -v
Segmentation fault

Similarly for php-fcgi

Admittedly it worked right after I installed it, but stopped working after a reboot.


using PHP version 5.2.4-1 from Olegs repo.

Anyone remedy this problem somehow?

freakazoid
25-11-2007, 19:24
mine problem is with the starting of php...

when i try to start it this it what appears:

Cannot bind/listen socket - [125] Address already in use.
Couldn't create FastCGI listen socket on port 1026


Can anybody help me?

raas
26-11-2007, 11:32
@Aramiki


I've installed MODx and corrected the faulty setting of register_globals ..

Everything works fine.

btw.. MODx is a much nicer CMS than I had currently installed, so I'm very happy, thanks again.

Greetz,

raas
11-12-2007, 22:58
Hi,

I'm having a problem with the modx install on my asus.
the website is running fine, can make pages etc. but,

if i create a link in a page to /Foto (a dir which has dir browsing on after a login) the link is saved wrong.

depends on which side of the network I am.
If I'm on my internal network the link is: http://192.168.1.1:8082/Foto

but when I connect externally and I want to click the link it still says: http://192.168.1.1:8082/Foto instead of: http://my.dns.com/Foto

If I then edit the link externally again to /Foto and save the page, all is ok as long as I stay externally, but when I'm on my internal network again, and open the webserver and want to click the foto link it says: http://my.dns.com/Foto instead of: http://192.168.1.1:8082/Foto

So my guess is that somehow the http_referer is somehow copied to links beginning with an / to the server.

I don't really know if it's modx or php, I was experiencing the same behaviour with my previous cms.


Does anyone have a clue where to look?

Thanks in advance !

freakazoid
31-12-2007, 09:13
Hi,

first, thank you for the tutorial...
and now ive uninstalled the php and tried to reinstall it again, using the same method. it all works fine except when i try to run it it states:

[admin@(none) init.d]$ ./S45php start
[admin@(none) init.d]$ ./S45php: ./S45php: 17: /opt/bin/php-fcgi: not found

i dont know why does it says that because the file is there! and the "S45php" file is copyed from your tutorial.

ps:when i was reinstaling it, i dont think i removed it completely... i used "ipkg remove php and php-fcgi" command. dont know if thats enough...

cheers

raas
17-01-2008, 13:11
Hi,

My answer to my own question about modxcms (a very nice cms!).:

I''ve ditched the whole idea about running modx on my asus.

I couldn't resolve the problem I was having with the internal and external links.

I tracked the problem down to the 'base href' which modx creates in it's generated html output, if it wasn't for this base href, modx would be a 'near perfect' system. but I couldn't get the base href out of modx.

That's why I've switched to AIOCP (www.aiocp.com)

This one works on the internal side of the network, as well as on the external side of the network.

It's more than I needed, (it's more like a website management system), but it does what I want it to do.

piezomotor
30-01-2008, 18:03
Hi, I have installed PHP and lighttpd.

I moved my web site from the Hosting site to my WL500gP...

As the result the feedback form PHP script (shown below) does not work...-

http://www.thesitewizard.com/wizards/

Any idea why?

Thanks.