PDA

View Full Version : Apache2 DirectoryIndex Override?



Dalrain
06-Mar-2012, 15:54
Hello,
We use SLES 10 and 11 at my workplace to provide web services using PHP apps. Unfortunately, I noticed that every time apache gets patched, it insists on replacing /srv/www/htdocs/index.html, which breaks the server by throwing "It Works!" at clients. I created a /etc/apache2/httpd.conf.local file and added it to /etc/sysconfig/apache2 as an INCLUDE, which has "DirectoryIndex index.php index.html index.htm" That directive is listed in order of preference, but the apache httpd still prefers the stupid index.htm. I know there's a DirectoryIndex declaration in /etc/apache2/httpd.conf, but the instructions in that file say not to modify the file directly!

In addition, I see that the PHP file contains multiple DirectoryIndex declarations, each on their own line, which suggests the directive is additive. Help! How can I avoid the blasted "It Works!" index.html taking over every patch release?

Edit: Grammar

Dalrain
06-Mar-2012, 16:26
For the tl;dr crowd: How can I make Apache HTTPd prefer index.php over index.html, while respecting the advice in /etc/apache2/httpd.conf to not edit it directly?

smflood
09-Mar-2012, 16:50
On 06/03/2012 15:04, Dalrain wrote:

> We use SLES 10 and 11 at my workplace to provide web services using PHP
> apps. Unfortunately, I noticed that every time apache gets patched, it
> insists on replacing /srv/www/htdocs/index.html, which breaks the server
> by throwing "It Works!" at clients. I created a
> /etc/apache2/httpd.conf.local file and added it to
> /etc/sysconfig/apache2 as an INCLUDE, which has "DirectoryIndex
> index.php index.html index.htm" That directive is listed in order of
> preference, but the apache httpd still prefers the stupid index.htm. I
> know there's a DirectoryIndex declaration in /etc/apache2/httpd.conf,
> but the instructions in that file say not to modify the file directly!
>
> In addition, I see that the PHP file contains multiple DirectoryIndex
> declarations, each on their own line, which suggests the directive is
> additive. Help! How can I avoid the blasted "It Works!" index.html
> taking over every patch release?

In your /etc/apache2/httpd.conf.local try adding the following lines

<Directory /srv/www/htdocs>
AllowOverride Indexes
</Directory>
DirectoryIndex index.php index.html index.htm

HTH.
--
Simon
Novell/SUSE/NetIQ Knowledge Partner

------------------------------------------------------------------------
Do you work with Novell technologies at a university, college or school?
If so, your campus could benefit from joining the Novell Technology
Transfer Partner (TTP) program. See novell.com/ttp for more details.
------------------------------------------------------------------------

Dalrain
09-Mar-2012, 17:21
On 06/03/2012 15:04, Dalrain wrote:

In your /etc/apache2/httpd.conf.local try adding the following lines

<Directory /srv/www/htdocs>
AllowOverride Indexes
</Directory>
DirectoryIndex index.php index.html index.htm



No dice, it would appear. Specifically, the server prefers index.html (not index.htm) - I think this is probably because DirectoryIndex is additive, so any directive appearing after the initial declaration is at a lower precedence. (Rather than overriding, that is.)

The first line apache would encounter is the following, which I'm guessing means it remains the first thing it looks for (from httpd.conf):
# List of resources to look for when the client requests a directory
DirectoryIndex index.html index.html.var

I think this might be a case where SuSEconfig needs to allow for precedence in the sysconfig dir.

Dalrain
09-Mar-2012, 17:25
Derp. Self replying because I got it now, in part due to your answer. It actually works if you just toss the index directive into a Directory container i.e.

<Directory /srv/www/htdocs>
AllowOverride Indexes
DirectoryIndex index.php index.html index.htm
</Directory>

Thank you for the response, Simon!

smflood
09-Mar-2012, 17:53
On 09/03/2012 16:34, Dalrain wrote:

> Derp. Self replying because I got it now, in part due to your answer.
> It actually works if you just toss the index directive into a Directory
> container i.e.
>
> <Directory /srv/www/htdocs>
> AllowOverride Indexes
> DirectoryIndex index.php index.html index.htm
> </Directory>

Ah yes DirectoryIndex within the Directory would take precedence over
the default configured via /etc/apache2/httpd.conf whereas having it
outside is still cumulative though would apply to all directories
(something to bear in mind if you want to access PHP-based sites from
other directories).

> Thank you for the response, Simon!

No problem, glad you've now got it working.
--
Simon
Novell/SUSE/NetIQ Knowledge Partner

------------------------------------------------------------------------
Do you work with Novell technologies at a university, college or school?
If so, your campus could benefit from joining the Novell Technology
Transfer Partner (TTP) program. See novell.com/ttp for more details.
------------------------------------------------------------------------