Jofio wrote:
Hello,
I am a newbie in PHP and I am enthusiastically trying out things. I've
just replaced my
index.html (
file with
index.php
with of course a few lines of php code, which I am sure they are all
correct as far as the syntax goes. I expect the file (index.php) to be
loaded in to the browser window upon launching the browser. It's not
doing that; instead, it loads the apache index file. (Oh, I forgot...
I am running php 5 and apache 2.xxx and modified idex.html to
indexHtml.html to avoid the webserver serving the page).
Huh? Do you mean that you renamed the current index.html ->
indexHtml.html? OK, where's your index.html page now?
I guess that I need to insert a line somewhere in the apache config
file but I don't how...
Any help, please.
First make sure that your index.php page really does work by specifying
it completely. IOW, if your index.php page is at your DocumentRoot then
specify http://<myserver>/index.php. See if that works.
There's no real magic here. Apache, and other web servers for that
matter, is configured to open up a default file if none is specified.
Traditionally that's index.html but more defaults have crept in.
I'm running Apache 2 on Linux. Adjust for your OS. On my OS the
configuration files are under /etc/httpd/conf (some OSes use
/etc/apache/conf or /etc/apache2/conf). Additionally Apache has several
configuration files. A simple grep yeilds me:
$ grep index.php *.conf
commonhttpd.conf: DirectoryIndex index.html index.html.var index.php
index.php3 index.shtml index.cgi index.pl index.htm Default.htm default.htm
So then, it's in the commonhttpd.conf file in /etc/httpd/conf for me.
The parameter is called DirectoryIndex. What follows is the list of
files that Apache will look for when you specify a URL that points to a
directory instead of a file. In my case it's index.html followed by
index.html.var (I believe the .var files are an Apache 2 convention for
multiple languages. I don't use them so I haven't investigated them
further) then index.php (Viola!), index.php3 (old - I probably could get
rid of this), index.shtml (shtml are for server parsed files. I played
with that once), index.cgi (IOW any index.cgi but generally I name my
Perl scripts .cgi), index.pl (again, for Perl), index.htm (old MS
heritage 3 character extensions, which, BTW, Win95 and above can do more
than 3 character extensions) Default.htm and default.htm (Yuck! IIS
influenced names!).
So then just stick the index.php in the list of DirectoryIndex files in
whatever order of importance you see fit (When Apache searches for a
DirectoryIndex first one found wins!) and restart Apache. For exmaple,
given my configuration above if I had an index.html it would be server
first before index.php. That's OK for me because if I consciously
rewrite an index.html to be dynamic making it an index.php I am
replacing the index.html so I'd simply remove it.
--
I used to work at a factory where they made hydrants; but you couldn't
park anywhere near the place.