未执行PHP代码,而是在页面上显示代码
本文翻译自:PHP code is not being executed, instead code shows on the page
I'm trying to execute some PHP code on a project (using Dreamweaver) but the code isn't being run. 我正在尝试在项目上执行一些PHP代码(使用Dreamweaver),但是该代码未在运行。
When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). 当我检查源代码时,PHP代码显示为HTML标记(我可以在源代码中看到它)。 Apache is running properly (I'm working with XAMPP), the PHP pages are being opened properly but the PHP code isn't being executed. Apache正常运行(我正在使用XAMPP),PHP页面已正确打开,但PHP代码未执行。
Does someone have a suggestion about what is happening? 有人对正在发生的事情有建议吗?
Note: The file is already named as filename.php
注意:该文件已被命名为filename.php
Edit: The Code..: 编辑:代码..:
<?
include_once("/code/configs.php");
?>
#1楼
参考:https://stackoom.com/question/LUKl/未执行PHP代码-而是在页面上显示代码
#2楼
I'm running Apache on Ubuntu and my issue was that the /etc/apache2/mods-available/php5.conf
file was missing this: 我在Ubuntu上运行Apache,但我的问题是/etc/apache2/mods-available/php5.conf
文件缺少此文件:
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
I added it back in and php was parsing php files correctly. 我重新添加了它,php正确地解析了php文件。
#3楼
I found another problem causing this issue and already solved it. 我发现了另一个导致此问题的问题,并已解决。 I accidentally saved my script in UTF-16
encoding. 我不小心将脚本保存为UTF-16
编码。 It seems that PHP5 can't recognize <?php
tag in 16 bit encoding by default. 默认情况下,PHP5似乎无法识别16位编码的<?php
标记。
#4楼
I'm posting this answer because my Virtualmin/Webmin admin interface decided it was a good idea to disable my PHP engine.. took me a while to find the solution, so I thought I'd share it with you guys: 我发布此答案是因为我的Virtualmin / Webmin管理界面认为禁用PHP引擎是个好主意。花了我一段时间才找到解决方案,所以我想与大家分享一下:
Also, be sure to check that none of your website config files related to this specific host or virtualhost have any php_admin_value's in them that turn off PHP, like this: 另外,请确保检查与该特定主机或虚拟主机相关的网站配置文件中是否没有任何php_admin_value可以关闭PHP,例如:
php_admin_value engine Off
When in doubt, comment it... 如有疑问,请评论...
# php_admin_value engine Off
And restart your webserver. 并重新启动您的Web服务器。
#5楼
Check all the packages you have installed for php using: 使用以下命令检查已为php安装的所有软件包:
yum list installed | grep remi
Install all relevant php packages, especially php-devel on your machine. 在您的计算机上安装所有相关的php软件包,尤其是php-devel 。
#6楼
I know it should sound silly... but seldom it happens. 我知道这听起来很傻...但是很少发生。
Check if you are trying to execute php from 检查您是否尝试从以下位置执行php
**http://localhost/info.php**
and not from 而不是
file:///var/www/info.php
ps> you can notice that if you write from shell ps>您会注意到,如果您从shell编写
php info.php
it answer with the code (it means php functions).. 它回答的代码(这意味着PHP功能)。
推荐阅读