Index.php does not open up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jofio

    Index.php does not open up

    Hello,

    I am a newbie in PHP and I am enthusiasticall y 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). I guess that I
    need to insert a line somewhere in the apache config file but I don't
    how...

    Any help, please.

    jofio

  • Andrew DeFaria

    #2
    Re: Index.php does not open up

    Jofio wrote:
    [color=blue]
    > Hello,
    >
    > I am a newbie in PHP and I am enthusiasticall y 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).[/color]

    Huh? Do you mean that you renamed the current index.html ->
    indexHtml.html? OK, where's your index.html page now?
    [color=blue]
    > I guess that I need to insert a line somewhere in the apache config
    > file but I don't how...
    >
    > Any help, please.[/color]

    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.con f: 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.con f 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.

    Comment

    • Jofio

      #3
      Re: Index.php does not open up

      I have renamed index.html to indexHtml.html so to avoid the browser
      from opening the file by default at the launching of a browser. Instead
      I want wanted the index.php to open up by default....

      and oh yes, typing http://localhost/index.php does open the page.
      However, problem is it doesn't open up by default as it should like
      index.html.

      Win XP pro is my OS.

      I've just uppended index.php in the DirectoryIndex line in the
      apache's httpd config file as shown below


      DirectoryIndex index.html index.php index.html.var

      .....don't seem to see any difference.
      But nevertheless, thanks alot.


      jofio

      Comment

      • Andrew DeFaria

        #4
        Re: Index.php does not open up

        Jofio wrote:
        [color=blue]
        > I have renamed index.html to indexHtml.html so to avoid the browser
        > from opening the file by default at the launching of a browser.
        > Instead I want wanted the index.php to open up by default....[/color]

        What a browser opens as a default page is a function of what you tell
        the browser to open as a default - not a function of the web server! My
        default "home" page is set to http://defaria.com on the browser I run at
        home - Firefox. At work it's set to http://news.google.com. Notice none
        of these involve localhost!
        [color=blue]
        > and oh yes, typing http://localhost/index.php does open the page.
        > However, problem is it doesn't open up by default as it should like
        > index.html.[/color]

        You could always set your default home page to
        http://localhost/index.php! ;-)

        What is your default home page set to in your browser? For that matter
        WHAT'S YOUR BROWSER! You neglected to mention that.
        [color=blue]
        > Win XP pro is my OS.
        >
        > I've just uppended index.php in the DirectoryIndex line in the
        > apache's httpd config file as shown below
        >
        > DirectoryIndex index.html index.php index.html.var[/color]

        What's an "uppended"? !? 'Cause I see index.php between index.html and
        index.html.var. Is that what "uppended" means? :-)
        [color=blue]
        > ....don't seem to see any difference.[/color]

        Did you follow the other advice to restart Apache? Changes to the config
        will not go into effect until you do that. Also, is there an index.html
        in your DocumentRoot?
        [color=blue]
        > But nevertheless, thanks alot.[/color]

        Again this is not rocket science here. If you specify http://localhost
        in the address bar (or configure it for the default page to open for
        your browser) then the web server at localhost (default port of 80) will
        be contacted. The server will look at what DocumentRoot is set to (for
        example, C:\HTDocs). Since you didn't specify an actual file then the
        server will search for C:\HTDocs\index .html, because that is what you
        listed first in DirectoryIndex. If that file is found it will be
        retrieved - end of search. If not then the search continues to
        C:\HTDocs\index .php. Assuming you've configured the type for .php files
        to run through PHP it will be run through PHP and the resulting file
        will be displayed. If C:\HTDocs\index .php is not found then
        C:\HTDocs\index .html.var will be use if it is found. Finally, if none
        are found then the server will return 404.
        --
        If love is blind, why is lingerie so popular?

        Comment

        Working...