My clients host uses PHP4 and 5 and all *.php files run via 5 but when I use this
<FilesMatch "edit.js">
AddHandler application/x-httpd-php .js
</FilesMatch>
it runs as PHP 4.4.9 but not on my personal web server (VPS) I need this file.
<FilesMatch "edit.js">
AddHandler application/x-httpd-php5 .js
</FilesMatch>
doesn't seem to work just displays source code of PHP.
and help appreciated.
Try
AddHandler application/x-httpd-php5 .js
^---
Since, as you say, your host has both PHP 4 and PHP 5, you need to expclitly say which version you want used.
Related
I am on a shared linux server using php7. I want my .html pages use php. I have tried every answer on here, things so far are;
AddType application/x-httpd-php7.0 .html .htm - downloads the page when trying to open it
AddHandler application/x-httpd-imh-php70 .html - does nothing
I've tested this in .htaccess, worked for me:
<FilesMatch ".+\.(htm|html)$">
SetHandler application/x-httpd-php
</FilesMatch>
https:/www.example.com/test/my.html or my.htm will be interpreted by php7.
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).
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
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
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.