# Auto-generated index.html in Apache2?

## al

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

 :Very Happy: 

----------

## Delkaton

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: 

----------

## NeddySeagoon

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.

----------

## cjc

 *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.

----------

## al

 *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.  :Sad: 

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

 :Very Happy: 

----------

## dvc5

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

----------

## al

 *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:

```
# 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:

```
 <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?

 :Sad: 

----------

## dvc5

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:

```
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

----------

## al

 *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:
> ...

 

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:

```
###

### 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

 :Sad: 

----------

## dvc5

 *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.

```
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.

----------

## al

 *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. 
> ...

 

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  :Sad: 

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?

----------

## NeddySeagoon

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?

----------

## al

 *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?
> ...

 

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

----------

## Insanity5902

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?

----------

## NeddySeagoon

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.

----------

## al

 *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?
> ...

 

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 

```
ServerName alunt2003.homelinux.org
```

and 

```
###

### 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?

----------

## NeddySeagoon

al, 

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

----------

## al

 *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  :Embarassed: 

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

 :Very Happy: 

----------

## Insanity5902

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.

----------

## al

 *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.

----------

## NeddySeagoon

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.

----------

## vonhelmet

I know you got it fixed but...

Learn PHP anyway  :Smile:  It's top.

----------

## al

 *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.

 :Very Happy: 

----------

## YopWongSapn

 *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.

----------

