Wamp Server Not Parsing htm Files As PHP - apache

I know this question has been already asked here. I am trying to use a script in my localhost. The script contains .htm files and an .htaccess file with the following code to parse those .htm files as PHP.
AddHandler application/x-httpd-php5 .htm .php .html
Now this is not working at all and i get a blank web page whenever i run it from my localhost. i.e "localhost/paystill_enterprise" and it give me blank webpage.
Now i have tried every solution i could find on internet like editing httpd.conf file etc. Here are some of the solutions i have tried.
1- I have tried editing httdp.conf and have added the following code one by one
<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .txt
</IfModule>
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
<FilesMatch "\.htm$">
ForceType application/x-httpd-php
</FilesMatch>
2- Tried adding these lines of code one by one in my .htaccess file
AddType application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
No matter what i use, always get a blank page for "localhost/paystill_enterprise".
Note:
Sometimes it also happens that when i type the address "localhost/paystill_enterprise", the browsers asks me to save the file i.e the browser tries to download it.
Any suggestions?

The one time I did this all I did was add these 2 instructions to me .htaccess file.
AddHandler application/x-httpd-php .html
DirectoryIndex index.html index.php
So remove all your other changes and try just this one change as your other chnages may interfere with this.

Related

AddType (css, js) not working after Apache 2.3.x

After moving an old server to Apache 2.4 all of our
AddType text/css .css
AddType text/javascript .js
.. 'esque directives have stopped working.
mod_mime and all of the same configurations are in place.
After Apache 2.3.x the DefaultType directive has been removed and replaced with the ForceType directive.
Note that the ForceType directive overrides any AddType directives.
See: https://httpd.apache.org/docs/2.4/mod/core.html#forcetype

.htaccess - Deny all except one folder

I am trying to deny all connections to my website using .htaccess that looks something like this:
ErrorDocument 403 /errors/403\.php
SetEnvIfNoCase Request_URI "^/errors/403\.php$" HANDLE403
order deny,allow
deny from all
allow from 188.167.150.5
allow from 78.145.188.71
allow from env=HANDLE403
AddType application/x-httpd-php53 .php
AddType application/x-httpd-php5 .php52
AddType application/x-httpd-php .php4
The .htaccess file is stored in the root folder of my ftp and this works fine, however I want to use custom Error 403 page which is saved in Errors folder on the same ftp, so basically it gets blocked too. I have tried to create a new .htaccess in the Errors folder (as suggested in other topics) with this code:
order allow,deny
allow from all
AddType application/x-httpd-php53 .php
AddType application/x-httpd-php5 .php52
AddType application/x-httpd-php .php4
But it still doesn't work and I get just the default 403 page with "Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request."
Any idea how I could fix this, so that the error files are accessible by all, while the rest is denied for all except few specific IPs?
Use your custom handler like this:
ErrorDocument 403 /errors/403.php
order deny,allow
deny from all
allow from 188.167.150.5
allow from 78.145.188.71

How to select file in subdirectory by "files" directive?

I want to compile PHP code in specific .htm file, if file located at root directory of domain I can add
<Files file.htm>
AddType application/x-httpd-php5 .htm
</Files>
to .htaccess, but what should I do if file located at another directory(/sub/file.htm, for example)?
Maybe it could be done if your are using httpd 2.4 which has <if> supports
<If "%{PATH_INFO} =~ /.*\/sub\/(file|anotherfile|andanother)\.htm/">
AddType application/x-httpd-php5 .htm
</If>
Maybe you want to use the httpd.conf instead of .htaccess file. You could then use <Location>-directive in this case:
<Location /sub/file.htm>
AddType application/x-httpd-php5 .htm
</Location>
Note that if you want to use a regexp to match the location you need to write a ~ before the location or use the <LocationMatch>-directive.
E.g.:
<Location ~ "/sub/(file|anotherfile|andanother).htm">
AddType application/x-httpd-php5 .htm
</Location>
EDIT:
Another possible solution (also only in virtualhost-config) should be a combined <Directory> and <Files>-directive:
<Directory /sub>
<Files file.htm>
AddType application/x-httpd-php5 .htm
</Files>
</Directory>
Try FilesMatch:
<FilesMatch "file.htm$">
AddType ...
</Files>
It applies a regex to the filename, so this'll match any file path which has "file.htm" at the end. It'd apply to any file in any directory that ends with "file.html". Note that this would also match on "somefile.htm" and "/subdir/somefile.htm". If you've got other files in your site tree that could trigger this, you'll have to mod the regex to exclude them.

.htaccess add exception to disabled CGI execution

I have a website with a "protected folder" using a .htaccess file.
Inside this folder the execution of CGIs is disabled, the .htaccess is as follow
Options -Indexes -Includes -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi .php4 .php5 .js
Now I'm in the need of executing a PHP script in this folder (overiding the CGI disabling), lets suposse the name of my script is
my_script.php
What is the best way to maintain my security in this folder deniying the execution rights to ALL the scripts BUT to my_script.php?
I have full access to the .htaccess file so I can change what I want.
Kind regards and thanks a lot in advance.
P:.

Apache and mod_mono not playing well together

I'm trying to get Mono to work on CentOS 5, however haven't had much success so far. This is what I did:
> yum install mono-web
> yum install xsp
> yum install mod_mono
> echo ":CLR:M::MZ::/usr/bin/mono:" > /proc/sys/fs/binfmt_misc/register
Ensured that the following line is present in /etc/httpd/conf/httpd.conf:
Include conf.d/*.conf
Ensured that /etc/httpd/conf.d/mod_mono.conf exists and looks like this:
<IfModule !mod_mono.c>
LoadModule mono_module /usr/lib/httpd/modules/mod_mono.so
AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex default.aspx
DirectoryIndex Default.aspx
<Location /mono-ctrl>
SetHandler mono-ctrl
</Location>
</IfModule>
Created /etc/httpd/conf.d/mono-vhost.conf and inserted the following:
<VirtualHost *>
DocumentRoot /var/www/html
Alias /demo /usr/local/lib/xsp/test
MonoApplications "/demo:/usr/local/lib/xsp/test"
MonoServerPath /usr/bin/mod-mono-server2
<Location /demo>
SetHandler mono
</Location>
</VirtualHost>
And finally:
> apachectl restart
Then I browsed to http://my.server.ip.address/demo/index.aspx, expecting to see an ASPx page; instead my browser prompted me to download that file. There is nothing in the Apache error log.
I've got other websites running on this box via PHP and they work perfectly, so I'm pretty sure it's just mod_mono that's weird, but for the life of me I can't figure out what the problem is. If anyone can point me in the right direction, it would be most appreciated.
Eventually got it working with the help of the following tutorial:
http://blog.palehorse.net/2008/11/06/my-adventures-installing-mono-20-on-centos-4-to-work-with-apache-via-mod_mono/
Although it's for CentOS 4 it works just as well on CentOS 5.x. :)