Apache is ignoring index.php

I am using the distributed version of Apache in Lion and apparently have it working! However, though it serves index.html files it does not recognise index.php files. It just displays the content of the file. If I try to open a directory containing index.php it displays the contents of the directory. In httpd.conf I have the following:

#

# DirectoryIndex: sets the file that Apache will serve if a directory

# is requested.

#

<IfModule dir_module>

DirectoryIndex index.php index.htm index.html

</IfModule>


I thought that this should be sufficient for the server to be forced (persuaded!) to serve the index.php file.

What am I doing wrong? I never had this trouble with SnowLeopard!

😢

Posted on Oct 10, 2013 2:57 PM

Reply
2 replies

Oct 10, 2013 11:06 PM in response to Bob-r

A couple of things to check:


Where is this directive? In httpd.conf?


If so, you should be aware that this directive can be overridden at a virtual host or directory level, or even via .htaccess.


So you should check the rest of your server's configuration for additional DirectoryIndex directives.


Additionally, the diective is in an <IfModule> clause, meaning it only applies if the corresponding module is enabled. You should check httpd.conf to ensure that mod_dir is enabled:

LoadModule dir_module libexec/apache2/mod_dir.so

If this line is commented out, then mod_dir won't load and the IfModule check will fail, preventing the directive from applying.

Oct 11, 2013 9:07 AM in response to Camelot

Thanks Camelot.


Yes, it is in httpd.conf and all the modules were being loaded!

I've since added:



<IfModule mod_php5.c>

# If php is turned on, we respect .php and .phps files.

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

</IfModule>




because I found that it wasn't really serving normal php files - let alone index.php!

And it's now sprung into life - thank goodness 🙂


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apache is ignoring index.php

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.