本文介绍了为什么我的 php 标签会转换为 html 注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友的灯主机似乎配置错​​误.我尝试执行 php,但它似乎不起作用.

A friend's lamp host seems to be misconfigured. I try to execute php, but it doesn't seem to be working.

在 Chrome 的检查元素中:

In Chrome's inspect element:

<?php echo 'test'; ?>

变成:

<!--?php echo 'test'; ?-->

此外,它会触发文件下载,而不是将其作为网页打开.

Furthermore, its been triggering a file download, rather than opening it as a webpage.

我在 .htaccess 文件中尝试了各种代码,但似乎没有任何效果:

I've tried various code in an .htaccess file, but it doesn't seem to have any effect:

AddType x-mapp-php5 .php
AddType application/x-httpd-php .php
AddHandler x-mapp-php5 .php

推荐答案

正确配置 PHP 操作的地方是 httpd.conf 文件,它位于 confApache 安装目录的子目录.

The place to correctly configure PHP operation is the httpd.conf file, which resides in the conf subdirectory of your Apache installation directory.

在那里,您需要查找模块加载部分,这将是一堆以 LoadModule 开头的行.在那里的某个地方,您应该拥有以下内容(或非常相似的内容):

In there, you'll want to look for the module loading section, which will be a bunch of lines that start with LoadModule. Somewhere in there, you should have the following (or something very similar):

LoadModule php5_module "locationofyourphpinstallation"
AddType application/x-httpd-php .php
PHPIniDir "locationofyourphpconfigurationfile"

我对 Linux 不太熟悉,但在 Windows (WAMP) 安装中,这些内容大致如下:

I'm not all too familiar with Linux, but in Windows (WAMP) installations, those would be something along the lines of:

LoadModule php5_module "c:/program files/php/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/program files/php"

我机器上的 httpd.conf 文件位于 C:Program FilesApache GroupApache2confhttpd.conf.

And the httpd.conf file, on my machine, is at C:Program FilesApache GroupApache2confhttpd.conf.

也可能是您的机器上根本没有安装 PHP,在这种情况下,您必须下载并安装它.布拉德已经在他的一条评论中发布了相关链接(顺便说一下,布拉德+1),但为了将所有内容集中在一个地方:

It could also be that PHP is simply not installed at all on your machine, in which case, you will have to download it and install it. Brad's already posted the relevant link in one of his comments, (+1, by the way, Brad), but for the sake of having everything in one spot:

PHP:安装和配置 - 手册

这篇关于为什么我的 php 标签会转换为 html 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 12:27