PDA

View Full Version : PHP: making index files work


drewprops
2005-11-20, 02:26
I've set up a new website using PHP but to my surprise the index page (index.php) doesn't automatically load in Safari or Firefox. Can anyone enlighten me as to what I'm supposed to do to make a PHP index page load automatically like HTML index pages normally do? Am I supposed to alter the .htaccess file? Keep banging the rocks together?

chucker
2005-11-20, 02:32
I've set up a new website using PHP but to my surprise the index page (index.php) doesn't automatically load in Safari or Firefox. Can anyone enlighten me as to what I'm supposed to do to make a PHP index page load automatically like HTML index pages normally do? Am I supposed to alter the .htaccess file? Keep banging the rocks together?

What webserver are you on? Your local one? A hosted one (in that case, does it offer PHP?).

Presumably, you're on something Apache-based. To make Apache look for index.php files, make sure the DirectoryIndex directive includes that. You can enforce this with .htaccess like this:

DirectoryIndex index.php

You should give more information first what kind of server you're talking about though. :)

drewprops
2005-11-20, 02:39
Bingo, Chucker.

It's Apache-based and it's working now. That bit you mentioned...


DirectoryIndex index.php


.... did the trick.

I just found an article with your same tip in it (in the WordPress docs) and came back here to post that I'd found it. Good show sir, this here programmers forum is pretty spiffy.

Now to bang out the CSS browser bugs in the website.... if anyone is interested the site is www.film-ga.com and is still in giddy first-legs mode~

chucker
2005-11-20, 02:42
Glad to be of help. :)

torifile
2005-11-21, 00:15
Make sure you don't remove the reference in that line to "index.html". Just put it after the index.php reference. This way, if you don't have an index.php file in the directory, but an index.html, it will automatically load that. I usually add index.htm just for good measure.

edit: I just realized that you're probably not making changes to the httpd.conf file, so never mind. :) If you are reading this and making changes to the httpd.conf file on your local box, the above applies.

drewprops
2005-11-21, 09:07
Nope, not messing with the httpd.conf file (whatever that is!!).
For confirmation, I did not create a reference to index.html or index.htm in the .htaccess file and am curious if I need to do so (even after reading your edit Tori). I don't have access to that domain while I'm at work so I can't do a quick experiment to see what would happen if I only had an .html or .htm file in there.

What's the normal setup for how these things behave?

Majost
2005-11-21, 10:33
I believe .htaccess will override all previous settings. So, you'll want it to sayDirectoryIndex index.html index.htm index.php or whatever in the order that you want it.

Just a note to everyone else - .htaccess is disabled by default on Mac OS X. So, if you're locally serving your webpages, you'll want to make these changes inside /etc/httpd/httpd.conf.

And if you want to enable .htaccess, you'll need to change your httpd.conf file such that the second "AllowOverride None" directive becomes "AllowOverride All." And, you'll need to make the same change in /etc/httpd/users/your_username.conf. And then if you're using Virtual Servers, you'll need to add "AllowOverride All" into your virtual server block in httpd.conf.

But, you don't want to enable .htaccess if you don't have to... you end up with a performance hit since Apache looks through every single directory on its way to the file requested for an .htaccess file.

Yeah, I just spent three hours figuring all that out. Figured I'd leave it all here for posterity.

ast3r3x
2005-11-21, 12:15
Although the speed his is rather negligable. Maybe more if you are using are hosting locally though.