ubuntu 上的 Apache 2 服务器无法解析 html 文件中的 php 代码 [英] Apache 2 server on ubuntu can't parse php code inside html file
问题描述
我在 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.
这篇关于ubuntu 上的 Apache 2 服务器无法解析 html 文件中的 php 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!