[英]PHP Files Being Downloaded instead of showing on website
So I installed Php70* on my amazon Linux Server, and have apache (httpd) installed and when i go to view the php page on my browser, it downloads the php file instead of showing on the browser.所以我在我的亚马逊 Linux 服务器上安装了 Php70*,并安装了 apache (httpd),当我在浏览器上查看 php 页面时,它会下载 php 文件而不是在浏览器上显示。
I tried different browsers, clearing the cache, checking the permissions to my php files and the error perists.我尝试了不同的浏览器,清除了缓存,检查了我的 php 文件的权限,但错误仍然存在。
here is what I have on my system hope it helps;这是我系统上的内容,希望对您有所帮助; Anything else I could be missing?
还有什么我可能会遗漏的吗? Any help is appreciated.
任何帮助表示赞赏。
(i have a simple php file called "phpinfo.php" and in it is (我有一个简单的 php 文件,叫做“phpinfo.php”,里面是
on my ec2 instance at the terminal i can successfully do php phpinfo.php在终端的 ec2 实例上,我可以成功地执行 php phpinfo.php
php -v
PHP 7.0.14 (cli) (built: Jan 18 2017 19:13:23) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.14, Copyright (c) 1999-2016, by Zend Technologies
httpd -v
Server version: Apache/2.4.25 (Amazon)
Server built: Jan 19 2017 16:55:49
I got all php70 packages installed:我安装了所有 php70 包:
sudo yum list installed php70*
Loaded plugins: priorities, update-motd, upgrade-helper
Installed Packages
php70.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-bcmath.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-cli.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-common.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-dba.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-dbg.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-devel.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-embedded.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-enchant.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-fpm.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-gd.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-gmp.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-imap.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-intl.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-json.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-ldap.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-mbstring.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-mcrypt.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-mysqlnd.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-odbc.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-opcache.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-pdo.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-pdo-dblib.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-pecl-apcu.x86_64 5.1.5-2.2.amzn1 @amzn-main
php70-pecl-apcu-devel.x86_64 5.1.5-2.2.amzn1 @amzn-main
php70-pecl-igbinary.x86_64 1.2.2-0.1.20151217git2b7c703.5.amzn1 @amzn-main
php70-pecl-igbinary-devel.x86_64
1.2.2-0.1.20151217git2b7c703.5.amzn1 @amzn-main
php70-pecl-imagick.x86_64 3.4.2-1.4.amzn1 @amzn-main
php70-pecl-imagick-devel.x86_64
3.4.2-1.4.amzn1 @amzn-main
php70-pecl-memcache.x86_64 3.0.9-0.4.20160311git4991c2f.8.amzn1 @amzn-main
php70-pecl-memcached.x86_64 3.0.0-0.1.20160217git6ace07d.2.amzn1 @amzn-main
php70-pecl-oauth.x86_64 2.0.2-1.2.amzn1 @amzn-main
php70-pecl-ssh2.x86_64 1.0-5.16.amzn1 @amzn-main
php70-pecl-uuid.x86_64 1.0.4-7.1.amzn1 @amzn-main
php70-pecl-yaml.x86_64 2.0.0-1RC8.3.amzn1 @amzn-main
php70-pgsql.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-process.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-pspell.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-recode.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-snmp.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-soap.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-tidy.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-xml.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-xmlrpc.x86_64 7.0.14-1.20.amzn1 @amzn-updates
php70-zip.x86_64 7.0.14-1.20.amzn1 @amzn-updates
I saw people mentioning to change the /etc/httpd/conf/httpd.conf file to include addtype/handler so here is what I have:我看到有人提到要更改 /etc/httpd/conf/httpd.conf 文件以包含 addtype/handler 所以这就是我所拥有的:
grep -n "php" /etc/httpd/conf/httpd.conf
54:LoadModule php7_module modules/libphp-7.0.so
163: DirectoryIndex index.html index.php
175: SetHandler application/x-httpd-php
287: AddType application/x-httpd-php .php
288: AddType application/x-httpd-php-source .phps
301: AddHandler php7-script .php
302: AddHandler application/x-httpd-php .phps
303: AddHandler application/x-httpd-php .php
I also have the short_open_tags=on just in case:我也有 short_open_tags=on 以防万一:
grep short_open_tag php-7.0.ini
; short_open_tag
short_open_tag = On
grep short_open_tag php.ini
; short_open_tag
short_open_tag = On
I've been through the same issue too for about two days.我也遇到了同样的问题大约两天。 This [link][1] solved mine!
这个 [link][1] 解决了我的问题!
If any of the solutions in that link doesn't work, then here are a few other things to checkout for:如果该链接中的任何解决方案都不起作用,那么这里还有一些其他的东西需要检查:
Advisably, uninstall php* entirely and install a new one.建议完全卸载 php* 并安装一个新的。 Be sure of the version of php you installed.
请确定您安装的 php 版本。 You can check with
php -v
你可以用
php -v
查看
Work on your .htaccess file.处理您的 .htaccess 文件。 It might be causing a download for you instead of executing your script (in some cases)
它可能会导致为您下载而不是执行您的脚本(在某些情况下)
Check your httpd/apache2 config files: This is very important, If you mapped the wrong or incorrect module in your config file.检查您的 httpd/apache2 配置文件:这非常重要,如果您在配置文件中映射了错误或不正确的模块。 it can cause issues.
它可能会导致问题。
Check out directives such as AddHandler and AddType.查看 AddHandler 和 AddType 等指令。 It should look like the below for PHP:
对于 PHP,它应该如下所示:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddHandler application/x-httpd-php52 .php
This can vary depending on your PHP version.这可能因您的 PHP 版本而异。
Make sure you have php-.so (linux) or php-.dll (windows) in your apache/httpd module folder (That's to be extra sure that php is enabled and that php is loaded for apache correctly).确保你的 apache/httpd 模块文件夹中有 php-.so (linux) 或 php-.dll (windows)(这要特别确保 php 已启用并且 php 已正确加载到 apache)。
If any of these still doesn't work out,Restart your server and Hard Reload/Clear Browser Cache.如果其中任何一个仍然无法解决,请重新启动您的服务器并硬重新加载/清除浏览器缓存。 Then Reload Page.
然后重新加载页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.