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'; ?>
<!--?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
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
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"
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:
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.
This just happened to me. Turned out I had forgotten to change the filetype from .html to .php
Sounds to me that your PHP is not correctly configured or installed in your lamp configuration. What distribution are you using? It might be as simple as running a command to re-install PHP, otherwise you will likely need to compile apache with php support.
This answer doesn’t apply to the OP’s specific variant of this problem, but I had the basic same issue –
<? var_dump($test); ?> being converted to
<!--? var_dump($test); ?--> – which I could solve by enabling
short_open_tag in php.ini.
I was faced with exact same problem when I accidently tried to test local php file in browser on server through
file:// protocol, not through installed site.
So the answer is one: “Mr. PHP has left the building”. We need to check the configuration, location of a file or access.
And browser is just trying to fix a web page and help us.
If you are placing your code outside the standard directories (development scenario, in my case) you should check in your /etc/apache2/mod-enabled or /etc/apache2/mod-available in the php5.conf (for ubuntu) and comment the lines that the comment indicates:
# To re-enable PHP in user directories comment the following lines # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it # prevents .htaccess files from disabling it. <IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule>
Sounds like you are using an editor that is changing what you enter. Make sure that what you want in the file is what is actually in the file. Using FTP to upload a php file should ensure this.
I just solved this same problem.
You need to open your file from your WAMP, and not from your hard drive directrory.
In your browser, put:
Otherwise, your browser will replace all
<!-- ?php ?-->
It seems you have to instruct apache explicitly to handle html files as php files, I was having the same problem but renaming the file to .php solved the issue for me.
On an Ubuntu system, installing the apache php5 plugin worked for me:
sudo apt-get install libapache2-mod-php5 sudo service apache2 restart
I have same problem sometimes, probably the extension of your file is “html”.
Change It to “php” and it’ll OK.
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂