Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a local LAMP server set up on my Ubuntu laptop for testing various PHP scripts.

Sometimes, when I do something wrong, instead of getting an error, the script I'm testing is offered for download. Why is that and how can it be fixed?

share|improve this question
up vote 2 down vote accepted

The server does not recognize the script as something to execute locally, and as such it offers it as a file instead.

These lines should be present in your Apache config. Note that the path may need to be changed for the .so modules, depending on your configuration:

# -- if you're using PHP 5, uncomment this line to activate it
#LoadModule php5_module libexec/

# -- if you're using PHP 4, uncomment this line to activate it
#LoadModule php4_module libexec/

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

Follow up with a restart of the Apache service and php should load into Apache to run just fine.

share|improve this answer

Some reasons I have found that this happens:

  • if php is not configured correctly on the server
  • if the file doesn't have the correct .php extension
  • if it is in a directory that does not allow execution
  • if the script takes too long to execute.

One test I use is to make a file in the same directory (verify.php) that contains:


If that file executes in my browser, it the first 3 points are ok

share|improve this answer
Good call, always have a process to test the environment. It does not have to be elaborate, something simple like Brent's verify.php is perfect. – BillN Jun 13 '09 at 15:33
From my experience, if Apache/PHP are set up correctly, it's usually script execution timeout. – analytik Jun 13 '09 at 17:21
It's not a script execution timeout in my case. – scribu Jun 13 '09 at 17:43

I would agree with Avery, that's the usual cause. However, you specifically say it's only sometimes. Any chance you are changing the content type header?

share|improve this answer
No, at least I don't think I am. I was actually working on a WordPress plugin and one minute it was working and after modifying something trivial, I got the download dialog. – scribu Jun 13 '09 at 17:47

A usual error is to print something to the page before the headers get sent.

share|improve this answer

Also note that if you have a .htaccess file in the same folder as your php script, it could be the reason for some execution problems.

For example, if you got a copy of the site files from another server, your htaccess file could have a line like:

AddHandler x-httpd-php5-3 .php

But in your actual server you may be running another version of PHP. So it would not excecute right.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.