8

So my PHP project is causing localhost as well as localhost/project/ is downloading the index.php for the project rather than loading it, it downloads it as download...here is the download file:

<?php   
/*
* Index.php - Define the directories
*
*
* DS, DIRECTORY_SEPARATOR = /
* ROOT, dirname = string containing the path of a file or directory
* __FILE__ = The full path and filename of the file. If used inside an include, the name of the included file is returned
*
* In this file we load the apporpriate files that our website wants to load and render the
* template with informatio from the database. We load the bootstrap.php from the library folder.
*
* We are not including the ?\>  to avoid injection of any extra whitespaces in our output.
*
*
*/


define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));

$url = $_GET['url'];

require_once (ROOT . DS . 'library' . DS . 'bootstrap.php');

And loading localhost downloads this:

<?php
    if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
        $uri = 'https://';
    } else {
        $uri = 'http://';
    }
    $uri .= $_SERVER['HTTP_HOST'];
    header('Location: '.$uri.'/xampp/');
    exit;
?>
Something is wrong with the XAMPP installation :-(
5
  • You might not have loaded the PHP module for apache? Commented Jul 13, 2013 at 14:55
  • Do you know how to load this manually on ubuntu? I will search to try it Commented Jul 13, 2013 at 14:56
  • 2
    Are you actually using XAMPP on Ubuntu? I mean, the stuff from apachefriends? - they can't even get their own website right (Or is #META TITLE# supposed to be the actual page title?). Just "sudo apt-get install apache2 php5 libapache2-mod-php5 mysql" and off you go... Commented Jul 13, 2013 at 15:27
  • Hey @germainelol, did you actually get to find the solution for this. I think I got the exact same problem.... Commented Oct 7, 2013 at 2:14
  • I don't think this is an issue with php handler. Check whether your index.php file is having executive permission. Try "chmod 644 index.php". Give 644 permission for index.php. It will resolve :) Commented Nov 12, 2013 at 7:04

7 Answers 7

6

I have the same problem (using Ubuntu 12.04) and also have a line in the .htaccess like pi4r0n, e.g.,

AddHandler application/x-httpd-php54s .php

The XAMPP does not have the same version of PHP as the AddHandlercommand is calling (mine has v5.3.8). I have found that commenting it out, as pi4r0n did, i.e.,

# AddHandler application/x-httpd-php54s .php

will allow it to work on the local server. You just need to remember to change it before uploading it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks it worked in my mac. I struggled to find the reason to make it work and followed all the available answers. Finally just commenting the above mentioned in .htaccess file it worked.
This helped me as well! Technically original credit to @pi4r0n but this was closer to my exact answer. Thank you both!
In my case both localhost and server are on PHP 7.4, but i was still facing the issue. Commenting out this line did work, many thanks!
2

Guys I had exactly the same problem as well and in my cases it was htaccess file. By mistake I have download it from my server (cPanel server) and the htaccess looked like this

# Use PHP5.4 as default AddHandler application/x-httpd-php54 .php

but because I do not have PHP5.4 installed it locally on XAMPP, it did not know what to do with the file.

So my advice would be to make sure your htaccess files if you got any are removed or are correct ;)

1 Comment

In my case both localhost and server are on PHP 7.4, but i was still facing the issue (and I also had downloaded the cPanel .htaccess file by mistake). Commenting out the cPanel generated lines (in localhost) did work, many thanks!
1

In my case, the problem is that I have the project in cPanel and if try to execute the project in my local, Xampp upload file instead open localhost.

In cPanel I have the version 7.2 of php and in my local I have version 7.4.

In my case the reason of this uses is that cPanel generate a handler in the .htaccess file:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

so to be able to execute the project in local we need to comment this line, like this:

#AddHandler application/x-httpd-ea-php74 .php .php7 .phtml

Comments

0

I had the same issue on my Ubuntu desktop computer. Using filezilla (or any other file explorer) I deleted a hidden a htaccess file from the parent directory.

And it was solved. Back to normal web page display.

(I am not sure if that htaccess file was important for the desktop computer, but I am sure I did not add that on my live server..hence I deleted it. Let me know if I am wrong)

Comments

0

This is for MAC Version 10.15.4.

If you have XAMPP installed, you can try adding following lines to httpd.conf locating at /Applications/XAMPP/xamppfiles/apache2/conf.

AddType application/x-httpd-php .htm .html

If I do not work, try to delete cache of your browsers or restart your computer.

Note: If you have .htaccess file in the same root directory, you should delete it to prevent browsers download your php or html file.

Comments

0

In addition to updating php.ini file and setting enable_post_data_reading=On, make sure you start XAMPP (go to where it's installed and doubleclick xampp_start)

Comments

-1

**

this error comes up due to few codes written in .htaccess when you upload your file in Cpanel you just have to remove this part of the code in .htaccess file solve this download error or change the version of php in .htaccess file.

remove "#" sign as well

php -- BEGIN cPanel-generated handler, do not edit Set the “ea-php74”

package as the default “PHP” programming language.

AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml

php -- END cPanel-generated handler, do not edit

Or just use this .htacess file downloading from the link

https://mega.nz/file/PU803bDA#evpjZZ0Yz6KQYw8xWVvIz_RNqV4xeyHq5RhDEtcNUYI

1 Comment

Please include the file as plaintext.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.