WAMP PHP/Apache selectively refusing to parse php pages - php

I have many years experience of working with Apache/PHP/MySQL directly and have only just started using WAMP.
I installed WAMP last week and had my first 4 PHP/MySQL websites up and running immediately. How much easier is this I began to think! That is until I added a fifth site and cannot get php to parse any php file below the websites root directory.
I have a test.php file containing just the word 'hello', ho HTML tags and no PHP directives.
If I place this into /wamp/www/ob/test.php it works, if I place it into /wamp/www/ob/html/test.php the browser comes up with 'You have chosen to open test.php, what should Firefox do with this file? Basically php failed to parse it.
My other sites are working fine with identical setup and this site plus three others were downloaded using Filezilla.
Can anybody help please before I uninstall WAMP and go back to installing Apache/MySQL/PHP manually.

Either the php handler is not turned on for that directory, or the content-type of the returned data is set wrong.
My WampDeveloper Pro setup has this...
<Directory "C:/WampDeveloper/Websites/*/webroot">
AddType text/html .php .php4 .php5 .phps
AddHandler application/x-httpd-php .php .php4 .php5
AddHandler application/x-httpd-php-source .phps
</Directory>
This turns on PHP for all website folders.
Has a DefaultType text/html in httpd.conf for fallback.
Also check any .htaccess files, they might be setting content-type to something other than 'text/html'.

The pages on the Internet that explain how to make Apache parse the PHP that you add to a file with the extension HTML suggest this:
AddType application/x-httpd-php .html .php .htm
AddHandler application/x-httpd-php .html .php .htm
If your Apache server is configured for php5 but not php, then the result, I believe, is the refusal described. I changed what I added to .htaccess to this (notice the digit 5):
AddType application/x-httpd-php5 .html .php .htm
AddHandler application/x-httpd-php5 .html .php .htm
That fixed the problem for me.

Related

How to Parse HTML as PHP?

I'm using Apache2 on Heroku and I'm trying to parse HTML as PHP so I can include files inside a HTML file and use HTML as normal, so I don't have to copy paste the navigator and stuff, such as footer in each other html file. This makes work much easier.
I've tried to look things up, made .htaccess and httpd.conf work, but whatever I have done so far it doesn't really work. What it does at the moment is it gives me .html to download.
These are the current settings I have:
AddHandler x-httpd-php .html .htm
AddType application/x-httpd-php .html .htm
I AddType started to cause the .html to download.
Inside httpd.conf I have this:
AddHandler application/x-httpd-php .htm .html
<Files />
AddType application/x-httpd-php .html
</Files>
Update:
I've asked Heroku support, however, they don't support these things... uhm..
So, I've figured out that the buildpacks that Heroku has, this one: https://github.com/heroku/heroku-buildpack-php
has a folder inside support that includes this:
https://github.com/heroku/heroku-buildpack-php/tree/master/support/build/_conf/apache2
a httpd.conf that I can't access, because apperantly it builds from that. However I can remove that buildpack and replace it with mine. The problem is the buildpacks work like that
they have a bin folder with a compiler inside, and when I fork it, it still compiles it from their repository.
I need someone to help me out and fork it and basically modify it so that it doesn't load a httpd.conf at all, so that I can include mine and do stuff with it.
Update:
I am just using PHP now, since I can't do anything to change it, it's on heroku's side or the buildpack from heroku.
Your AddType seems to be ok:
AddType application/x-httpd-php .html .htm
Sometimes you need to indicate the PHP version:
AddType application/x-httpd-php5 .html .htm
or for PHP 7:
AddType application/x-httpd-php7 .html .htm
another solution is to remove html handler:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
one more solution:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
Do not forget to restart the server to see the results!

html files parsed as php but shown as html

I have a website which has a bunch of simple HTML pages. There is a menu in the page and of course the html is repeated across all the pages. I want to be able to put the menu in a php file and then have it as an include in all html files.
I thought I could do this with .htaccess by getting all html files parsed as php. However I'm having real problems getting it to parse. I've been tons of google links and have tried a bunch of stuff but none of it seems to work any ideas:
stuff I've tried:
# Use PHP5.4 as default
AddHandler x-httpd-php .html .htm
AddHandler php-script .php .html .htm
AddHandler php5-script .php .html .htm
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
AddHandler application/x-httpd-php54 .html .htm
AddHandler application/x-httpd-php54 .php .html
Not all at once but line by line. None of it worked! The server uses fast cgi so I think actually only the addhandler stuff is needed and it uses 5.4.4
thanks
My answer in the comment (which I shouldn't have done) had the linebreak removed.
Some hosts (including the one I use for their shared servers) have Linux configured differently. You might want to speak with them or check their support documentation, they may have answered it for you.
For my host, this is the correct pair of commands to have PHP execute within files that have a .html extension.
AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html

$con->query error MySQL with PHP

What I'm trying to do is get my html/php code to display data from my MySQL in a table.
It connects just find to the database, but I think I'm getting an error at: $resultt=$con->query("SELECT DisplayName, Kills, Deaths, Wins, Lost FROM TTPlayer"); for it always shows that code as text on the webpage when I execute it. Also in the tables it shows each of the row methods and their variable Thanks in advance for any help!
Code:
http://pastebin.com/j1EDux5y
Executed webpage:
http://pasteboard.co/2pzqESnw.png
"It is a .html file, I will check on php5_module – ZachtheBoB 2 mins ago"
.html file extensions will not parse PHP directives.
A .php extension is required to do this, plus making sure a webserver and PHP are installed and properly configured.
If on a local machine, you will need to access it like http://localhost/file.php and not file:///file.php
You can however, instruct Apache to treat .html files as PHP through .htaccess if that is your preference.
AddType application/x-httpd-php .html
If you only plan on including the PHP on one page, it is better to setup this way:
<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>
If you are running PHP as CGI
AddHandler application/x-httpd-php .html
If on GoDaddy
Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html

run htm file as php using htaccess

I have few files whose extension is htm that i want to run as php using htaccess code
this is the htaccess code that i am using
AddHandler application/x-httpd-php5 .htm .php .html
this code work fine but now i change my hosting server in that this code not working.
i tried all these code but no one work
AddHandler application/x-httpd-php .htm .php .html
AddType application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
my new server says
cPanel Linux Hosting packages only support the SymLinksIfOwnerMatch option in the .htaccess file.
Please point me in right direction how can i run htm file as php on my server
I'm afraid it's a no-go then... If your hosting blocks the appropriate directives in your .htaccess, your only way to go would be to either blackmail or hack the provider, or change the extension from .htm to .php. As this is really a server-administration thing, and if the server administrator doesn't allow you, there is no way you can go around it...
A hacky solution would be to use rewrites to route .htm to .php files. But still then you'd need to rename your files from .htm to .php. This could be a solution if you're app routing isn't setup dynamically and your main concern is that the url's should not be changed. Although changed url's can be caught with 301 redirects.

AddType in htaccess causes page to download

I have read about 10 questions like this, but there seems to be no answer to this simple question.
What could cause .htm files to be downloading instead of executed as php?
I am using the following code:
AddType application/x-httpd-php htm
I have tried many combinations but no success.
What else can I try?
All I need is .htm and .html files to execute php.
Use AddHandler also, change htm to .htm and add .html
AddHandler application/x-httpd-php .htm .html
AddType application/x-httpd-php .htm .html
http://www.suffix.be/blog/addhandler-addtype-directives
I had the same issue but then i figured the version of php i'm using is php5. I changed the handler to the following and it worked!
AddHandler x-httpd-php5-3 .php
AddHandler application/x-httpd-php5 .php
I had the same problem and couldn't find the answer here. Did find it on this cpanel forum though:
https://forums.cpanel.net/threads/php-script-is-not-working-in-html-file.595195/
Their advice was to use this:
AddHandler application/x-httpd-ea-php56 .htm .html .shtml
AddType application/x-httpd-php5 .php
I was using PHP together with JSON though. After this PHP did work, but JSON didn't. Solved it by removing the AddType and sticking with the AddHandler
AddHandler application/x-httpd-ea-php56 .htm .html .shtml
I'm sharing my own experience with this super frustrating issue. My host got taken over by another hosting provider and they changed technologies. One of the changes allowed me to edit my own PHP version at will, but absolutely none of them (from the lowest 5.4 to the highest 7.2) worked properly. I was using a global .htaccess across all my domains (placed in the root) and had my AddType-s and AddHangler-s at the beginning of the file. Little that I knew - when I had been changing PHP versions, the little bugger wrote the correct string defining the proper name of my PHP version at the very end of that .htaccess file. When I defined the types at the beginning of the file, I was using the wrong handle and that skipped the bottom declaration altogether, Apache didn't recognize the technology and decided to spew out a direct download.
So watch for custom PHP handle definitions on your hosting providers.
What worked for me in the end was:
<IfModule mime_module>
AddType application/x-httpd-ea-php72___lsphp .php .php7 .phtml .htm .html
</IfModule>
Note the "___lsphp" appended at the end of the standard "x-httpd-ea-php72" handle...
God, that ate me up so much...
In Apache and nginx ONLY work .htaccess file:
<FilesMatch "\.html$">
SetHandler php-script
</FilesMatch>
I've also removed AddHandler and AddType from Apache conf (I used plesk).
Add this line to your .htaccess file (Solved)
AddHandler application/x-httpd-php5 .php .php4 .php5 .html .htm .phtml .shtml
Try:
application/x-httpd-ea-php5 or
application/x-httpd-ea-php56 for PHP 5.6
I had to change to this after upgrading to EasyApache 4
Doug
Smartlab Software
Try
AddHandler fcgid-script .htm .html
Or
AddHandler x-mapp-php5 .html .htm
add this in .htaccess file
AddType application/x-httpd-php .php .php5 .phtml

Categories