Modules in Apache

The Apache Web server has been the number one server on the Internet since 1996. This Daily Drill Down gives you an overview of some of the more popular modules for dynamic content.

In this Daily Drill Down I will give you an overview of some of the more popular Apache modules in relation to dynamic content. Developed in 1995, the Apache Web server is a powerful open-source application. Its users include the British royal family, the Financial Times, and TechRepublic. It runs on almost every computer and OS and has many features and capabilities. No wonder it's been the number one server on the Internet since 1996.

The Apache server is built out of several modules, which are pieces of computer code. By combining these pieces, you can create your own server and configure it for every detail. Many modules are installed by default, such as the mod_dir module, which serves a nice starting page instead of the directory contents.

You can use the modules delivered with Apache, and you can also use modules from third parties, which let you integrate every application you can imagine with your server. You can compile modules in Apache or install them using a tool like RPM.

This Daily Drill Down will cover six modules.

Dynamic content
Many modules enable dynamic content. Dynamic content means that the pages are created just before they’re sent to the person who requested them. This enables you to include files in the dynamic pages, which makes updating easy. You can also add some things to your page that are constantly changing, like the date or form input. Using forms and cookies, you can customize all your pages for every user.

Dynamic content is also used to access databases. A database stored in HTML isn't very easy to update because the data can be stored in more than one place. If you have all of your information in a SQL database, however, you need only change the database to change every dynamic page.

Because dynamic content can be used for so much, including Web applications and search engines, many Web sites use it.

CGI (Common Gateway Interface) is one way to include some dynamic content in your page. When a CGI script is read, it's executed by a program on the server. You could write a Perl script, for example, or a shell script. When the script is executed, the output appears on the screen. You can use CGI for all kinds of files. For example, you can create an HTML file, an image, or an executable file dynamically with CGI.

When using CGI, the server must load the CGI script along with a powerful scripting language every time a CGI is requested, which makes it resource-intensive. This alone gives solid reason for CGI scripts to be most widely used to interpret information from forms and not to create dynamic pages.

When you provide users access to your Web server to let them upload their pages, you probably don't want them to have access to your entire computer. This is, however, possible with CGI, so you might be taking a great risk by letting your users write their own CGI scripts.

PHP (Personal Home Pages) is frequently used for dynamic pages and is made for the job. Started as a Perl hack, PHP has become a real scripting language in its own right. This scripting language can be combined with HTML, so you can include a small section of PHP in an HTML page instead of writing the whole page in PHP. It also has database capabilities and supports almost every existing database. PHP is very similar to Perl, but if you haven't programmed before, you'll find it a bit hard to learn.

Apache modules used by various Web sites:
Web site

Besides using databases as dynamic content, PHP can also deal very well with forms and cookies, which makes it very useful for every customization or adaptation that a good site needs.

The Server Side Includes (SSI) module, which is, like CGI, available with Apache, is not very powerful but implements just enough functionality to make it easy to update small sites. With SSI, you can insert pages into other pages, which is helpful if every page contains something like a menu. If you want to change an item on the menu, then you only need to change the file containing the menu, and the Web server will paste the menu into all other files in the areas you defined.

SSI also supports some dynamics, such as different pages for every browser, but it’s not as powerful as PHP.

Securing your site with SSL
Of course not all Apache modules are for dynamic content—many of them are for securing your Web server. Normally, all Internet traffic is unencrypted and can be read easily with a sniffer. You can use SSL to encrypt your pages and other content, so that credit card numbers or other sensitive content cannot be easily read.

This doesn't imply that you’re completely safe when you encrypt everything. If someone can reach the data otherwise, such as by a telnet session to the server or by searching the cache of a client's browser, it doesn't matter whether you encrypt your pages or not.

In some cases, it's important to make sure that not everybody can read all information on a Web server. If you want to make particular information available only to some users, such as members, authorized users, or persons who paid to see it, then you could password-protect part of your server. You can enable password protection by using the authorizing module, which asks for a username and password. This is far safer than using JavaScript or other scripting languages, and the password is encrypted. There are also modules that can obtain the password from other places, such as a database or the system's password file.

User tracking
Sometimes you’d like to know which pages are visited often and which are not. With the user-tracking module, you can see how many people have visited your site, where they came from, which links they clicked, etc. This is very useful information: You can see where people spend the most time and then place advertisements on the pages that are visited heavily, or you can place links to appropriate pages.

In this Daily Drill Down, I’ve taken a look at some of the more popular modules used by the Apache Web server and how well they do (or do not) work with dynamic content. Most modules are very easy to use and configure, so you should not have to spend a lot of time learning them.

More information
For more information, you could visit the PHP or Apache Web sites. The Apache site contains information about all modules discussed here.
The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

Editor's Picks