PHP files coming up as files to download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Johnymap
    New Member
    • Dec 2007
    • 10

    PHP files coming up as files to download

    Hi everyone.

    I have migrated my site from Apache 1.3 web server to Apache2 and now when i open php files, they pop up in a download window instead of executing.

    I searched all around but no solution found. Someone please help.

    Thank you in advance
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    This usually happens because you have not told Apache to handle .php files as PHP code.
    So, when you open a .php file, Apache, not knowing what to do with it, will send it as a PHP file, which the browser doesn't know how to handle.

    You need to add the following to your Apache configuration:
    [code=php]
    AddType application/x-httpd-php .php .phtml .php3
    AddType application/x-httpd-php-source .phps[/code]
    Note, you can add file extensions to that list if you want Apache to handle them as PHP as well.

    Comment

    • Johnymap
      New Member
      • Dec 2007
      • 10

      #3
      Thanks Atli.

      This really helped

      Comment

      • nannajul
        New Member
        • Mar 2009
        • 1

        #4
        Ok, I am completely new to all this stuff. Apache, php, mysql etc. I am reading a book and trying to take my basic knowledge up a notch. I have installed Apache, php and mysql onto my system via XXAMP, and everything seems to be working apart from getting php files to open in the browser [I get the option to save the file]. I can access localhost, Myphpadmin, and create databases etc.

        I have searched numerous forums, and they all seem to give an answer similar to the answer provided in this thread - the problem is, being completely new to this, I don't know how to tell Apache to do it. I see the code examples given to add to the apache configuration - but how do I do that?

        Thanks in advance for any help - being new to this, it probably seems very simple to a lot of people, but I really don't know where to go to make this change to the configuration.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi, nannajul.

          You need to alter the Apache configuration file, "my.cnf". (Or "my.ini" on Windoze)
          It is usually located in the Apache installation directory, although if you installed this as a part of some package it may be located somewhere else.

          In any case, you just need to find that file, open it in a text editor and add the lines I posted to it.

          I don't recommend using Notepad to open it... Notepad has problems with Unix style line-breaks.

          Comment

          Working...