Fail to interpret PHP in Windows 7 Apache. Why? - php

I have follow every step of setting up apache & php in Windows 7.
I have the following set in the Httpd.conf:
LoadModule php5_module "C:/PHP/php5apache2_2.dll"
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php
</IfModule>
PHPIniDir "C:/PHP/"
if it is .html, it displays no problem. (e.g. localhost/index.hmlt)
if it is .php, then it displays the source code (e.g. localhost/phpinfo.php in which phpinfo.php is:
I run the phpinfo.php in command line and there is no problem. it is the apache server that doesn't recognized PHP. so what may be wrong?

You are encasing the type code in the wrong module
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .php
</IfModule>
should be
<IfModule php5_module.c>
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
</IfModule>
most distributions will include a php config file that does this for you in the correct way
DC

Related

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.

OS X Lion Apache & PHP not communicating

My apologies if this has already been answered - I'm having difficulty finding a solution however.
I'm attempting to make the OSX 10.7.4 Apache, PHP, MySQL leap... I followed this http://echodittolabs.org/blog/2011/09/os-x-107-lion-development-native-apache-php-homebrew-mysql-or-mariadb, which for the most part went flawless (I had a minor hickup with the .plist but that is fixed).
Apache works fine. PHP works fine (thru terminal). I cannot get any PHP file to work via the browser however. I've uncommented LoadModule php5_module libexec/apache2/libphp5.so as well as included the IfModule php5_module piece. I've checked the modules loaded by apache which includes PHP5. Apache error_log provides nothing
Thoughts? (Please don't say use MAMP).
Try adding this line to your IfModule php5_module block:
AddHandler php5-script .php
So it looks like this:
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddHandler php5-script .php
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

Apache server wont start after trying to configure it to run with php

I installed apache server 2.2.19 on a vista machine. It was running fine but I tried to configure it to use php by modifying the httpd.conf file. These are the lines I added
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir “C:\PHP”
I added this below this line
AddType application/x-gzip .gz .tgz
I also added this line
LoadModule php5_module “C:\PHP\php5apache2_2.dll”
I added this below this line
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
I tried to restart the apache server but every time i do so it returns an error message that The requested operation has failed. What could be the problem?
I don´t have any experience with installing it on windows, but the following lines seem very wrong to me:
PHPIniDir “C:\PHP”
LoadModule php5_module “C:\PHP\php5apache2_2.dll”
Is that really what you added? If it is, I would suggest changing it to:
PHPIniDir "C:\PHP"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
Note that I am using " instead of the curly quotes you are using.
If you are having problems I would suggest just downloading Xampp for Windows. It takes the manual steps out of installing the separate components.
Normaly, this is how you would set up PHP under Apache...
(adjust for your paths)
LoadFile "D:/WampDeveloper/Components/Php/php5ts.dll"
LoadModule php5_module "D:/WampDeveloper/Components/Php/php5apache2_2.dll
<IfModule php5_module>
PHPIniDir "D:/WampDeveloper/Config/Php"
<Directory "D:/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>
</IfModule>
You will do better to use a pre-made Apache, PHP, and MySQL solution for Windows.
XAMPP
WampServer
WampDeveloper Pro

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