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?
|
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? |
|||
|
|
|
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:
Follow up with a restart of the Apache service and php should load into Apache to run just fine. |
|||
|
|
|
Some reasons I have found that this happens:
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 |
|||||||||||||
|
|
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? |
|||||
|
|
A usual error is to print something to the page before the headers get sent. |
|||
|
|
|
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:
But in your actual server you may be running another version of PHP. So it would not excecute right. |
|||
|
|