Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my php tags converted to html comments?

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
like image 543
Zach Lysobey Avatar asked Oct 10 '12 20:10

Zach Lysobey


Video Answer


2 Answers

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

like image 175
João Mendes Avatar answered Oct 17 '22 09:10

João Mendes


Your Chrome is lying to you.

Your PHP source file is <?php echo 'test'; ?>. Because PHP is not executed, this file is sent to the browser. If the browser should interpret this text, it will stumble upon the <? ?> marks. They have a meaning - they are "XML processing instructions", and the text after the opening angle defines the target.

Obviously the browser does not know about a target named "PHP", so this text is ignored.

And then the element inspector tries to display the DOM and is lying about the original source code, because he is working on the PARSED source - which is great because you usually want to know on which data the browser acts, and this includes how the browser interpreted your source.

But if you make any error, the browser will try to fix it, and the fix is included in the element inspector.

Obviously the fix for an unknown XML processing instruction is to disable it by commenting it out.

like image 33
Sven Avatar answered Oct 17 '22 09:10

Sven