Parsing .html as PHP in .htaccess for Apache 2.4 - php

I am hosting in a whm/cpanel server and two of my sites were having .htaccess files that would parse .html files to .php.
However, the server is upgraded to Apache 2.4 and PHP to 5.5.38.
Since then the .htaccess files are not parsing the .html as PHP. I contacted the server provider, they said that the syntax for 2.4 is different which they don't know.
I'm a novice. If someone please help me with the correct .htaccess codes and if there is any module to be installed or scripts to be added in the root level, please provide me the step by step guidance - as I will just forward those instructions to the server provider.
Thanks in advance...

I'm not aware of any changes to the AddType or AddHandler directives between 2.2 and 2.4 - it could be the case that your htaccess file simply isn't running (disabled via AllowOverride, etc), or that it contains some other directive that isn't compatible with the new versions.
The required directive should be something like:
AddType application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php .html .htm
depending on the configuration.

Assuming AllowOveride is such that SetHandler is allowed.. per
http://httpd.apache.org/docs/current/mod/core.html#sethandler .htaccess should look like...
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
Check /etc/apache2/apache2.conf and /etc/apache2/conf.d where AllowOverride is typically set. Check out http://httpd.apache.org/docs/current/mod/core.html#allowoverride for the syntax and list of allowable methods.

The new syntax is:
AddHandler "proxy:unix:/usr/local/php56/sockets/[username].sock|fcgi://localhost" .html .htm .inc

Related

AddHandler .htaccess on GoDaddy stopped working today

I have the following code in my GoDaddy .htaccess file:
AddHandler fcgid-script .do
FCGIWrapper /usr/local/cpanel/cgi-sys/php .do
AddType application/x-httpd-php5 .do
This means that whenever we go to a ".do" file in the web browser, it runs as PHP. All of a sudden, after three years of working with no problem, it has stopped working correctly! Now, if I go to a .do file, the browser just downloads the file.
I think that GoDaddy have done a server upgrade, but I can't work out how to solve the problem.
Anyone have any ideas? Thanks in advance....
GoDaddy upgraded EasyApache (from version 3 to version 4) last night.
You should drop the FcgidWrapper and the AddType directives from your .htaccess, and modify AddHandler to:
AddHandler application/x-httpd-lsphp .do
Refresh browser cache after change.
I faced a similar issue. We were able to fix it by replacing the module name to the Apache V 2.4 standard.
In your case, you would need to do:
AddHandler fcgid-script .do
FcgidWrapper /usr/local/cpanel/cgi-sys/php .do
AddType application/x-httpd-php5 .do
We referred the official Apache documentation here. There might be more choices for your context.

Apache runs php files with or without .php extension

My apache runs php files with or without .php extension, How can I disable this and force apache to run php files only with .php extension. I don't want to use .htaccess, this might be an apache config. does anyone know how to disable this option?
Thanks for the answer but using Addtype as you mentioned did not ever work for me, all by itself, even in PHP 5..
Here's what I've tried that DOESN'T work with this version of PHP:
Options +ExecCGI
AddType application/x-httpd-php .php .nusuffix
AddHandler x-httpd-php5 .php .nusuffix
This worked for PHP 5. Now, does not.
This is for a hosted account, so I must do this via .haccess.
You can check your httpd.conf what extensions are configured, it need need to be following. if there is change in your file you can change it to following and restart the apache
AddType application/x-httpd-php .php
more details : https://wiki.archlinux.org/index.php/Apache_HTTP_Server
please add if anything is missing

php in html page doesn't work

I'm using PhpStorm 2016 with php language level 5.6 and the interpeter is PHP 5(5.6.24) and xampp version 3.2.2 .
I'm trying to add some php code in html page,
I created a file .htaccess in the same folder where my html file located, and put AddType application/x-httpd-php5 .html .htm inside it, added <?php echo "example" ?> but it doesn't show up.
I even tried <FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>, AddHandler application/x-httpd-php5 .html .htm and AddType application/x-httpd-php .html .htm but nothing work, don't know what eles to do.
Hope you can help me with any idea.
Thank you.
You may need to edit the Apache config file, and check if AllowOverride is set to none. If AllowOverride is set to None, .htaccess files are completely ignored.
See httpd.apache.org/docs/2.4/mod/core.html#allowoverride
To allow only the ForceType directive it would be
AllowOverride FileInfo
or if you want all entries in your .htaccess to be honored, then
AllowOverride All
In order to get xampp to interpret the file as PHP, you will need to set the Apache Server web-root to the base of your project (where the html files are) and access the webserver via the server (HTTP in a web-browser).
It sounds like you're trying to access the file directly with the browser (skipping the PHP processor).

htaccess rule to parse php in html files not working

can't for the life of me work out why this isn't working - on a dreamhost server, I've created an htaccess file and added AddHandler php5-cgi .html .htm to allow php in html files, as per the dreamhost docs. On an identical dreamhost package, I've done the same thing for another site and it worked perfectly, but in this case it just won't parse the php! Is there anything I could have missed here which could be causing the problem? The htaccess is in the web root and isn't being overridden by anything else.
Try this
AddType application/x-httpd-php .html .htm
The above setting will work if the apache is picking php as a module.
AddHandler application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php5 .html .htm
above will work if apache is executing php as CGI?
there is no harm i would say to put both of the above conditions together but try one over other and see if it work for you.
read more here in this article I wrote.
Is your server using suPHP rather than mod_php or plain php-cgi?
Try using
AddHandler x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
instead.
Postscript
Shared Hosting services use UID based separation on individual accounts from each others. Most use suPHP, but some use suEXEC. They will use one of these. Both act as a su wrapper around php-cgi so you can't tell from the phpinfo()as its PHP scripting engine as this will report Server API CGI/FastCGI in both cases. For CGI initiated scripts, phpinfo doesn't report on the Apache config. You need either to look at your hosting provider's FAQ or possibly try:
<?php
header( "Content-Type: text/plain");
echo system('grep -iR LoadModule /etc/httpd /etc/apache2');
The hosting provider's support forums / FAQ might give specific configuration advice here. Have you tried them?
I've got the same problem as you but I just put this AddType php .html .htm to my .htaccess, it's working.
For me it is working for only like this:
AddHandler php-cgi .php .htm

WAMP PHP/Apache selectively refusing to parse php pages

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.

Categories