Connecting Tech Pros Worldwide Help | Site Map

PHP files coming up as files to download

Newbie
 
Join Date: Dec 2007
Posts: 10
#1: Jan 22 '09
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's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#2: Jan 29 '09

re: PHP files coming up as files to download


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:
Expand|Select|Wrap|Line Numbers
  1. AddType application/x-httpd-php .php .phtml .php3
  2. AddType application/x-httpd-php-source .phps
Note, you can add file extensions to that list if you want Apache to handle them as PHP as well.
Newbie
 
Join Date: Dec 2007
Posts: 10
#3: Jan 29 '09

re: PHP files coming up as files to download


Thanks Atli.

This really helped
Newbie
 
Join Date: Mar 2009
Posts: 1
#4: Mar 23 '09

re: PHP files coming up as files to download


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.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#5: Apr 8 '09

re: PHP files coming up as files to download


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.
Reply