This question already has answers here:
How do I add PHP code/file to HTML(.html) files?
(12 answers)
Closed 8 years ago.
I am trying to run a simple php code inside my html file. The file name is test.html.
The following code is inside the file:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
I have also changed my .htaccess file to include a code which my service provider recommended which is: AddHandler x-httpd-php .html.
But I still cannot display a simple message. Everything works fine if I change the file name to .php. But I want to keep my file name .html.
I can provide more info if required.
Try
AddType application/x-httpd-php .html .htm
or
AddType application/x-httpd-php5 .html .htm
or
RemoveHandler .html .htm
AddType application/x-httpd-php .html .htm
or
RemoveHandler .html .htm
AddType application/x-httpd-php5 .html .htm
Instead of
AddHandler application/x-httpd-php .html .htm
Related
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!
This question already has answers here:
How do I add PHP code/file to HTML(.html) files?
(12 answers)
Closed 6 years ago.
I am not able to run a php script on an html file, as the picture showed in the link, it always show error and nothing function in html file.
But I already have .htaccess configured in website root, and my dreamweaver have a php local server, and I set up my php by using xamppp. I have no idea why it won't work.
My .htaccess file:
AddHandler application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .php5
AddType application/x-httpd-php5 .phps
AddType application/x-httpd-php5 .html .htm
Picture here
Exactly what #arif_suhail_123 said. Rename the index.html file to index.php and the PHP code should be executed.
Apache does not know the file contains PHP code if the .php file extension is not present.
I want to add php code to my .html file. I have searched a lot and din't find why it is not working
Steps i have followed for this:
1) Created a .htaccess file inside my htdocs
2) And added the following things
AddType text/html .shtml .shtm .htm .html
AddHandler application/x-httpd-php5.6 .html
3) Restarted my Apache.
Executed my page. My page contains
<?php
echo "hello";
?>
I din't see any errors and hello too. And i changed the htaccess content to
AddType application/x-httpd-php .htm .html
as mentioned here
It is also not working. I don't know whether htaccess file must contain some other elements or not. Please let me know.
Thanks
You need to set AllowOverride to All in httpd.conf, or in your virtual hosts file (httpd-vhosts.conf) if you are using them.
Otherwise, directives in your .htaccess file will not be allowed.
More information can be found here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Update
If it is set to All, then you should be able to do either of the following.
Unset the handler and reset it:
RemoveHandler .html .htm
AddType application/x-httpd-php .html .htm
Or, use FilesMatch:
<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Try this :
AddHandler application/x-httpd-php .html
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
When I try to load a php inside an html page, somepage.html ... It brings up a download box.
AddHandler application/x-httpd-php .html
AddType application/x-httpd-php html
Those were generated in my cpanel but still it shows a download box instead of the code.
What do I do?
Also additional information:
Apache version 2.2.17
PHP version 5.3.4
Not sure, but you can try:
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html
Took it from this blog post.
EDIT: Just saw that you're using PHP inside .html files. Can't you just change the extension?