Related
My index.html file
<html>
<head>
<title> PHP inside HTML </title>
</head>
<body>
<h1>
<?php
echo "PHP Output";
?>
</h1>
<h1>
<p>
HTML Output
</p>
</h1>
</body>
</html>
My Expected output of the above code:
PHP Output
HTML Output
I have tried with below combinations but none of these helps me get the output.
AddHandler application/x-httpd-php56 .shtml .html .htm
AddHandler server-parsed .shtml .shtm .htm .html
AddHandler x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
2nd Set of Codes Not Working
AddHandler application/x-httpd-php .htm
AddHandler application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
3rd Set of Codes Not Working.
AddHandler x-httpd-php5 .html
AddHandler x-httpd-php5 .htm
AddHandler application/x-httpd-php .htm
AddHandler application/x-httpd-php .html
While adding the Mime types using the .htaccess.
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html
It leads to download the files instead of working.
Returns Internal Server Error
Options +ExecCGIenter
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Please help me to resolve this issue.
I have referred the page in stack-overflow but all of the codes are not working for me.
StackOverFlow
If your account's under Cloudlinux based server then use the below code, Hope it will work fine.
Code
AddHandler application/x-httpd-ea-php56 .htm .html .shtml
AddType application/x-httpd-php5 .php
Consider the PHP versions and modify the code accordingly.
I have the included code in my .htaccess file but the php code I am attempting to include is not working.
Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript
Try:
AddType application/x-httpd-php .html .htm
UPDATE 1
It may be PHP version specific. If you're using PHP5 try:
AddType application/x-httpd-php5 .html .htm
UPDATE 2
Try:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Or here's yet another alternative way to do this:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
and restart apache
sudo service apache2 restart
For godaddy shared hosting (php-cgi):
From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
That's the only one that worked for me.
If you are using Plesk Control Panel:
PHP is running as an Apache module:
<IfModule mod_php5.c>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</IfModule>
PHP is running as a FastCGI application:
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</IfModule>
PHP is running as a CGI application:
<Files ~ (\.html)>
SetHandler None
AddHandler php-script .html
Options +ExecCGI
allow from all
</Files>
Then
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
http://kb.odin.com/en/115773
VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php5 .html .htm
Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!
If your server is using PHP5 then use this:
AddHandler application/x-httpd-php5 .html .htm
If it's not PHP5 then use
AddHandler application/x-httpd-php .html .htm
It worked for me on CPanel hosting.
If you are using some other linux hosting try this:
<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>
Options +FollowSymlinks
For Godaddy server it worked for me
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
BenG, did any solution ever work for you?
this may help -- i found this topic confusing, because either statement worked for me in my local dev environment
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
after reading the apache documentation on both directives, it seems that you want to use AddType when adding a mime type not yet handled by apache, and AddHandler when you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.
so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :
AddHandler application/x-httpd-php .html .htm
the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.
I was stumped for 2 hours until I looked into /etc/php/7.2/fpm/pool.d/www.conf and then uncommented the security setting to force php to only parse php and added .html so that the line now is security.limit_extensions = .php .php3 .php4 .php5 .php7 .html and then sudo service php7.2-fpm restart and doing the
<head>
</head>
<body>
This should show date here:
<?php echo date('l, F jS, Y'); ?>
</body>
and saved as test.html worked fine and displayed!
From http://support.lunarpages.com/knowledge_bases/article/321
How can I configure Apache to treat
.html files as PHP under suPHP? You
need to remove any previous entries
for handling .html files as PHP and
insert the following in your .htaccess
file: AddHandler x-httpd-php .html
.htm Or you can add this manually
using Cpanel -> Apache Handlers ->
New: Extension: .html .htm Handler:
x-httpd-php The newest cPanel servers
actually require the following
instead: AddHandler
application/x-httpd-php .html .htm or
AddType application/x-httpd-php .html
.htm Please try this if the first type
doesn't work for you for files.
You can just try to put only this AddType php .html .htm to your htaccess, If this AddType application/x-httpd-php .html .htm doesn't work.
Don't know if it helps but... My example after hour of searching:
AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"
in httpd.conf
Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext
Been stumped by this a lot before and what probably is happening, if none of the others worked, is your reading it as a file and not going through apache. Check your address bar and make sure it starts with localhost, your ip, 127.0.0.1, or your domain name if you've already set it up to direct to your server.
If you are trying to run very old PHP code, make sure you have
short_open_tag = On
in your php.ini
or, even better (because it's not recommended to use short open tags for new code anymore) to enable for specific virtual host only via:
php_value short_open_tag On
in httpd.conf / .htaccess file.
You might want to try adding this line to your .htaccess file:
AddHandler x-mapp-php6 .html .htm
simplify to 3 steps:
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .html
service httpd restart
I am using GoDaddy dedicated server with Plesk. Here is what I have to use to get it to work:
AddHandler fcgid-script .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
For the actual path of the cgi_wrapper, refer to the file:
/var/www/vhosts/yourdomain.com/conf/last_httpd.include
or /etc/httpd/conf.d/php_cgi.conf
Adding this to .htaccess solved my problem, using PHP 5.5:
AddType application/x-httpd-php .html
PHP is running with SuPHP:
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
this worked for me!
if you want url for www.examle.com/page.php?id=123&lang=it in seo like this www.examle.com/it/1/2/3/pagina.html
add in .htaccess
<Files it>
SetHandler php-script
</Files>
<Files ru>
SetHandler php-script
</Files>
and when create files "it" "ru" in web http root directrory like this:
<?php
// www.examle.com/it
$lang="it";
include("urlrewrite.php");
?>
<?php
// www.examle.com/ru
$lang="ru";
include("urlrewrite.php");
?>
For PHP version 5.6.40 run PHP as "FRM application served by Apache" ( Plesk )
add this in .httaccess
<FilesMatch "\.html$">
SetHandler php-script
</FilesMatch>
it's work for me
Open "MultiPHP INI Editor" from the cpanel
then enable "allow_url_include"
then add the below lines to your .htaccess file:
<IfModule mod_mime.c>
AddType application/x-httpd-ea-php73 .html .php .htm
</IfModule>
Options +FollowSymlinks
Important: must replace the php ver with yours
I have a html site and I want html pages to be parsed as php; I'm using a htaccess file for that.
On the online server, it works properly. The command is:
AddHandler application/x-httpd-php5 .html .htm
However, on localhost server it doesn't work at all. When I access the page, it prompts to download the file instead of displaying the page.
I'm using PHP 5.6.3 and PHP as module, I guess.
I tried all sorts of similar commands in htaccess, like:
AddType application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
AddHandler application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
AddHandler application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
AddHandler x-mapp-php .html .htm
AddHandler x-mapp-php5 .html .htm
but no luck.
I also tried RemoveHandler .html .htm but without success.
I checked the httpd.conf file and among others, there are the following:
LoadModule php5_module "C:/Program Files/PHP/php5apache2_4.dll"
AllowOverride All
<Directory "D:/mysites/">
AllowOverride All
Require all granted
</Directory>
Where should I look for anything wrong then..?
Any hint appreciated.
You should try something like this :
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
But it's better to add it in your vhost or if it's possible, blogbally in your apache2.conf.
When I try to embed PHP into an HTML file, it doesn't work. I edited my .htaccess so that it treats HTML files as PHP, but when I try to visit the .html file my browser downloads it instead of parsing and displaying it.
EDIT: My .htaccess contents:
AddType application/x-httpd-php .html
Try:
AddType application/x-httpd-php .php .html
RemoveHandler .php .html
<FilesMatch "\.(php|html)$">
SetHandler x-httpd-php
</FilesMatch>
EDIT:
Depending on your host, you may need to modify it a bit such as:
AddType application/x-httpd-php5 .php .html
RemoveHandler .php .html
<FilesMatch "\.(php|html)$">
SetHandler x-httpd-php5
</FilesMatch>
OR
AddType php5-script .php .html
RemoveHandler .php .html
<FilesMatch "\.(php|html)$">
SetHandler php5-script
</FilesMatch>
I have the included code in my .htaccess file but the php code I am attempting to include is not working.
Options +Includes
AddType text/html .htm .html
AddHandler server-parsed .htm .html
AddType application/octet-stream .vcf
AddOutputFilterByType DEFLATE text/html text/htm text/plain text/css text/php text/javascript application/x-javascript
Try:
AddType application/x-httpd-php .html .htm
UPDATE 1
It may be PHP version specific. If you're using PHP5 try:
AddType application/x-httpd-php5 .html .htm
UPDATE 2
Try:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
Or here's yet another alternative way to do this:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
On Apache 2.2.22 (Ubuntu) with Php 5 add these lines to /etc/apache2/mods-enabled/php5.conf
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
and restart apache
sudo service apache2 restart
For godaddy shared hosting (php-cgi):
From http://sagarnangare.com/parse-html-as-php-using-htaccess-file-on-godaddy/
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
That's the only one that worked for me.
If you are using Plesk Control Panel:
PHP is running as an Apache module:
<IfModule mod_php5.c>
AddHandler php5-script .php .html .htm
AddType text/html .php .html .htm
</IfModule>
PHP is running as a FastCGI application:
<IfModule mod_fcgid.c>
<Files ~ (\.html)>
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI
allow from all
</Files>
</IfModule>
PHP is running as a CGI application:
<Files ~ (\.html)>
SetHandler None
AddHandler php-script .html
Options +ExecCGI
allow from all
</Files>
Then
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
http://kb.odin.com/en/115773
VERY IMPORTANT that you must replace the "php5" to your OWN exact PHP version in the:
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php5 .html .htm
Because I have tried everithing in every way from all over the web, but nothing worked until I found a "MultiPHP Manager" menupoint under my CPanel, and under this I found out that my exact PHP version/name/id (or whatever it is called) was "ea-php56", so my working code is:
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
I have browsed all day the forums, comments, but I haven't found this very important information anywhere, so maybe You also have to look up your exact PHP version if it is not working!
If your server is using PHP5 then use this:
AddHandler application/x-httpd-php5 .html .htm
If it's not PHP5 then use
AddHandler application/x-httpd-php .html .htm
It worked for me on CPanel hosting.
If you are using some other linux hosting try this:
<IfModule mod_mime.c>
AddType application/x-httpd-php .html .php .htm
</IfModule>
Options +FollowSymlinks
For Godaddy server it worked for me
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
BenG, did any solution ever work for you?
this may help -- i found this topic confusing, because either statement worked for me in my local dev environment
AddHandler application/x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
after reading the apache documentation on both directives, it seems that you want to use AddType when adding a mime type not yet handled by apache, and AddHandler when you want apache to handle a file differently than its default handling of that file type. i may be wrong, but that does seem to be what the manual is saying.
so if you want apache to handle .html and .htm as if they were .php files then you would use the directive :
AddHandler application/x-httpd-php .html .htm
the .htaccess file you mention above is doing a few things, so maybe you could first verify that it does indeed tell apache to handle .htm and .html files as if they are .php files; then move on to the other directives you want to use.
I was stumped for 2 hours until I looked into /etc/php/7.2/fpm/pool.d/www.conf and then uncommented the security setting to force php to only parse php and added .html so that the line now is security.limit_extensions = .php .php3 .php4 .php5 .php7 .html and then sudo service php7.2-fpm restart and doing the
<head>
</head>
<body>
This should show date here:
<?php echo date('l, F jS, Y'); ?>
</body>
and saved as test.html worked fine and displayed!
From http://support.lunarpages.com/knowledge_bases/article/321
How can I configure Apache to treat
.html files as PHP under suPHP? You
need to remove any previous entries
for handling .html files as PHP and
insert the following in your .htaccess
file: AddHandler x-httpd-php .html
.htm Or you can add this manually
using Cpanel -> Apache Handlers ->
New: Extension: .html .htm Handler:
x-httpd-php The newest cPanel servers
actually require the following
instead: AddHandler
application/x-httpd-php .html .htm or
AddType application/x-httpd-php .html
.htm Please try this if the first type
doesn't work for you for files.
You can just try to put only this AddType php .html .htm to your htaccess, If this AddType application/x-httpd-php .html .htm doesn't work.
Don't know if it helps but... My example after hour of searching:
AddType application/x-httpd-php .php
LoadModule php5_module "c:/server/php5/php5apache2_2.dll"
ScriptAlias /_php/ "c:/server/php5/"
in httpd.conf
Without LoadModule and ScriptAlias it didn't process php at all and showed plaintext
Been stumped by this a lot before and what probably is happening, if none of the others worked, is your reading it as a file and not going through apache. Check your address bar and make sure it starts with localhost, your ip, 127.0.0.1, or your domain name if you've already set it up to direct to your server.
If you are trying to run very old PHP code, make sure you have
short_open_tag = On
in your php.ini
or, even better (because it's not recommended to use short open tags for new code anymore) to enable for specific virtual host only via:
php_value short_open_tag On
in httpd.conf / .htaccess file.
You might want to try adding this line to your .htaccess file:
AddHandler x-mapp-php6 .html .htm
simplify to 3 steps:
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .html
service httpd restart
I am using GoDaddy dedicated server with Plesk. Here is what I have to use to get it to work:
AddHandler fcgid-script .htm
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
For the actual path of the cgi_wrapper, refer to the file:
/var/www/vhosts/yourdomain.com/conf/last_httpd.include
or /etc/httpd/conf.d/php_cgi.conf
Adding this to .htaccess solved my problem, using PHP 5.5:
AddType application/x-httpd-php .html
PHP is running with SuPHP:
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
AddHandler application/x-httpd-ea-php56 .html .htm
AddType application/x-httpd-ea-php56 .html .htm
this worked for me!
if you want url for www.examle.com/page.php?id=123&lang=it in seo like this www.examle.com/it/1/2/3/pagina.html
add in .htaccess
<Files it>
SetHandler php-script
</Files>
<Files ru>
SetHandler php-script
</Files>
and when create files "it" "ru" in web http root directrory like this:
<?php
// www.examle.com/it
$lang="it";
include("urlrewrite.php");
?>
<?php
// www.examle.com/ru
$lang="ru";
include("urlrewrite.php");
?>
For PHP version 5.6.40 run PHP as "FRM application served by Apache" ( Plesk )
add this in .httaccess
<FilesMatch "\.html$">
SetHandler php-script
</FilesMatch>
it's work for me
Open "MultiPHP INI Editor" from the cpanel
then enable "allow_url_include"
then add the below lines to your .htaccess file:
<IfModule mod_mime.c>
AddType application/x-httpd-ea-php73 .html .php .htm
</IfModule>
Options +FollowSymlinks
Important: must replace the php ver with yours