Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: TomyTurbos on February 07, 2019, 05:47:13 PM

Title: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 07, 2019, 05:47:13 PM
I've been searching without finding, so once again, I'm asking.

TC+ 10.0.  Running properly with persistence.

I have lighttpd.tcz and its dependencies.

I run it as an 'onboot' item.  Or, I don't run it as an onboot item.  I get the same results.

It wants a config file, but I don't know where to put it or if I need to create the dirs/files myself or ???

So, how do I go about making it work?

Title: Re: 'Lighty' (lighttpd)
Post by: coreplayer2 on February 07, 2019, 07:08:23 PM
Tommy.....

I don’t use lighttpd so am not really qualified to answer this, however to help you find answers try these tips

Every extension has an info file which is the default landing page when you select an extension in APPS

Also from Tinycorelinux.net  downloads simply add the extension name with .info to the web address to learn more about configuration and usage
http://tinycorelinux.net/10.x/x86/tcz/lighttpd.tcz.info

From here you’ll find the config file location which I assume needs copying to and editing and saved to backup, but I’m guessing here..
Because you’ll find most configuration files live here
 
Code: [Select]
/etc/lighttpd/lighttpd.conf
Also  google is a great resource

;)


Sent from my iPhone using Tapatalk
Title: Re: 'Lighty' (lighttpd)
Post by: Rich on February 07, 2019, 07:24:34 PM
Hi TomyTurbos
If you look at this:
http://tinycorelinux.net/10.x/x86/tcz/lighttpd.tcz.list
you'll see there are a couple of  man (manual)  files at the end of the list. If you install  man.tcz  you can view those  man  files:
Code: [Select]
man lighttpd
man lighttpd-angel
Sometimes I check older info files for details that may have been lost during updates:
http://tinycorelinux.net/4.x/x86/tcz/lighttpd.tcz.info
Title: Re: 'Lighty' (lighttpd)
Post by: coreplayer2 on February 08, 2019, 02:17:51 AM
Good thinking Rich, I always forget the Man pages..     They provide the ultimate info on any program but they're a little dry for my taste..    Who writes those pages anyhow?
Title: Re: 'Lighty' (lighttpd)
Post by: andyj on February 08, 2019, 04:33:23 AM
I do use it for serving up tcz files for diskless VM's. You can try one like this:

Code: [Select]
server.document-root = "/"
server.bind = "192.168.0.3"
server.port = 80
server.username = "nobody"
server.groupname = "nogroup"
server.chroot = "/mnt/sda1/tce64"

You can see from the help that you need to specify the config file location on the command line:

Code: [Select]
~$ lighttpd -h
lighttpd/1.4.45 (ssl) (Sep  2 2017 15:14:56) - a light and fast webserver
usage:
 -f <name>  filename of the config-file
 -m <name>  module directory (default: /usr/local/lib/lighttpd)
 -i <secs>  graceful shutdown after <secs> of inactivity
 -1         process single (one) request on stdin socket, then exit
 -p         print the parsed config-file in internal form, and exit
 -t         test config-file syntax, then exit
 -tt        test config-file syntax, load and init modules, then exit
 -D         don't go to background (default: go to background)
 -v         show version
 -V         show compile-time features
 -h         show this help

Hope this helps.
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 08, 2019, 01:59:50 PM
Well, I have managed to get myself to a 403 error, so I guess I'm making progress.

Using the info above and various other places I was able to find that lighty does not care where you put the .conf file, but it does have to be told where to find it when starting up.  I also determined that the .conf file accepts comments prefaced with '#'. (in case anyone was wondering).  Simple facts such as these are what is lacking in the documentation.

Further I discovered that the command switches for lighttp can be combined  as "-tf" rather than "-t -f".  (Also useful information which was not clearly stated).

Here's where I am so far:

In order to maintain convention for TC, I sudoed to make '/etc/lighttpd/lighttpd.conf', then added 'etc/lighttpd' to '/opt/.filetool.lst' so it is saved.

Using the instructions directly from lighty's site (https://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration), my .config is as follows:

server.document-root = "[path-to-desired-folder]"

server.port = 3000

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain"
)

Running "lighttpd -tf [path-to-config]" gave a 'Syntax OK' response.  This was however despite the fact that I had made a typo in the "server.document-root" statement. (the hyphen was missing).

Running "lighttpd -Df [path-to-config]" gave errors.

Fixed that and ran it again.  Opened OTWeb and pointed to localhost:3000.  403 error. 

With some other [path-to-document-root] locations it resulted in 404 errors.


Obviously I did something wrong, and I suspect that it has to do with permissions.

I have tried all sorts of possible combinations: Using port 80, adding the user and group names as post above, running as sudo.  And and all of the above.  The ports answer pings.

Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 08, 2019, 05:32:55 PM
Well, I have managed to get myself to a 403 error, so I guess I'm making progress.

Using the info above and various other places I was able to find that lighty does not care where you put the .conf file, but it does have to be told where to find it when starting up.  I also determined that the .conf file accepts comments prefaced with '#'. (in case anyone was wondering).  Simple facts such as these are what is lacking in the documentation.

Further I discovered that the command switches for lighttp can be combined  as "-tf" rather than "-t -f".  (Also useful information which was not clearly stated).

Here's where I am so far:

In order to maintain convention for TC, I sudoed to make '/etc/lighttpd/lighttpd.conf', then added 'etc/lighttpd' to '/opt/.filetool.lst' so it is saved.

Using the instructions directly from lighty's site (https://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration), my .config is as follows:

server.document-root = "[path-to-desired-folder]"

server.port = 3000

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain"
)

Running "lighttpd -tf [path-to-config]" gave a 'Syntax OK' response.  This was however despite the fact that I had made a typo in the "server.document-root" statement. (the hyphen was missing).

Running "lighttpd -Df [path-to-config]" gave errors.

Fixed that and ran it again.  Opened OTWeb and pointed to localhost:3000.  403 error. 

With some other [path-to-document-root] locations it resulted in 404 errors.


Obviously I did something wrong, and I suspect that it has to do with permissions.

I have tried all sorts of possible combinations: Using port 80, adding the user and group names as post above, running as sudo.  And and all of the above.  The ports answer pings.

OK, I've got this sorted (sort of.) Still many more configuration things to do, but at least it is serving content now.

The "server.document-root =" statement MUST include a forward-slash ('/') before [path-to-files].

Also, adding "index-file.names = ( "index.html", "[etc]" )" to the .conf file was necessary.

This was counterintuitive because other documentation suggested that at the very least, index.html was implicit.

I found the answer here: https://iomem.com/index.php?archives/3-Starting-out-with-Lighttpd.html&serendipity&serendipity[entrypage]=2

Also, there is the (rather cryptic) description of .conf declarations from here: https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ConfigurationOptions

I hope this proves to be useful info for others who might face the same misfortune in trying to make this work.  I'll post a more succinct recap of this topic shortly.  Otherwise, consider it solved.
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 08, 2019, 07:27:18 PM
Here's a synopsis of what I did to create a basic HTTP Server: (for dummies like me)

1. Download lighttpd.tcz as an onboot item. (check elsewhere for how to do this as needed)

2. Create (as SU) a folder in 'etc' named 'lighttpd'.

3. Create a file in that folder named 'lighttpd.conf'.

NB:  This will only be editable as SU.

4. Choose the location for your web content and create it as necessary.  Hereafter it will be referred to as 'document-root'

5. Create a file in 'document-root' named 'index.html'.

6. Edit 'index.html' to say 'the second mouse gets the cheese' or anything else you want. (this way you will know if it's serving the file later, when you load it to your browser.)

7. Edit (as SU) '/etc/lighttpd/lighttpd.conf' to include the following:
Do not include single-quotes as written here.

' server.document-root = "[path-to-files]" '
NB:  Forward slash is important in the pathname.

' server.port = 3000 '
' server.username = "nobody" '
' server.groupname = "nogroup" '
' index-file.names = ("index.html") '
' mimetype.assign = (".html" => "text/html") '

NB: 'server.username' and 'server.groupname' are not necessary unless 'server.port' is a number below 1024. The names can be whatever you want them to be.

8. In terminal (aterm) run ' lighttpd -tf /etc/lighttpf/lighttpf.conf ' to (theoretically) check for syntax errors in your .conf file.

9. Assuming that there are no typos, run in terminal:
' lighttpd -Df /etc/lighttpf/lighttpf.conf '
OR
' sudo lighttpd -Df /etc/lighttpf/lighttpf.conf ' if you used a port below 1024

The content you put in ' index.html ' in Step 6 should now display in your browser with the address '  localhost:[port-selected-in config] '

This gives you the most basic of webservers.  Further configuration can be made by editing ' /etc/lighttpd/lighttpd.conf ' (as SU).

10. To make this persistent on tinycore, edit ' /opt/.filetool.lst ' to add ' etc/lighttpd '.
11. To make this run on startup edit ' /opt/bootlocal,sh ' to add ' lighttpd -Df /etc/lighttpf/lighttpf.conf '


I hope this answers my question.  I also hope it answers questions for others.

    [EDIT]: Corrected spelling of  /opt/bootlocal,sh.  Rich
Title: Re: 'Lighty' (lighttpd)
Post by: Rich on February 08, 2019, 07:39:36 PM
Hi TomyTurbos
Quote
11. To make this run on startup edit ' /opt.bootlocal,sh ' to add ' lighttpd -Df /etc/lighttpf/lighttpf.conf '
OR
' sudo lighttpd -Df /etc/lighttpf/lighttpf.conf ' if you used a port below 1024
There's no need for  sudo  when running commands from  /opt/bootlocal,sh  because it's already running as root.
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 08, 2019, 07:59:27 PM
Hi TomyTurbos
Quote
11. To make this run on startup edit ' /opt.bootlocal,sh ' to add ' lighttpd -Df /etc/lighttpf/lighttpf.conf '
OR
' sudo lighttpd -Df /etc/lighttpf/lighttpf.conf ' if you used a port below 1024
There's no need for  sudo  when running commands from  /opt/bootlocal,sh  because it's already running as root.

I did not know that.  Now that I do, I have corrected my previous post.

Thank you.
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 09, 2019, 03:24:48 PM
I found another, somewhat simpler way to deal with the .conf file and it's location.  It is perhaps somewhat less secure, but it is easier to accomplish.

Instead of making the directory and file in '/etc', put it in '/home/tc'.  If you have a persistent '/home', right from the get-go you can skip Step 10 in my previous post.  Also, you don't have to deal with the elevated permission needed to edit the .conf file further. (This is why I said it "MAY" be somewhat less secure.  But it's not enough a risk for my purposes at the moment, so I'm doing it that way now.)

The full [path-to-config] I used is '/home/tc/.lighttpd/lighttpd.conf'.

I want to reiterate that lighttpd does not care where this file is or what it is called.

And also, if you were following my previous instructions, the entry in Step 11 needs to have the same [path-to-config].
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 09, 2019, 03:34:08 PM
Rather than start a separate thread, I'll put this here as it is related.

lighttpd-angel

If anyone was wondering, it is simply a different launcher for the server.  It takes exactly the same command line parameters as lighttpd.  There is no apparent difference in its behavior, but it claims to be able to restart lighttpd if something were to cause the process to crash.

There is more to this than I have been able to figure out so far but I can attest to the fact that the two work interchangeably.
Title: Re: 'Lighty' (lighttpd)
Post by: coreplayer2 on February 09, 2019, 09:01:17 PM
I found another, somewhat simpler way to deal with the .conf file and it's location.  It is perhaps somewhat less secure, but it is easier to accomplish.

Instead of making the directory and file in '/etc', put it in '/home/tc'.  If you have a persistent '/home', right from the get-go you can skip Step 10 in my previous post.  Also, you don't have to deal with the elevated permission needed to edit the .conf file further. (This is why I said it "MAY" be somewhat less secure.  But it's not enough a risk for my purposes at the moment, so I'm doing it that way now.)
Hello Tommy,  but you're killing me with this obsession with sudo, elevated permissions etc etc...  It's not necessary to use elevated permissions to edit a config file created by user. 

First,  One of the most interesting aspects of TinyCoreLinux is the ability to build your system as you see fit..    Know that suggesting to do things against convention may cause confusion to others like yourself who came here with an honest question looking for the right solution.

What you're suggesting here is, that because of difficulty understanding the file system, file ownership and permissions it's easier to use home directory typically saved for user preferences and documents instead of  /etc directory..?     

You might find this interesting
http://www.aboutlinux.info/2007/03/what-does-etc-stands-for-in-linuxunix.html

Even more interesting and on topic
https://wiki.archlinux.org/index.php/Lighttpd

Code: [Select]
tc@box:~$ cd /
tc@box:/$ ls -l
total 12
drwxr-xr-x   2 root root  1400 Feb  9 21:27 bin/
drwxrwxr-x  14 root staff 6840 Feb  9 21:27 dev/
drwxrwxr-x  10 tc   staff  740 Feb  9 21:35 etc/
drwxrwxr-x   4 root staff 4096 Jan 22 10:13 home/
-rwxr-xr-x   1 root root   496 Jan 20 15:27 init
drwxr-xr-x   4 root root   800 Jan 20 15:27 lib/
lrwxrwxrwx   1 root root    11 Jan 20 15:27 linuxrc -> bin/busybox
drwxrwxr-x   8 root staff  160 Feb  9 21:27 mnt/
drwxrwsr-x   4 root staff 4096 Jan 20 15:27 opt/
dr-xr-xr-x 262 root root     0 Feb  9 21:26 proc/
drwxrwxr-x   4 root staff  140 Feb  9 21:27 root/
drwxrwxr-x   4 root staff   80 Feb  9 21:26 run/
drwxr-xr-x   2 root root  1200 Jan 20 15:27 sbin/
dr-xr-xr-x  12 root root     0 Feb  9 21:26 sys/
drwxrwxrwt   5 root staff  280 Feb  9 21:34 tmp/
drwxr-xr-x   7 root root   140 Mar 22  2018 usr/
drwxrwxr-x   8 root staff  180 Jan 20 15:27 var/
tc@box:/$
tc@box:/$ touch /etc/testfile
tc@box:/$
tc@box:/$ echo "MytestFileScript" > /etc/testfile
tc@box:/$
tc@box:/$ cat /etc/testfile
MytestFileScript
tc@box:/$
Notice from a fresh boot my /etc directory is owned by user & group "tc:staff"  therefore I shouldn't need elevated privileges to create and write to a file within it.
To confirm this I was able to create a file and edit it with only user privileges (see above).

So what error messages are you getting when you attempt to edit the file?


Maybe you're trying to edit the symlink?  whenever you come across this issue try instead to open the configuration file and saveas lighttpd.conf   then edit it and make a backup.
alternatively saveas a new file temporarily, delete the existing file and rename the new file same as per the old symlink and make a backup when editing is complete.
I'm not saying you can't do this any other way am just saying this is the right way to accomplish the task.


The TinyCore way is to create a configuration file and add it to your backup, or create an extension install into the file system all of your configuration files.  It's really no big issue when you know how.

Good luck


Title: Re: 'Lighty' (lighttpd)
Post by: mocore on February 10, 2019, 05:17:10 AM

The TinyCore way is to create a configuration file and add it to your backup,
 or create an extension install into the file system all of your configuration files.

the best (imho) overview of this is on the "Core Concepts" page : http://tinycorelinux.net/concepts.html

this : " diagram of the Tiny Core file architecture." http://tinycorelinux.net/arch_core.html
being my fav  :D

if `A picture is worth a thousand words`
then
http://tinycorelinux.net/images/core.png
is as good as the book  ;)
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 11, 2019, 08:11:23 PM
I found another, somewhat simpler way to deal with the .conf file and it's location.  It is perhaps somewhat less secure, but it is easier to accomplish.

Instead of making the directory and file in '/etc', put it in '/home/tc'.  If you have a persistent '/home', right from the get-go you can skip Step 10 in my previous post.  Also, you don't have to deal with the elevated permission needed to edit the .conf file further. (This is why I said it "MAY" be somewhat less secure.  But it's not enough a risk for my purposes at the moment, so I'm doing it that way now.)
Hello Tommy,  but you're killing me with this obsession with sudo, elevated permissions etc etc...  It's not necessary to use elevated permissions to edit a config file created by user. 

First,  One of the most interesting aspects of TinyCoreLinux is the ability to build your system as you see fit..    Know that suggesting to do things against convention may cause confusion to others like yourself who came here with an honest question looking for the right solution.

What you're suggesting here is, that because of difficulty understanding the file system, file ownership and permissions it's easier to use home directory typically saved for user preferences and documents instead of  /etc directory..?     

You might find this interesting
http://www.aboutlinux.info/2007/03/what-does-etc-stands-for-in-linuxunix.html

Even more interesting and on topic
https://wiki.archlinux.org/index.php/Lighttpd

Code: [Select]
tc@box:~$ cd /
tc@box:/$ ls -l
total 12
drwxr-xr-x   2 root root  1400 Feb  9 21:27 bin/
drwxrwxr-x  14 root staff 6840 Feb  9 21:27 dev/
drwxrwxr-x  10 tc   staff  740 Feb  9 21:35 etc/
drwxrwxr-x   4 root staff 4096 Jan 22 10:13 home/
-rwxr-xr-x   1 root root   496 Jan 20 15:27 init
drwxr-xr-x   4 root root   800 Jan 20 15:27 lib/
lrwxrwxrwx   1 root root    11 Jan 20 15:27 linuxrc -> bin/busybox
drwxrwxr-x   8 root staff  160 Feb  9 21:27 mnt/
drwxrwsr-x   4 root staff 4096 Jan 20 15:27 opt/
dr-xr-xr-x 262 root root     0 Feb  9 21:26 proc/
drwxrwxr-x   4 root staff  140 Feb  9 21:27 root/
drwxrwxr-x   4 root staff   80 Feb  9 21:26 run/
drwxr-xr-x   2 root root  1200 Jan 20 15:27 sbin/
dr-xr-xr-x  12 root root     0 Feb  9 21:26 sys/
drwxrwxrwt   5 root staff  280 Feb  9 21:34 tmp/
drwxr-xr-x   7 root root   140 Mar 22  2018 usr/
drwxrwxr-x   8 root staff  180 Jan 20 15:27 var/
tc@box:/$
tc@box:/$ touch /etc/testfile
tc@box:/$
tc@box:/$ echo "MytestFileScript" > /etc/testfile
tc@box:/$
tc@box:/$ cat /etc/testfile
MytestFileScript
tc@box:/$
Notice from a fresh boot my /etc directory is owned by user & group "tc:staff"  therefore I shouldn't need elevated privileges to create and write to a file within it.
To confirm this I was able to create a file and edit it with only user privileges (see above).

So what error messages are you getting when you attempt to edit the file?


Maybe you're trying to edit the symlink?  whenever you come across this issue try instead to open the configuration file and saveas lighttpd.conf   then edit it and make a backup.
alternatively saveas a new file temporarily, delete the existing file and rename the new file same as per the old symlink and make a backup when editing is complete.
I'm not saying you can't do this any other way am just saying this is the right way to accomplish the task.


The TinyCore way is to create a configuration file and add it to your backup, or create an extension install into the file system all of your configuration files.  It's really no big issue when you know how.

Good luck

It's not really an obsession.  Frankly, I could do without it.  But it is necessary to start the server as Root in order for it to use ports under 1024 (specifically 80 and 443, which are defaults expected by other applications).  And this limits the ways in which lighty can be implemented.  For reasons of security it is not desirable to operate the Server as root, yet it must be launched as root in order to access those ports.

I definitely made a lot of mistakes along the way, but this was me trying to answer various unanswered questions and create a breadcrumb trail through my various blunders.  Let's not forget the first reply: "I don’t use lighttpd so am not really qualified to answer this, ..."

One of the mistakes was probably making a Dir as root when I should not have.  That said, I am using spacefm to navigate and editing with leafpad.  Neither of these are 'playing nice' with '/etc' or its subdirs.  Troubleshooting that is beyond the scope of this thread, however.

Meanwhile, I have learned a great deal about both TC and lighty and how to deploy it in a way which  follows conventional wisdom of which I was previously unaware.

After learning, testing and a lot of redoing I currently have lighty loading with SSL before the desktop or the browser, which is what I needed to happen. I still need to get PHP, Ruby and a couple of other things going before I'm ready for prime time, but when I get a moment I'll post an update on how I managed to make this work.
Title: Re: 'Lighty' (lighttpd)
Post by: andyj on February 12, 2019, 05:36:17 AM
I don't know about lighttpd and php as I only use it for static files, but I do know that nginx and php-fpm works well. Lighttpd and nginx extensions are both less than 1 meg and have the same dependencies, if size is your concern.
Title: Re: 'Lighty' (lighttpd)
Post by: coreplayer2 on February 12, 2019, 07:07:29 AM
TomyTurbos,  please...

The point here..  If you have to use sudo to launch the application with desired options, fine!  There's no problem with that at all.  As I've said earlier I know nothing about lighttpd and at present have no need for it,  but if I did I'm fairly sure I could figure out how to do it right without all the fuss just like most folks..   
Most linux applications have similar usage and lighttpd is clearly not that difficult to figure out.  Heck, https://linux.die.net/man/8/lighttpd tells us almost everything we need to know barring a few TinyCore specifics.   

This!
Quote
One of the mistakes was probably making a Dir as root when I should not have.  That said, I am using spacefm to navigate and editing with leafpad.  Neither of these are 'playing nice' with '/etc' or its subdirs.  Troubleshooting that is beyond the scope of this thread, however.
This is infuriating, this attitude doesn't help us help you at all.    I feel for you and everyone else new to TC, because I've been there;  Understanding the file system and permissions is of utmost importance and should be your primary focus, not shrugging it off as" beyond this thread's scope",  on the contrary IMO it's probably the only topic you should be discussing.    The Core Concepts will help.  Either way figure it out..


I'm obviously biased regarding spaceFM and while it's not 100% perfect IMO spaceFM is the best user friendly File Manager available for any operating system.     I strongly recommend putting in the effort learning how to navigate the file system, manipulate files (incl. symlinks) and even basic file editing with VI from the terminal.  Because there are often times especially managing a web/file server (which doesn't need a desktop gui) when this is the only way..      Used in combination, SpaceFM and the Terminal are extremely powerful tools and typically is all you'll ever need. 

Quote
Neither of these are 'playing nice' with '/etc' or its subdirs
Really?   please explain...
What command did you use, with what options?
What was the desired result?
What was the actual result?
What was the error message?

I demonstrated in my previous post how to create a file and edit it without every needing sudo.   
You can use SpaceFM to navigate, then "F4" to open a terminal and enter a command.

Or simply open a terminal from the wbar and enter
mkdir /etc/mydir
touch /etc/mydir/myfile.conf

When you understand the file system you'll know that /usr/local/etc/lighttpd might not be directly edited even with sudo, meanwhile:
Use the editor of choice to copy and save the contents of /usr/local/etc/lighttpd  to your new /etc/mydir/configFile (or /etc/configFile) and edit that file as necessary
SpaceFM with it's multi-Tab feature is great for this.
When the file permissions are such that a user is not given read permisions, then and only then try from a terminal
Code: [Select]
sudo editor /usr/local/etc/lighttpdcopy the contents to a file you can edit (eg: /etc/configFile), or SaveAs /etc/configFile

then launch the application with the -f option specifying where the new config file is
Don't forget to make a backup which includes the new config file before rebooting

There's no fuss, no having to find a workaround, just learn why you can't accomplish the task as expected.
Is there really anything else?

good luck
Title: Re: 'Lighty' (lighttpd)
Post by: TomyTurbos on February 12, 2019, 06:24:12 PM
When I previously said "Troubleshooting that is beyond the scope of this thread", it was in keeping with "Do not go from one question to a completely different question in the same thread. Start a different topic." http://forum.tinycorelinux.net/index.php/topic,7738.0.html

This is why I am not discussing spacefm here.