简体   繁体   English

PHP xampp 下载我的 index.php 而不是加载页面

[英]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 项目导致localhost以及localhost/project/正在下载项目的index.php而不是加载它,它下载它作为download ...这里是download文件:

<?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:并加载localhost下载:

<?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,我有同样的问题(使用 Ubuntu 12.04)并且在 .htaccess 中也有一行像 pi4r0n,例如,

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). XAMPP 与AddHandler命令调用的 PHP 版本不同(我的版本为 v5.3.8)。 I have found that commenting it out, as pi4r0n did, ie,我发现注释掉它,就像 pi4r0n 所做的那样,即,

# 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.伙计们,我也遇到了完全相同的问题,在我的情况下是 htaccess 文件。 By mistake I have download it from my server (cPanel server) and the htaccess looked like this我错误地从我的服务器(cPanel 服务器)下载了它,htaccess 看起来像这样

# Use PHP5.4 as default AddHandler application/x-httpd-php54 .php # 使用 PHP5.4 作为默认 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.但是因为我没有在 XAMPP 上本地安装 PHP5.4,所以它不知道如何处理该文件。

So my advice would be to make sure your htaccess files if you got any are removed or are correct ;)因此,我的建议是确保您的htaccess文件是否已删除或正确;)

I had the same issue on my Ubuntu desktop computer.我在我的 Ubuntu 台式计算机上遇到了同样的问题。 Using filezilla (or any other file explorer) I deleted a hidden a htaccess file from the parent directory.使用 filezilla(或任何其他文件资源管理器)我从父目录中删除了一个隐藏的 htaccess 文件。

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) (我不确定该 htaccess 文件对台式计算机是否重要,但我确定我没有在我的实时服务器上添加它。因此我删除了它。如果我错了,请告诉我)

This is for MAC Version 10.15.4.这适用于 MAC 版本 10.15.4。

If you have XAMPP installed, you can try adding following lines to httpd.conf locating at /Applications/XAMPP/xamppfiles/apache2/conf.如果您安装了 XAMPP,您可以尝试在位于 /Applications/XAMPP/xamppfiles/apache2/conf 的 httpd.conf 中添加以下行。

AddType application/x-httpd-php .htm .html 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.注意:如果你在同一个根目录下有 .htaccess 文件,你应该删除它以防止浏览器下载你的 php 或 html 文件。

除了更新 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.就我而言,问题是我在 cPanel 中有项目,如果尝试在我的本地执行项目,Xampp 上传文件而不是打开 localhost。

In cPanel I have the version 7.2 of php and in my local I have version 7.4.在 cPanel 中我有 7.2 版的 php,而在我的本地我有 7.4 版。

In my case the reason of this uses is that cPanel generate a handler in the .htaccess file:在我的情况下,这种使用的原因是 cPanel 在 .htaccess 文件中生成一个处理程序:

# 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.当您在 Cpanel 中上传文件时,由于 .htaccess 中编写的代码很少,因此出现此错误,您只需删除 .htaccess 文件中的这部分代码即可解决此下载错误或更改 .htaccess 文件中的 php 版本。

remove "#" sign as well删除“#”号

php -- BEGIN cPanel-generated handler, do not edit Set the “ea-php74” php -- BEGIN cPanel 生成的处理程序,不要编辑设置“ea-php74”

package as the default “PHP” programming language.包作为默认的“PHP”编程语言。

AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml AddHandler 应用程序/x-httpd-ea-php74___lsphp .php .php7 .phtml

php -- END cPanel-generated handler, do not edit php -- 结束 cPanel 生成的处理程序,不要编辑

Or just use this .htacess file downloading from the link或者只是使用从链接下载的这个 .htacess 文件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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