PDA

Bekijk de volledige versie : Complete detailed guide for PHP enabled webserver + ssh server.



macsat
17-04-2005, 15:38
Changelog :

29-06-2005
+ CRON job scheduling system tutorial added

16-06-2005
+ SAMBA tutorial added

25-05-2005
+ esmtp tutorial added
# php webserver tutorial split in two :
1. php enabled webserver
2. ipkg package system tutorial

18-05-2005
+ Hardware comparison table added

11-05-2005
+ Added a page with general information about Olegs Firmware
+ Added a complete guide for setting up a Cross Compiling Build Environment

10-05-2005
# Username related error in the vsftpd guide corrected.

02-05-2005
+ Added a complete vsftpd guide

29-04-2005
+ Added a small guide in howto enable perl .pl / .cgi scripts

28-04-2005
# Switched from thttpdphp to php-thttpd
# Changed webroot to comply with Unslung standards
# Corrected small error in setting eXecutable flag (thanks rdk)

+ Added a small ssh-server only guide as well.

----
http://macsat.com/wlguide/index.php
----

I just made a complete and quite detailed guide on how to make your ASUS WL device into a full featured PHP enabled webserver, and a ssh server.

The guide should be usuable even for people that dont know linux in advance !!

The Guides Include :
*PHP enabled webserver + ssh server guide
*ssh server guide

Link :
http://macsat.com/wlguide/index.php

britnet
28-04-2005, 13:16
Had somebody test this guide?

Jean-Fabrice
28-04-2005, 14:01
This howto is very nice and complete. Thank you macsat !

Just a few things:
1) phpthttpd is now obsolete.
Instead of running


cd /opt/tmp < enter >
wget http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/thttpdphp_2.25b-5.0.3-1_mipsel.ipk < enter >
/opt/bin/ipkg install thttpdphp_2.25b-5.0.3-1_mipsel.ipk < enter >
rm thttpdphp_2.25b-5.0.3-1_mipsel.ipk < enter >




ipkg install php-thttpd < enter >


This will install thttpd with php support plus the full php package (giving you additionnals modules)

2) webroot *should* sits under /opt/share/www.
Unslung staff makes this (arbitrary) choice so that web-related packages can all rely on this dir at install time. storing your webroot somewhere else will not guarantee that web-related package will be web visible once installed.


JF

britnet
28-04-2005, 14:05
Thank you,

can i change the www files via ftp?

macsat
28-04-2005, 14:08
Hi Jean-Fabrice

Thanks for the nice words.

The thttpd package thing will be updated soon, and also the placement of the www dir :-)

Will keep people posted in here.

/macsat

rdk
28-04-2005, 15:06
Hi Macsat

I ve also used this howto and found it very useful to learn how the ipkg stuff works :) Thank you!

Its just at one place where you put

mkdir /usr/local < enter >
mkdir /usr/local/sbin < enter >
touch /usr/local/sbin/post-boot < enter >
touch /usr/local/sbin/post-firewall < enter >
=>>> chmod -x /usr/local/sbin/* < enter >

Shouldn't this last line be chmod +x ??
At least thats what worked for me....

The rest was fine :)

Regards,
Rainer

macsat
28-04-2005, 16:22
Yes, you are right....a little mistake there.

Will be fixed ASAP :-)

britnet
29-04-2005, 07:40
Cool,

you changed your How To Site.

Its really nice.

Can you do this guide in PDF,too?
It's much more better to print.
(because of the grey backgrounds)


Regards,
britnet

Antiloop
29-04-2005, 08:55
Cool,

you changed your How To Site.

Its really nice.

Can you do this guide in PDF,too?
It's much more better to print.
(because of the grey backgrounds)


Regards,
britnet
please see attached

rwhitby
29-04-2005, 11:16
macsat,

Great HowTo's :-)

-- Rod

[Edit: didn't see the nslu2-linux links at first cause they were black, but realised they are all there - thanks.]

mullog
01-05-2005, 13:31
thx for the guide. all works fine except access from wan.
Am I supposed to have the firewall enabled in web setup?

kdudl
01-05-2005, 16:01
thx for the guide. all works fine except access from wan.
Am I supposed to have the firewall enabled in web setup?

I had the same problem. The solution was to take port 80 in the list of the virtual servers (under NAT Settings):
Port range: 80
Local IP: local IP address of the router
Local port: the port number you have chosen for local access to your web server
Protocol: TCP

I do not know if it it is the unique solution (and the best ?) but it works. May be the (excellenet) howto could be updated with this point.

macsat
01-05-2005, 19:50
I will update the howto with that little note, thanks for pointing out :-)

Bartjuh
09-05-2005, 14:03
Is there some kind of version of mysql included? Lite or something?

Thanks in advance! :)

FOXTREE
09-05-2005, 14:25
guide vsftpd not working

Status & Log - System Log

May 9 17:24:14 xinetd[126]: Unknown user: root [file=/opt/etc/xinetd.d/vsftp] [line=7]
May 9 17:24:14 xinetd[126]: Error parsing attribute user - DISABLING SERVICE [file=/opt/etc/xinetd.d/vsftp] [line=7]
May 9 17:24:14 xinetd[126]: 126 {init_services} no services. Exiting...

barsju
09-05-2005, 14:41
try changing user from root to admin

S.

britnet
09-05-2005, 15:57
Are there any changes in the guide refered to the new version of Oleg's Firmware?

macsat
10-05-2005, 17:17
Hi guys

Sorry for keeping you in the dark, I have been away on a conference for a couple of days, so I havent been able to check my mail / this forum.

Foxtree : The username in /opt/etc/xinetd.d/vsftp should be the same as your login on the admin webpages on your router. I kindda forgot that :-) Thanks for "finding" that little error for me.

Britnet : CR5 of the Oleg firmware, should have no impact on my guides.

FOXTREE
11-05-2005, 08:22
The following problem guide vsftpd.
The problem is obviously connected with access rights.
At installation in line vsftpd.conf anonymous_enable=YES, client is not connected also by the administrator and anonymous. If anonymous_enable=NO that the administrator enters. How to solve the given problem ?

Forgive me for my English. I as a dog - understand all, but I can not tell. :)

britnet
11-05-2005, 09:07
Hello,

yesterday i installed the whole thing.

Then i create a test page like:

index.php/htm

<? phpinfo(); ?>

How is this site reachable from the internet?
A friend of me said, he could not reach the Site.

britnet
12-05-2005, 16:13
Hello,

sorry but I have another question:

How can I copy my webfiles in the www directory?

FOXTREE
12-05-2005, 18:04
Install vsftpd

Styno
13-05-2005, 07:18
Hello,

sorry but I have another question:

How can I copy my webfiles in the www directory?
FTP them to your WL-500g and then copy them to the /opt/share/www directory

britnet
13-05-2005, 08:30
FTP them to your WL-500g and then copy them to the /opt/share/www directory

Thank you,

should i ftp to my.router or to my "external ip" ?

Another Question?
Why is there no Samba?

FOXTREE
13-05-2005, 09:37
1.It is possible both external and internal IP to give
2.It is possible and SAMBA. But it in 2 times more slowly ftp.

rdk
19-05-2005, 18:30
Hi

I have the php server running. But I cannot use it as I would like to:

I also installed sqlite via ipkg. I have created a db called wordpress.db with sqlite3

I have download wordpress blogging system and sqlite patch (to be found here:http://elizabethmariesmith.com/?p=19)

With no php.ini file in /opt/etc I have errors, mostly session errors trying to write to /tmp (this directory is write enabled?!)

I really want to get this working, I have then taken the php-dist.ini and php recommended file from a php5 distribution and copied to /opt/etc because I didn't have a php.ini there (phpinfo() shows the path but no the file)

I have also changed the extensions path in php.ini to /opt/lib/php/extensions to be able to use the gd functions installed. What else has to be changed to run smoothly on the wl500g?!

But I still get some weird errors mostly:

With sqlite admin:
Undefined index: DOCUMENT_ROOT in .....

With wordpress installation:
Fatal error: main() [function.require]: Failed opening required '/opt/share/www/wordpress/wp-includes/functions.php' (include_path='.:')

Can someone post his php.ini file that he is using? Thanks a lot :-) Maybe you could even add this to your guide...

Regards,
Rainer

Styno
19-05-2005, 18:59
With no php.ini file in /opt/etc I have errors, mostly session errors trying to write to /tmp (this directory is write enabled?!)
I have the same problem with many websites which write session/lock/cache files to /tmp. I believe it's cause because the 'nobody' user (which is used to run the webserver) does not have write access to /tmp.

Do a chmod 777 on tmp and try again, or run the webserver using the admin account (security risk!).

rdk
19-05-2005, 22:22
I have the same problem with many websites which write session/lock/cache files to /tmp. I believe it's cause because the 'nobody' user (which is used to run the webserver) does not have write access to /tmp.

I have done a chown nobody /opt/tmp and also chmod 777 or even 6777 the tmp

But when I take the recommended php ini file from php5 distro not the php dist file then these errors seem to go away, but the other errors then occur:

Undefined index: DOCUMENT_ROOT

and include_path='.:'

How has a working php.ini for wl500g?? Or maybe someone can share some tips on howto run php without errors ?!

Regards,
Rainer

macsat
25-05-2005, 17:46
I have now added a esmtp tutorial to my page.

This will enable you to make the router send out mails....very useful for php pages, perl scripts and certail server programmes, that likes to send status mails.

Tutorials I am considering making :
- crontab
- samba (windows drive / folder sharing)
- multi user setup

I would like comments, both on existing turorials / guides, and on future plans....

Regards
macsat

barsju
26-05-2005, 09:13
Well, for crontab there is a little howto being discussed at the moment, so you're more then welcome to use my example there atleast. http://wl500g.info/showthread.php?t=1058

And a nice tutorial I have been contemplating writing is about SSH tunneling/port forwarding, which is great for accessing local network safely. With dropbear setup there is actually nothing more that needs configuring on the server so it's all just learning how to use the ssh client (like putty). I use it for http access to admin pages, Remote Desktop on LAN pc, Samba to LAN PC..

As for tunneling samba traffic, I found a neat trick on the net. http://www.blisstonia.com/eolson/notes/smboverssh.php
The problem is that in windows you cannot samba to an other port than 139. Thus you need to turn off local sharing to connect through localhost:139. But this trick solves that problem by setting up a new loopback adapter.

Good work! Keep it up!
B.

keke
28-05-2005, 20:59
I would like comments, both on existing turorials / guides, and on future plans....
t
Hi! Your tutorials are excellent. I'm voting for a ctorrent tutorial, it would be great to have console torrent client on wl500.

Thanks again for great tutorials

macsat
28-05-2005, 21:41
It seems like all you need to do to get torrent running is :


ipkg install torrent

Then you use the command :


btget filename.torrent

or


btget -h http://www.somedomain.com/filename.torrent

I havent testet it much, but it seems to be "it"

macsat
16-06-2005, 17:06
Hi guys

I have added a simple SAMBA tutorial on my page.

/macsat

dragonstyle
19-06-2005, 02:45
I got a few problems:

- Everytime when the webserver is running it dies after 40 minutes or less. When I open the site it says failed to connect. I've tried reinstall everything but that didn't help.

- I've installed vsftpd. Everytime when I try to connect with a ftp client it says: "500 OOPS: vsftpd: not found: directory given in 'secure_chroot_dir':/usr/share/empty"

I hope someone can help me with this.

sup
19-06-2005, 21:27
so just make that directory;-). I suppose you followed macsat guides and you are using some kind of usb storage device. You have it mounted somewhere - you can find out where by typing
df in telnet - if you followed the guide, it should be mounted as /opt, so just make the directory
mkdir /opt/usr/share/empty
and then change the value in secure_chroot_dir=/usr/share/empty (if you already created it) vsftpd config file via some text editor to this :
secure_chroot_dir=/opt/usr/share/empty
(you cannot just make the directory in /usr/share/empty - it is a directory directly in your asus device and cannot be so easilly changed if ever, I guess - just hoping I am not doing any FUD)

dragonstyle
20-06-2005, 00:13
The directory already excists. I've tried to put "secure_chroot_dir=/opt/usr/share/empty" in the config files but it still doesn't work.

I still got disconnection problems with the webserver
Log:
click here (http://home.wanadoo.nl/zhao/log.txt)

sup
23-06-2005, 21:01
I installed thttpd and it is running fine and I can see the web from the LAN side, but not from the WAN side, unless I completle disable the firewall via the webinterface. Otherwise, the server cannot be found - even when I opened ports 1:65535 both ways (LAN>WAN and WAN>LAN).
the log says this:

Jun 23 21:46:36 kernel: DROPIN=eth1 OUT= MAC=00:11:2f:86:8e:f0:00:80:48:1e:6b:84:08:00 SRC=194.108.97.134 DST=10.102.236.214 LEN=48 TOS=0x00 PREC=0x20 TTL=115 ID=6375 DF PROTO=TCP SPT=1713 DPT=8080 SEQ=1399993079 ACK=0 WINDOW=8192 RES=0x00 SYN URGP=0 OPT (0204057001010402)
Jun 23 21:46:36 kernel: DROPIN=eth1 OUT= MAC=00:11:2f:86:8e:f0:00:80:48:1e:6b:84:08:00 SRC=194.108.97.134 DST=10.102.236.214 LEN=48 TOS=0x00 PREC=0x20 TTL=115 ID=6375 DF PROTO=TCP SPT=1713 DPT=8080 SEQ=1399993079 ACK=0 WINDOW=8192 RES=0x00 SYN URGP=0 OPT (0204057001010402)
Jun 23 21:46:44 kernel: DROPIN=eth1 OUT= MAC=00:11:2f:86:8e:f0:00:80:48:1e:6b:84:08:00 SRC=194.108.97.134 DST=192.168.1.1 LEN=48 TOS=0x00 PREC=0x20 TTL=115 ID=6376 DF PROTO=TCP SPT=1714 DPT=81 SEQ=2333953345 ACK=0 WINDOW=8192 RES=0x00 SYN URGP=0 OPT (0204057001010402)
194.108.97.134 being the adress os the computer I am trying to access the web (it is dynamic;-)), 10.102.236.214 being the adress of my router (I am connected through a private network, however, I have got a public IP adress, which is assigned at the gateway - at least I think so) 192.168.1.1 being adress of the router.

I have no idea how to solve this problem - can you help me?(or at least explain, what those records in log mean?)

macsat
24-06-2005, 05:21
Hi

did you try : http://my.router:81

?

If this works, what you need is to make the ipfirewall script that forwards all incoming traffic in port 81 to port 80 :

#!/bin/sh
iptables -D INPUT -j DROP
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i $1 -p tcp --dport 80 -j DNAT --to-destination $4:81

iptables -A INPUT -j DROP

Regards
macsat

sup
24-06-2005, 07:01
Tried that and it ain`t working either. I believe it has something to with the firewall itself, not with forwarding ports since as I have said, when I disable firewall, I can access the web from the internet and when I enable it (with all ports opened!), it is inaccesible:-/.(I can access the web pages from LAN all the time)

(however - using virtual server, port range 80, local IP 192.168.1.1 local port 80, protocol TCP should do the same as your script, am I right?)

macsat
24-06-2005, 10:50
No, you are not right :-)

The important thing is that the web server it self listens @ port 81.

You need to configure your router to forward all port 80 requests to internal ip port 81....this is the trick.

when logged on to the router using telnet, try to run the following and copy-paste me the output :


ps

sup
24-06-2005, 14:19
Oh stupid me, of course, I was thinking 81 but I wrote 80 - what was I thinking about:-)?

The log is here, seems to me like thttpd is running allright?:
PID Uid VmSize Stat Command
1 admin 336 S /sbin/init
2 admin SW [keventd]
3 admin SWN [ksoftirqd_CPU0]
4 admin SW [kswapd]
5 admin SW [bdflush]
6 admin SW [kupdated]
7 admin SW [mtdblockd]
41 admin 276 S telnetd
46 admin 324 S httpd eth1
49 admin 296 S klogd
53 nobody 388 S dnsmasq
54 admin 312 S syslogd -m 0 -O /tmp/syslog.log -S -l 7
59 admin SW [khubd]
69 admin 184 S lpd
71 admin 188 S p9100d -f /dev/usb/lp0 0
73 admin 188 S p9101d -f /dev/printers/0 1
76 admin 216 S waveservermain
80 admin SW [usb-storage-0]
81 admin SW [scsi_eh_0]
86 admin 224 S infosvr br0
89 admin 420 S watchdog
91 admin 248 S ntp
106 admin 300 S udhcpc -i eth1 -p /var/run/udhcpc0.pid -s /tmp/udhcpc
115 admin 772 S /usr/sbin/nmbd -D
117 admin 644 S /usr/sbin/smbd -D
123 admin SW [kjournald]
133 admin 300 S /opt/sbin/xinetd
146 nobody 3320 S /opt/sbin/thttpd -C /opt/etc/thttpd.conf
157 admin 464 S upnp -D -L br0 -W eth1
159 admin 524 S -sh
161 admin 392 R ps
[admin@wl500g root]$ ps
PID Uid VmSize Stat Command
1 admin 328 S /sbin/init
2 admin SW [keventd]
3 admin SWN [ksoftirqd_CPU0]
4 admin SW [kswapd]
5 admin SW [bdflush]
6 admin SW [kupdated]
7 admin SW [mtdblockd]
41 admin 280 S telnetd
46 admin 324 S httpd eth1
49 admin 296 S klogd
53 nobody 388 S dnsmasq
54 admin 312 S syslogd -m 0 -O /tmp/syslog.log -S -l 7
59 admin SW [khubd]
69 admin 184 S lpd
71 admin 188 S p9100d -f /dev/usb/lp0 0
73 admin 188 S p9101d -f /dev/printers/0 1
76 admin 208 S waveservermain
80 admin SW [usb-storage-0]
81 admin SW [scsi_eh_0]
86 admin 224 S infosvr br0
89 admin 400 S watchdog
91 admin 240 S ntp
106 admin 296 S udhcpc -i eth1 -p /var/run/udhcpc0.pid -s /tmp/udhcpc
115 admin 764 S /usr/sbin/nmbd -D
117 admin 520 S /usr/sbin/smbd -D
123 admin SW [kjournald]
133 admin 304 S /opt/sbin/xinetd
146 nobody 3320 S /opt/sbin/thttpd -C /opt/etc/thttpd.conf
157 admin 460 S upnp -D -L br0 -W eth1
159 admin 524 S -sh
163 admin 392 R ps
the thttpd.conf is here:
dir=/opt/share/www
port=81
user=nobody
nochroot
nosymlink
novhost
logfile=/opt/var/log/thttpd.log
# Please do not edit pidfile path at it is use to kill thttpd process during ini

pidfile=/opt/var/run/thttpd.pid

sup
25-06-2005, 19:37
I tried formating the disk and complete reinstalling of the ipkg package, but it did not help at all. However, during the instalation of thttpd, this erorr mesagge appeared(at the bottom, I am posting a complete log of the instalation):
[admin@wl500g root]$ /opt/bin/ipkg install php-thttpd
Installing php-thttpd (2.25b-5.0.3-9) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/php-thttpd_2.25b-5.
0.3-9_mipsel.ipk
Installing php (5.0.3-13) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/php_5.0.3-13_mipsel
.ipk
Installing bzip2 (1.0.2-4) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/bzip2_1.0.2-4_mipse
l.ipk
Installing openssl (0.9.7d-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/openssl_0.9.7d-3_mi
psel.ipk
Installing zlib (1.2.2-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/zlib_1.2.2-2_mipsel
.ipk
Installing libxml2 (2.6.17-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/libxml2_2.6.17-3_mi
psel.ipk
Installing libxslt (1.1.12-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/libxslt_1.1.12-3_mi
psel.ipk
Installing gdbm (1.8.3-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/gdbm_1.8.3-2_mipsel
.ipk
Installing libdb (4.2.52-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/unslung/wl500g/libdb_4.2.52-2_mips
el.ipk
can't get //opt/lib/ipkg/info/libdb.control open for read
Configuring bzip2
Configuring gdbm
Configuring libdb
Configuring libxml2
Configuring libxslt
Configuring openssl
Configuring php
Configuring php-thttpd
/opt/bin/update-alternatives: 185: dirname: not found
update-alternatives: Linking //opt/sbin/htpasswd to /opt/sbin/php-thttpd-htpassw
d


To complete the installation, you must edit /opt/etc/thttpd.conf,
and then run /opt/etc/init.d/S80thttpd to start thttpd.

Configuring zlib
Successfully terminated.
Collected errors:
Unable to open the control file in set_flags_from_control
Google said nothing about it, can you say if it si something important?

sup
26-06-2005, 18:23
also, this is part of my starting log - does it mean something? especially this:"bind 0.0.0.0 - Address already in use"?


Jun 26 19:20:15 thttpd[145]: bind 0.0.0.0 - Address already in use
Jun 26 19:20:22 thttpd[145]: thttpd/2.25b PHP/5.0.3 starting on port 81
Jun 26 19:20:22 thttpd[145]: started as root without requesting chroot(), warning only

macsat
30-06-2005, 07:18
Hi

I have written a complete Tutorial on how to install and configure cron for running scheduled jobs on your ASUS.

I have set up a cron-system that is kindda "RedHat-like", and very easy to use even for non-advanced users, once it has been setup by completing the Tutorial :-)

frankd
30-06-2005, 10:42
Hi macsat,

thanks for another fine tutorial.

a few questions:

- what is "root" supposed to be in a crontab line? is it part of the command?

- i have running a crond already, it uses a uses specific crontab e.g.
/tmp/var/spool/cron/crontabs/admin

this other crontab seems to have the standard crontab format. It runs fine.

[admin@DELTA /tmp]$ cat /tmp/var/spool/cron/crontabs/admin
# 0 * * * * cp /opt/var/log/tcpdump.log /tmp/harddisk/LOG/TCP/tcpdump.tmp-$$
# 0 * * * * cp /opt/var/log/syslog.log /tmp/harddisk/LOG/SYS/syslog.tmp-$$
# 0 * * * * cp /opt/var/log/vsftpd.log /tmp/harddisk/LOG/FTP/vsftpd.tmp-$$
# 2 * * * * cat /opt/ftp.mai /opt/var/log/vsftpd.log | sendmail xxxxxxxxxxxx@gmail.com
# 4 * * * * cat /opt/sys.mai /opt/var/log/syslog.log | sendmail xxxxxxxxxxxx@gmail.com
could you give comment on admin's crontab please?

macsat
30-06-2005, 11:35
I'm not sure I undestand your question...

Are you asking what the word "root" in this line in my script means? :


01 * * * * root run-parts /opt/etc/cron.hourly

?

Then it is the user as which the command is ran....I will update my Tutorial to inform about this tonight....

frankd
30-06-2005, 11:49
Yes, that should have been my question :rolleyes:

Every user has its own crontab, no user id inside.

Edit: I noticed too late that the system crontab has a user field. :(

macsat
30-06-2005, 13:12
:-)

Yes - I used the System Crontab, since the WL500g with olegs firmware is a one user system (yes...I do know that multiuser-setups CAN be made!)..

The idea behind my crontab implementation, is that after it is setup, all that is needed to run a task daily, weekly, monthly etc...is to place a script in a certain directory, and hence there is no need to "know" anything about cron to use it :-)