Home » Topic » Apache Handlers

Apache Handlers

Apache Handlers

A “handler” is an internal Apache command that tells the Apache server software what action to perform when a file is called. Generally, files have what is know as implicit handlers, which are based on the file type. Normally, all files are simply served by the server, but certain file types are “handled” separately.

For example, PHP files when served to the user are first run through the PHP program running on the server. They are processed and returned back to the Apache server to be sent to the user. The ability to explicitly add handlers to Apache started with version 1.1. This means that handlers can be specifically added to files without regard to the inherent type of file but based on the file extension.

What this means is that you can put PHP or asp code in a .html file and it will be processed by the PHP program on the server before being sent to the user. Why would you want to do that? Well, just think of all the .html or .htm files that you probably currently have on your or some other server you are managing. And just think about all the links to those files. Wouldn’t it be nice to just add PHP code to those files and not have to worry about renaming them or changing all the links to them? Sure it would.

So here is how to do it.

I am going to show you the method using the CPanel that your hosting provider probably has setup for you if you are using a standard Linux hosting service.

Step 1: Login to your CPanel by typing www.yourdomain.com/cpanel into your address field in your browser. Type in your login information. Step 2: Click on the Apache Handlers icon or link option. Your should see a screen like this one.
example 1

Step 3: Enter in the file extension you want to add like .html into the small field and application/x-httpd-php in the larger field for the PHP program. Then click the Add button. If you want to delete one, select it from the drop-down menu and click the Delete button. The other programs that you might want to have it run thought are below.

application/x-httpd-cgi – for CGI (Common Gateway Interface)

application/x-httpd-asp – for ASP (Active Server Pages)

application/x-httpd-asp-cgi – for ASP in CGI scripts

application/x-tar – for .tgz compressed files

application/zip – for .zip compressed files

.htaccess Method

Since some of you have expressed interested in doing this without the use of CPanel, I have decided to amend this article. Yes, it’s possible to tell Apache web server to do the same thing without using CPanel to do it.

Here is the procedure. You need to turn on the ability to see hidden files on the ftp program you use. Then ftp into your site and look for the .htaccess file in the root level of your site. The one that holds your homepage. If one does not exist, then you can create a plan text file that is named “.htaccess”.

Download the file to your hard drive and open it in a text editor that supports UNIX line breaks. On Windows you can use TextPad or on Mac you can use BBEdit Lite or TextWrangler. There may or may not be anything in the file when you open it. On a new line paste in the following.

AddHandler application/x-httpd-php .html

AddHandler application/x-httpd-php .htm

Save the file and then upload it back to your site. That’s it. Your files that end in .html or .htm will now be processed by PHP so you can put PHP code in them.

About

I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry from last 7 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud