为什么我的PHP代码转换为HTML评论? [英] Why are my php tags converted to html comments?

查看:173
本文介绍了为什么我的PHP代码转换为HTML评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个朋友的灯主机似乎配置错​​误。我试图执行PHP的,但它似乎并不奏效。

在Chrome浏览器的检查元素:

 <?PHP的回声测试; ?>
 

变成了:

 <! -  PHP的回声测试?; ? - >
 

此外,它已引发了文件下载,而不是打开它作为一个网页。

我已经试过各种code在的.htaccess 文件,但它似乎并没有产生任何影响:

 将AddType的X MAPP-PHP5的.php
将AddType应用/ X的httpd  -  PHP的.php
AddHandler的的X MAPP-PHP5的.php
 

解决方案

要正确配置PHP运行的地方是的httpd.conf 文件,该文件驻留在 CONF 子目录Apache安装目录下。

在那里,你要寻找的模块加载部分,这将是一堆与的LoadModule 开始行。某处在那里,你应具有以下(或非常类似的东西):

 的LoadModule php5_module的\你\ PHP \安装位置\
将AddType应用/ X的httpd  -  PHP的.php
中的PHPIniDir的\你\ PHP \配置\文件位置\
 

我不是太熟悉Linux,但在Windows(WAMP)安装,这些将是沿着线的东西:

 的LoadModule php5_moduleC:/程序文件/ PHP / php5apache2.dll
将AddType应用/ X的httpd  -  PHP的.php
中的PHPIniDirC:/程序文件/ PHP
 

的httpd.conf 的文件,我的机器上,是 C:\ Program Files文件\ Apache的集团\的Apache2 \的conf \ httpd的。 CONF

这也可能是PHP根本就不是你的机器上安装的,在这种情况下,你必须下载并安装它。布拉德的已经贴在了他的意见的一个相关链接,(+1,顺便说一句,布拉德),而是为了拥有一切在一个地方的:

PHP:安装和配置 - 手动

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

In Chrome's inspect element:

<?php echo 'test'; ?> 

becomes :

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

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

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

解决方案

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

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 "location\of\your\php\installation"
AddType application/x-httpd-php .php
PHPIniDir "location\of\your\php\configuration\file"

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"

And the httpd.conf file, on my machine, is at C:\Program Files\Apache Group\Apache2\conf\httpd.conf.

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: Installation and Configuration - Manual

这篇关于为什么我的PHP代码转换为HTML评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆