How to show Directory Index in Apache 2.4 with custom Document Root
Asked Answered
P

6

19

i have problem in Apache 2.4 in Ubuntu 13.10. I try to change Document Root to /home/fandi/public_html And all working fine. But i try to create folder in my public_html/ i get an error like this :

[Sat Jan 25 10:59:50.149441 2014] [autoindex:error] [pid 1093] [client 127.0.0.1:39901] AH01276: Cannot serve directory /home/fandi/public_html/report_php/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive

I must create file index.html, index.php and other index.xxx file.

In default it must show Directory Index. How to enable Directory Index?

This is my file 000-default.conf :

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/fandi/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/home/fandi/public_html">
        Options All
        AllowOverride All
        Require all granted
        Options Indexes FollowSymLinks
    </Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Please help, thanks before ^^

Pontonier answered 25/1, 2014 at 4:8 Comment(2)
Not sure why this was tagged php or ubuntu - it's a pure Apache questionMonjo
How to use Apache DirectoryIndex directive amitoverflow.com/2021/04/29/how-to-use-directoryindexHornmad
H
10

Turns out you need to disable DirectoryIndex in Apache 2.4 to get auto Indexes.

DirectoryIndex disabled
Options Indexes

When DirectoryIndex is not disabled, auto index does not work and apache sends either a 403 Forbidden or a 404 File not found if you use fastcgi/php-fpm.

Here are the corresponding error log lines (for search purposes):

[authz_core:error] client denied by server configuration:
[proxy_fcgi:error] Got error 'Primary script unknown\n'
Hydropic answered 1/8, 2014 at 12:34 Comment(5)
Would have thought the failure to serve /usr/share/apache2/icons/ would have been picked up by some automated testing suite somewhere. alias.conf enables .../icons/ by default but still had [autoindex:error] ... AH01276: Cannot serve directory /usr/share/apache2/icons/Thank You!Impeditive
That was the problem for me. You must first disable DirectoryIndexTorose
That did nothing for me.Monjo
No info where to disable DirectoryIndex.Borkowski
This certainly does not work. I tried it. The documentation contradicts it: "If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory." In addition, Options Indexes turns all other options OFF.Gunas
O
8
Options All <--turn on all options
Options Indexes FollowSymLinks   <--- replace previously set options with these two

The second line is redundant, because you've already turned on all the options with the first line, and since the two options aren't prefixed with +, they actually REPLACE the entire options list enabled set with All with just those two individual options.

Overscrupulous answered 25/1, 2014 at 4:11 Comment(2)
So, how should i edit? Previously i just use Options All , and now i try to use just Options Indexes FollowSymLinks , but it didn't work. :\Pontonier
Didnt work for me. Apache 2.4 is an headache all suddenly and I have been working with apache for over 10 years. The problem is, if you try google it, you get answers from past 10+ years for 2.2, which are all WRONG.Category
C
6

I had the same problem with Centos 7.2 and apache 2.4.

In new installation, the problem is most likely caused by welcome.conf that disable Option Indexes in every location:

<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>

This file is restored on every Apache upgrade, then you should comment or delete previous lines.

Centipoise answered 30/8, 2016 at 22:34 Comment(1)
This is the correct solution, it also applies to other redhat style release (ie Fedora in my case)Anatase
M
5

I managed to get it to work

Basically it seems that Apache2.4 doesn't carry over the settings from DocumentRoot to your virtual hosts unless the virtual hosts are subfolders of DocumentRoot, like previous versions used to do. Which kind of makes sense, but the change should be documented and it wasn't.

What I mean is, in your httpd.conf you'll have (this is an OS X one):

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
    Options +Indexes +FollowSymLinks
    # etc
</Directory>

And then in your extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "/pth/to/somewhere/completely/different"
    ServerName my-virtual-host.dev
    ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
    CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
</VirtualHost>

The VH used to inherit all the settings - not anymore if it's not a subfolder. So what you need to do is copy and paste the settings in the VH (or you can probably create another <directory if you have a lot of VHs in the same place)

<VirtualHost *:80>
    DocumentRoot "/pth/to/somewhere/completely/different"
    ServerName my-virtual-host.dev
    ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
    CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
    <Directory "/pth/to/somewhere/completely/different">
        Options +Indexes
    </Directory>
</VirtualHost>

It's the +Indexes which does the magic.

Monjo answered 6/3, 2015 at 22:35 Comment(1)
In Debian 8.0 Jessie's Apache (2.4) it's needed to explicitly add DocumentRoot /var/www to your /etc/apache2/apache2.conf if you serve multiple virtual hosts with their own document roots.Epexegesis
M
1

In the log you can find an error

[Sun Dec 03 17:38:17.649269 2017] [autoindex:error] [pid 4806] [client ::1:57323] AH01276: Cannot serve directory /etc/httpd/conf/htdocs/: No matching DirectoryIndex () found, and server-generated directory index forbidden by Options directive

to fix it:-

then you must remove the line in /etc/httpd/conf.d/welcome.conf

below existing configuration:-

<LocationMatch "^/+$">
   Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>

solved with the below configuration,:- commented out a line.

<LocationMatch "^/+$">
   #Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>
Morville answered 3/12, 2017 at 16:47 Comment(0)
E
0

for future people,if you follow all above and problem still occur,try this:

httpd.conf(make sure belows are open):
LoadModule alias_module modules/mod_alias.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule autoindex_module modules/mod_autoindex.so
Include conf/extra/httpd-autoindex.conf

extra/httpd-autoindex.conf:

<Directory "change to your directory">
Excurvature answered 4/3, 2016 at 4:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.