Problems Parsing PHP in an HTML files on cPanel GoDaddy - php

I'm moving a client's website from and old Linux server to a new server with cPanel, both servers are with GoDaddy and the client's html files include PHP code. (I know it's not efficient but that's how he wants it.)
On the Linux server the following lines on the .htaccess file worked:
Options +ExecCGI
AddHandler x-httpd-php5-3 .html
But on the new server, those lines are not working, I've looked everywhere and tried many different lines including the following:
AddHandler php8-script .php .html .htm
AddHandler application/x-httpd-php8 .htm .html
Options +ExecCGI
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php8 .php .htm .html
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php8 .html
SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .htm
Options +ExecCGI
allow from all
I also tried getting help form their customer service but they refuse to help me because according to them it is a "content issue."
If anyone can guide me how to solve the issue I'd really appreciate it.

Related

Why is PHP no longer parsing correctly in my .html pages?

My site is with HostGator shared hosting (yes, I know, that’s my first mistake). I'm looking to redesign it, but before I do, I need to fix a PHP parsing problem.
All of the site's pages are HTML (.html). However, I have always used PHP to insert dates, times, random text, etc. Suddenly, PHP stopped parsing in all .html pages of the site, even though I did not touch my htaccess file. Simple PHP code no longer works. For example:
<?php print date('Y'); ?>
My default PHP is set to PHP 5.6. HostGator claims that it's "outside the scope of [their] service" to help me figure out what happened (even though it's obvious that they changed/updated something on their end).
The following worked perfectly in .htaccess for years, but now it results in a "500 error":
Options +ExecCGI
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
I have also individually tried each one of the following in htaccess, to no avail:
AddHandler application/x-httpd-php .html .htm
AddHandler application/x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddHandler application/x-httpd-php5 .html .htm
AddHandler application/x-httpd-php5 .php
AddHandler application/x-httpd-php5 .php .html
AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php54 .php .html
AddHandler application/x-httpd-php54s .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php56 .html
AddHandler application/x-httpd-php56 .php5 .php4 .php .php3 .php2 .phtml
AddHandler fcgid54-script .php
AddHandler php-script .php .html .htm
AddHandler php5-script .php .html .htm
AddHandler x-httpd-php .html .htm
AddType application/x-httpd-php .php .htm .html`
Some of those options result in a "500 error," while the others have no effect at all.
I'd greatly appreciate some help in resolving this problem. (Changing the extension to ".php" is not an option.) Thank you!
UPDATE: There is no updating "log" or "error" file anywhere in my FTP interface. Also, the only entries in Hostgator's "Last 300 Error Log messages" page in cPanel look like this:
[Thu Nov 08 03:32:04 2018] [error] [client xx.xxx.xxx.xxx] SoftException in Application.cpp:313: File "/home4/.../public_html/index.html" is writeable by group, referer: https://www.********.com/
The error message
File "/home4/.../public_html/index.html" is writeable by group
suggests that the problem is the file permissions of your html files. So change them from 664 to 644 to make them not-group-writeable.

No output to screen [duplicate]

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

parse html as php with htaccess prompts to downloading

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.

problem with htaccess file and handlers?

i asked a question if i can execute html files as php files and i got those answers
AddType application/x-httpd-php5 .php .html
and another answer
AddHandler application/x-httpd-php .html .htm
and here is another one
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
and i got 1 problem
when i used to write any condition to add type it send me to download the page instead of run it
for example if i have a file index.html which have php code
after i create the .htaccess and write
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
then try to navigate the link it send me to download index.html instead of run it
AddType is used to assign a MIME type to a file suffix.
F.e. to override the MIME type of an PDF *sic
AddType text/plain .pdf
This will force the browser to load and show a PDF as plain text, because server is sending the text/plain MIMe type. But many applications handle files by content and not by suffix.
RemoveHandler
This is unnecessary, you don't want to remove anything from the standard configuration.
AddHandler handler-name .htm
This should do it, but it depends on your server configuration. You need the right "handler-name".
Standard handler-name for most Apache servers with PHP installed is
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php .htm
but it could differ and it depends on your configuration. If you are using a shared or managed hosting without access to the Apache configuration file, you should ask your hoster.
I was using shared hosting with handler-names like
AddHandler php4-cgi .php .html
or
AddHandler php52-cgi .php .html
and another was using totally different way like
AddType x-mapp-php5 .php .php5 .htm .html
Otherwise have a look on your Apache configuration file. This page may be helpful to find the right section and to adapt.
Did you try:
AddHandler application/x-httpd-php5 .htm .html
?
Exactly the same problem, the basic code forces page download, but this:
AddHandler application/x-httpd-php5 .php .htm .html
...rectified the issue & worked perfectly.
if you are using fcgi none of the above will work ;
you need
<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>

Server not parsing .html as PHP

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

Categories