My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.
I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.
This is what I'm using to test:
<!DOCTYPE html>
<body>
<?php
echo("php working");
?>
</body>
</html>
Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.
EDIT:
Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.
SECOND EDIT:
I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?
have you made sure to install php correctly within apache?
if you are using php as a module, you need the following:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
or as a CGI binary
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
# For PHP 4
Action application/x-httpd-php "/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?
lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config
AddType application/x-httpd-php .html .htm
Do you see the line like this in your htaccess file?
php_flag engine off
If yes, delete it.
One more thing that may help you understand what happened
The following piece of htaccess would make Php from being executed but rather downloaded as a text file
<VirtualHost *>
ServerName sourcecode.testserver.me
DocumentRoot /var/www/example
AddType text/plain php
</VirtualHost>
One more thing
I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading
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
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: localhost/...../yourfile.php
Otherwise, your browser will replace all <?php ?>
with <!-- ?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.
Recently I configured Apache 2.2 server to run PHP and have configured to load PHP 5 as a module. I am able to start Apache with no problems but when I try to run PHP files it pops up would you like to open or save file?
Running on Windows XP SP3
Internet Explorer browser but not related
Simply trying to open it as a file not as my index.php and haven't set Apache to look for that as my index. If it helps I think my issue might be here:
;AddType application/x-httpd-php .php
;AddType application/x-httpd-php .php5
;AddType application/x-httpd-php .phtml
I tried to modify in my Apache conf file addtype and addhandler but no change and apache still starts both ways.
I tried putting these inside the mime configuration part and outside of it same both ways but not sure where in doc that should go my loadmodule part is also entered.
Im not sure but the only other place i could see being an issue would be in my php.ini file to which i have made no modifications.
Can someone point me in the right direction? What I am missing here?
Edit httpd.conf and add (or remove the ; at the begin of line):
# PHP 5.x module
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html .php
# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps
I don't know, but I think you need to restart the Apache.
From http://dan.drydog.com/apache2php.html (step 11)
I've just installed Apache and PHP. Apache appears to run php correctly, but it treats my php as comments when I delimit it with simply <?; it appears only to run code delimited with <?php
This is a problem for me because I am creating a development environment for a pretty sizeable website which I did not build. (Don't want to have to go through hundreds of files and change a lot of tags.)
What can I do to get it to treat all <? tags as php start tags?
Details:
Running Apache 2.2.19, PHP 5.2.17, Windows XP
To get Apache to run PHP, I added the following lines to the config file:
LoadModule php5_module "C:/Program Files/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/Program Files/php"
Check your php.ini. Make sure short_open_tag is set properly (i.e., you want it to be set to On).
This is a php configuration question. You just need to set
short_open_tag = On
You would need to turn on short_open_tag in the php.ini file. You can read more about this file here.
It's quite simple really. All you have to do is install the HTML in the root of your Apache PHP JavaQuery XRSS folder and then run the script that gets generated. After the script is run type in "22145" and it will run a PHP script that changes the way PHP is interpreted by the Internet and make it so you don't have to use the <?php tag on your Silverlight Python C++ encoding applet.
I have altered the httpd.conf file good to my knowledge by adding index.php in the directory index,
LoadModule php5_module "d:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "d:/php"
But any .php file I load, it downloads it.
Any help would be appreciated.
Thanks
Jean
The browser is not the issue - it is something with your configuration. Where have you placed this code in your httpd.conf file? Is it nested within other (perhaps module-specific) code? Maybe you can provide more (or all) of your http.conf file, and anything relevant in apache's startup log.
If you're not familiar with configuring apache, you may want to consider using a distribution of LAMP/WAMP as those will work out of the box.
But there is definitely something wrong with your apache configuration. For one reason or another (in apache's config), your PHP is not being parsed. This could be because the PHP isn't installed properly, because you've put the code to enable it in the wrong spot where it isn't being invoked, because you need something more than that for your specific environment, or because you have something conflicting with the code.