ubuntu 上的 Apache 2 服务器无法解析 html 文件中的 php 代码

问题描述:

我在 Ubuntu 13.04 上安装了 apache2、php5 和 php5 apache 模块.

I installed apache2, php5 and the php5 apache module on Ubuntu 13.04.

PHP 正在处理 .php 文件,但 html 文件中的 php 代码行不执行.

Php is working on .php files but lines of php code inside html files do not execute.

谷歌搜索我发现必须将 AddHandler...AddType... 行添加到 httpd.conf 但安装的版本没有此文件或至少在 /etc/apache2/

Googling I found that must add AddHandler... and AddType... lines to httpd.conf but the version installed doesn't have this file or at least can't find it in /etc/apache2/

代码示例:

<html>
<head></head>
<body>
    <?php 
      phpinfo(); 
    ?>
</body>
</html>

开始工作.我的 apache 版本没有 httpd.conf,而是在 /etc/apache2/mods-enabled/

Got it to work. my version of apache doesn't have httpd.conf, instead has php5.conf in /etc/apache2/mods-enabled/

编辑那个文件,发现这个:

editing that file, found this:

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler applicatio
    ....
....

添加了以下几行:

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

现在 php 解析 html 文件并且 代码有效.

now php parses the html files and <?php ... ?> code works.