Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Auto-generated index.html in Apache2?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 12:37 pm    Post subject: Auto-generated index.html in Apache2? Reply with quote

I have Apache2 with PHP installed and working fine.

What i want is when i add files to my "files" directory for eg. is for my index.html file to auto update itself to show the file names as hperlinks.

I'm guessing i would need some kind of script which would read the contents of the "files" directory every 2 seconds or so and then write the contents as links to the index file?

Can i write a script in PHP to do this?

Does anyone have a script to do this?

Please gun me down in flames if i'm am missing something really simple!

Thanks in advance

:D
Back to top
View user's profile Send private message
Delkaton
Tux's lil' helper
Tux's lil' helper


Joined: 26 Feb 2004
Posts: 121

PostPosted: Sat Apr 24, 2004 2:02 pm    Post subject: Reply with quote

Wouldn't it br easier to set up a ftp server? This way you could use a browser to view files inside it without having to spend you machine's cpu looking for new files from time to time.

Of course, I don't know if that works for you. :wink:
_________________
Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32099
Location: 56N 3W

PostPosted: Sat Apr 24, 2004 2:07 pm    Post subject: Reply with quote

al,

If you have a directory with no index.html file, Apache will show users a list of the files in that directory. Its dynamically generated.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
cjc
n00b
n00b


Joined: 16 Mar 2004
Posts: 63
Location: Birmingham, United Kingdom

PostPosted: Sat Apr 24, 2004 2:13 pm    Post subject: Re: Auto-generated index.html in Apache2? Reply with quote

al wrote:
I'm guessing i would need some kind of script which would read the contents of the "files" directory every 2 seconds or so and then write the contents as links to the index file?


There is no reason for the script to poll that regularly. If you are really unsure about when you will update and require all updates to appear immediately, then you can use a PHP script to read the directory and format the output. As an alternative, if you are only going to add updates from the machine (or are also running a shell server), you could consider using a separate script as a pseudo-uploader - updating the page as and when the directory content changes. There is more book-keeping in the non-active method, but it can save server load if that is important in this environment (it probably is not).

Also, see the point above, unless you mean the front-page of the site to display a sub-directories contents.
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 4:15 pm    Post subject: Reply with quote

NeddySeagoon wrote:
al,

If you have a directory with no index.html file, Apache will show users a list of the files in that directory. Its dynamically generated.


I tried that but it doesn't work for me. :(

I created a directory called "files" /var/www/localhost/htdocs/files but if i point my browser to http://alunt2003.homelinux.org/files i get no directory listing.

My main index.html page is in /var/www/localhost/htdocs http://alunt2003.homelinux.org and it works.

Is there something i should edit in the apache config file?

My config file is here: http://alunt2003.homelinux.org/apache2.conf


Oh,and sorry for taking so long to answer but i was painting my garage doors
:D
Back to top
View user's profile Send private message
dvc5
Guru
Guru


Joined: 06 Dec 2003
Posts: 433
Location: Sunnyvale, California

PostPosted: Sat Apr 24, 2004 4:17 pm    Post subject: Reply with quote

You need to have the "+Indexes" option set for your files/ directory. This can be done either in your commonapache2.conf or your vhosts.conf if you use one.

Edit: That should be commonapache2.conf, not apache2.conf
_________________
#define NULL rand() /*heh heh heh */

Green Is Good
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 5:17 pm    Post subject: Reply with quote

dvc5 wrote:
You need to have the "+Indexes" option set for your files/ directory. This can be done either in your commonapache2.conf or your vhosts.conf if you use one.

Edit: That should be commonapache2.conf, not apache2.conf


I had a look for +Indexes in commonapache2.conf and found this:

Code:
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
    Options +Indexes FollowSymLinks MultiViews
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"


So it looks like it was already set?

I tried putting in this:

Code:
 <Directory /home/al/public_html>
    AllowOverride All
    Options MultiViews +Indexes Includes FollowSymLinks
    <IfModule mod_access.c>
      Order allow,deny
      Allow from all
    </IfModule>
</Directory>


and created a directory called public_html in my home directory but the files i dropped into it are not accessable.

I've tried restarting apache but it still doesnt work.
What am i doing wrong?

:(
Back to top
View user's profile Send private message
dvc5
Guru
Guru


Joined: 06 Dec 2003
Posts: 433
Location: Sunnyvale, California

PostPosted: Sat Apr 24, 2004 5:28 pm    Post subject: Reply with quote

What are the permissions of /home/al/public_html?
It should be chown'ed to apache:apache and have read access to u & g.
Here's a working config for a virtual host that I modified for your hostname and directory, so maybe try cutting and pasting it into your vhosts.conf file, changing the hostnames and directories if necessary:
Code:
NameVirtualHost *:80
                                                                               
### alunt2003.homelinux.org ###
<VirtualHost *:80>
ServerName alunt2003.homelinux.org
DocumentRoot /home/al/public_html                                                                     
<Directory /home/al/public_html>
Options -Indexes FollowSymLinks MultiViews
</Directory>                                                                               
<Directory /home/al/public_html/files>
Options +Indexes
</Directory>

</VirtualHost>


Note, this will only show the files/ folder indexed, as it is generally bad practice to make your top-level directory tree viewable to the world.

Edit: Make sure you have this vhosts.conf file as an Include in your apache2.conf
_________________
#define NULL rand() /*heh heh heh */

Green Is Good
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 5:56 pm    Post subject: Reply with quote

dvc5 wrote:
What are the permissions of /home/al/public_html?
It should be chown'ed to apache:apache and have read access to u & g.
Here's a working config for a virtual host that I modified for your hostname and directory, so maybe try cutting and pasting it into your vhosts.conf file, changing the hostnames and directories if necessary:
Code:
NameVirtualHost *:80
                                                                               
### alunt2003.homelinux.org ###
<VirtualHost *:80>
ServerName alunt2003.homelinux.org
DocumentRoot /home/al/public_html                                                                     
<Directory /home/al/public_html>
Options -Indexes FollowSymLinks MultiViews
</Directory>                                                                               
<Directory /home/al/public_html/files>
Options +Indexes
</Directory>

</VirtualHost>


Note, this will only show the files/ folder indexed, as it is generally bad practice to make your top-level directory tree viewable to the world.

Edit: Make sure you have this vhosts.conf file as an Include in your apache2.conf


Okay i did the above,apart from making the directory u & g,because i dont know how.Then i uncommented the vhosts line in apache.conf as below:

Code:
###
### Virtual Hosts
###
# We include different templates for Virtual Hosting. Have a look in the
# vhosts directory and modify to suit your needs.
Include conf/vhosts/vhosts.conf
#Include conf/vhosts/dynamic-vhosts.conf
#Include conf/vhosts/virtual-homepages.conf


So it would load the vhosts file.
I restarted apache then pointed my browser to http://localhost/ but i got the apache error page.
I then dropped my index file into the directory and it then displayed my web page so it seems its directing apache to my public_html directory fine, which is better than i had but it still wont display directory contents.

If you point your browser to http://alunt2003.homelinux.org/files/ you get a 404 error

:(
Back to top
View user's profile Send private message
dvc5
Guru
Guru


Joined: 06 Dec 2003
Posts: 433
Location: Sunnyvale, California

PostPosted: Sat Apr 24, 2004 6:48 pm    Post subject: Reply with quote

al wrote:
If you point your browser to http://alunt2003.homelinux.org/files/ you get a 404 error

:(

Just tried it and it worked fine for me.

Remember if you're trying to visit that page from inside the same subnet as the webserver hosting the page, you'll need to have an entry in your /etc/hosts file to resolve the server manually.
Code:
LOCAL.IP.OF.SERVER    alunt2003.homelinux.org    alunt2003

If you add that line to your /etc/hosts file replacing "LOCAL.IP.OF.SERVER" with whatever local IP Address that server has, you can then visit the page from inside the same subnet.
_________________
#define NULL rand() /*heh heh heh */

Green Is Good
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 7:07 pm    Post subject: Reply with quote

dvc5 wrote:
al wrote:
If you point your browser to http://alunt2003.homelinux.org/files/ you get a 404 error

:(

Just tried it and it worked fine for me.

Remember if you're trying to visit that page from inside the same subnet as the webserver hosting the page, you'll need to have an entry in your /etc/hosts file to resolve the server manually.
Code:
LOCAL.IP.OF.SERVER    alunt2003.homelinux.org    alunt2003

If you add that line to your /etc/hosts file replacing "LOCAL.IP.OF.SERVER" with whatever local IP Address that server has, you can then visit the page from inside the same subnet.


Okay thats fine that it works for you guys.I can see in my access.log that youve been into my "files" directory.

I have my /etc/hosts file setup with LOCAL.IP.OF.SERVER alunt2003.homelinux.org alunt2003 which used to work,but now it doesnt :(
If i point my browser to http://alunt2003.homelinux.org/files i get a 404 error message.
If i point my browser to http://alunt2003.homelinux.org my Netgear router box index file is displayed and asks me for my router box user name and password.

How can i fix that? Anyone familiar with a Netgear DG834?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32099
Location: 56N 3W

PostPosted: Sat Apr 24, 2004 7:14 pm    Post subject: Reply with quote

al,

Describe your network set up please. You may as well use real IP addresses. We can get them from a whois anyway. It will be easier for us all.

Are you using DHCP on your network or not?
Do you run your own nameserver?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 7:29 pm    Post subject: Reply with quote

NeddySeagoon wrote:
al,

Describe your network set up please. You may as well use real IP addresses. We can get them from a whois anyway. It will be easier for us all.

Are you using DHCP on your network or not?
Do you run your own nameserver?


Right I have a Netgear DG834 ADSL router box.IP address 192.168.0.1
I have 4 Windows boxes (wife & kids) with static IP addresses in the 192.168.0.ip range
Then i have my Gentoo Laptop IP address 192.168.0.2,which is my workstation but also my web server running apache2.
The router box allows port 80 as incoming but also as outgoing.Do i need port 80 outgoing or is this unsafe?
Oh and the web address homelinux.org is a redirection from http://www.dyndns.org/ because i have a dynamic dns from my isp btopenworld.

edit: /etc/hosts looks like this:

192.168.0.2 alunt2003.homelinux.org alunt2003
127.0.0.1 localhost
192.168.0.2 gentoo.wireless
192.168.0.101 lewis
192.168.0.200 jordan
192.168.0.85 ewan
192.168.0.24 jolene
192.168.0.71 elaine
Back to top
View user's profile Send private message
Insanity5902
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1228
Location: Fort Worth, Texas

PostPosted: Sat Apr 24, 2004 7:37 pm    Post subject: Reply with quote

Al, are you trying to browse your site from the same comptuer that is the server?

coud you post your /etc/host file?

Can you see your page at http://localhost?

Also when you set up apache, how did you have apache bind your domain name, did you specify which IP for it to bind to or did you have it bind to all available IP's? Do you have any virutal host? If so how are they set up?
_________________
GibbonsR.net | OpenLaptops.org

Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32099
Location: 56N 3W

PostPosted: Sat Apr 24, 2004 7:52 pm    Post subject: Reply with quote

al,

What IP address have you got Apache set up to respond to?
Since I can browse it it must be your real routable one, not 192.168.0... or 127.0.0.1.

Try connecting to http://<IPAddress> where <IP Address> is your current real IP.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 7:57 pm    Post subject: Reply with quote

Insanity5902 wrote:
Al, are you trying to browse your site from the same comptuer that is the server?

coud you post your /etc/host file?

Can you see your page at http://localhost?

Also when you set up apache, how did you have apache bind your domain name, did you specify which IP for it to bind to or did you have it bind to all available IP's? Do you have any virutal host? If so how are they set up?


Yes im trying to browse my site from the same computer.

If i point my browser to http://localhost i get my index.html file displayed but if i try http://localhost/files i get 404 error not found

My apache.conf is here: http://alunt2003.homelinux.org/files/apache.conf and reads
Code:
ServerName alunt2003.homelinux.org

and
Code:
###
### IP Address/Port
###
#BindAddress *
Listen 80


I did setup a virtual host as was previously posted above by dvc5 like so: NameVirtualHost *:80

### alunt2003.homelinux.org ###
<VirtualHost *:80>
ServerName alunt2003.homelinux.org
DocumentRoot /home/al/public_html
<Directory /home/al/public_html>
Options -Indexes FollowSymLinks MultiViews
</Directory>
<Directory /home/al/public_html/files>
Options +Indexes
</Directory>

</VirtualHost>

I dont have an /etc/host file.

My /etc/hostname is set to gentoo.wireless-should i change this to alunt2003.homelinux.org?
Also my /etc/hosts file has 2 entries for my computer 192.168.0.2,gentoo.wireless and alunt2003.homelinux.org alunt2003.Should i remove the gentoo.wireless one?Is there a confliction there?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32099
Location: 56N 3W

PostPosted: Sat Apr 24, 2004 8:15 pm    Post subject: Reply with quote

al,

Try http://localhost/files/ (note the trailing slash). I've never fixed my server to take either.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 8:26 pm    Post subject: Reply with quote

NeddySeagoon wrote:
al,

Try http://localhost/files/ (note the trailing slash). I've never fixed my server to take either.


Okay i feel stupid now for not thinking of that my self :oops:
It now works fine for me.

Thanks for that.It will make life easier for me just to dump files into a directory and have them displayed automatically instead of having to edit an index.html


:D
Back to top
View user's profile Send private message
Insanity5902
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1228
Location: Fort Worth, Texas

PostPosted: Sat Apr 24, 2004 8:35 pm    Post subject: Reply with quote

Okay, I have found that when trying to access a site hosted by apahce on the same computer, the only way I could get to it is http:://localhost . If you have another computer on your network try accessing it form that one using the domain name ... see what that does.
_________________
GibbonsR.net | OpenLaptops.org

Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 8:53 pm    Post subject: Reply with quote

Insanity5902 wrote:
Okay, I have found that when trying to access a site hosted by apahce on the same computer, the only way I could get to it is http:://localhost . If you have another computer on your network try accessing it form that one using the domain name ... see what that does.


If i try to access the server from the wifes laptop using http://alunt2003.homelinux.org or http://alunt2003.homelinux.org/files it doesnt work but if i try http://192.168.0.2 it does display the index.html file but http://192.168.0.2/files doesnt work.

I would like to get it working as an "intranet" as well,as i could download my kids favourite sites so they could browse them from the server instead of the internet.

Would it be better if i just piped the kids computers through "squid" so squid could cache the pages for them?

I already use squid for my own browsing on the same computer.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 32099
Location: 56N 3W

PostPosted: Sat Apr 24, 2004 9:02 pm    Post subject: Reply with quote

al,

You have the trailing slash problem again.
I know that you can configure Apache to accept either as the same thing but I gave up and left it.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
vonhelmet
l33t
l33t


Joined: 06 Apr 2004
Posts: 770
Location: Somewhere in a school

PostPosted: Sat Apr 24, 2004 9:15 pm    Post subject: Reply with quote

I know you got it fixed but...

Learn PHP anyway :) It's top.
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Sat Apr 24, 2004 9:30 pm    Post subject: Reply with quote

vonhelmet wrote:
I know you got it fixed but...

Learn PHP anyway :) It's top.


Yeah i came across PHP at http://www.phpfreaks.com/ and thought it looked powerful but not too hard to learn so i went out and bought "SAMS Teach Yourself PHP,MySQL and Apache"

I'm hoping once i've read that i will be able to produce a web site worth looking at instead of another poxy screenshot web page.

:D
Back to top
View user's profile Send private message
YopWongSapn
l33t
l33t


Joined: 26 Jan 2004
Posts: 627

PostPosted: Fri May 28, 2004 7:04 pm    Post subject: Reply with quote

al wrote:
I'm hoping once i've read that i will be able to produce a web site worth looking at instead of another poxy screenshot web page.



With PHP/MySQL, you can easily make a nice looking web page that does what you're looking to do. It's also nice because if you have something in that folder you don't want the public to see, it won't be seen.
_________________
Gentoo...it's like wiping your ass with silk. Or sandpaper.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum