简体   繁体   中英

PHP xampp downloading my index.php instead of loading the page

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 :-(

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

AddHandler application/x-httpd-php54s .php

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

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

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 ;)

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)

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.

除了更新 php.ini 文件并设置 enable_post_data_reading=On 之外,请确保启动 XAMPP(转到安装位置并双击 xampp_start)

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

**

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM