我试图在一个项目上执行一些PHP代码(使用Dreamweaver),但代码没有运行。

当我检查源代码时,PHP代码显示为HTML标记(我可以在源代码中看到它)。Apache运行正常(我正在使用XAMPP), PHP页面正在正常打开,但PHP代码没有被执行。

有人有什么建议吗?

注意:该文件已经命名为filename.php

编辑: 代码. .:

<?
include_once("/code/configs.php");
?>


当前回答

使用Debian 10安装Apache + php7测试的最简单方法:

apt-get update -y
apt-get install apache2 php7.0 libapache2-mod-php  -y
sudo service apache2 restart

其他回答

注意,对于PHP 7用户,添加到你的httpd.conf文件:

# PHP 7 specific configuration
<IfModule php7_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
</IfModule>

我知道这听起来很傻……但这种情况很少发生。

检查您是否试图从

**http://localhost/info.php**

而不是来自

file:///var/www/info.php

Ps >你可以注意到如果你从shell写

php info.php 

它回答的代码(它意味着PHP函数)..

这是我的。htaccess

DirectoryIndex index.html index.htm

index.html包含PHP代码。默认情况下,PHP不会将扩展名为htm*的文件作为PHP代码处理。

你可以通过在.htaccess中添加以下内容来覆盖它:

<FilesMatch ".+\.html$">
    SetHandler application/x-httpd-php
</FilesMatch>

我发布这个答案是因为我的Virtualmin/Webmin管理界面决定禁用我的PHP引擎是一个好主意。我花了一段时间才找到解决方案,所以我想和你们分享一下:

同时,确保你的网站配置文件中没有任何与这个特定主机或虚拟主机相关的php_admin_value在它们中关闭PHP,就像这样:

php_admin_value engine Off

有疑问的时候,评论一下…

# php_admin_value engine Off

并重新启动您的web服务器。

重新安装mcrypt模块对我有用。

$sudo apt-get install php5-mcrypt
$sudo php5enmod mcrypt