Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

How to enable SSI (Server Side Include) support on an Apache web server


Server Side Include (or SSI) is a useful feature that enables you to do things like include files into your web pages. The most common use for this feature is to allow you to design a navigation bar, put it in a separate file and then include that in all of your web pages. When you need to change the navigation bar you change just the include file, not every web page on your server. The change in the include file simply propogates through all the pages that include it.

Configuring Apache to enable SSI support

The first thing to do is ensure that your server has the mod_include module installed and enabled. Most Linux systems come with this preconfigured so you should not have to worry about this.

The next step is to edit your httpd.conf file to enable Includes. You will typically find this file in /etc/httpd/conf. The directive that needs to be set is as follows:

    Options +Includes

Not all files will automatically support SSI and the recommended practice is that you do not configure your server so that all files support SSI. Web pages that support SSI must be scanned by the server for includes before they are displayed putting a extra overhead on the performance of the system. It is better to only have the server perform that for pages that actually contain includes. This can be achieved in a number of ways:

- Apache can be configured to parse any file with a particular file extension, such as .shtml, with the following directives in the http.conf file:
        AddType text/html .shtml
AddHandler server-parsed .shtml

This is a great approach when you know in advance whether a page needs to use server side includes or not but can be a problem if you need to change an existing page since you would have to rename the page to use the new filename extension and also change any links that point to this file.

- Use the XBitHack directive in the httpd.conf file:

        XBitHack on

XBitHack tells the Apache server to parse files for SSI directives if they have the execute bit set. In other words, to add SSI directives to an existing page, you simply need to make the file executable using the chmod command. For example:

        chmod +x mypage.html

NOTE: When experimenting with pages that support SSI it is important to ensure the pages are actually served up by the Apache web server. A common mistake web designers make is to work on local HTML files in a work directory and directly open the web pages in a browser. In this situation the SSI includes are not activated because the pages are not being handled by the web server. When testing always upload the pages to the web server.

Example SSI  Directives

Now that you have SSI working on your Apache web server here are some useful examples SSI directive in action.

- The syntax for SSI directives is as follows:

    <!--#element attribute=value attribute=value ... -->

- To include a header into web pages:

    <!--#include virtual="/header.html" -->

- To include today's date in a web page:

    <!--#echo var="DATE_LOCAL" -->

- To display the modification date of a web page:

    Document was last modified on <!--#flastmod file="index.html" -->

- To fire up a CGI program and display the result:

    <!--#include virtual="/cgi-bin/mycgi.pl" -->

There are many more advanced uses of the SSI feature of the Apache web server. More detail can be found on the Apache web site at:

    http://httpd.apache.org/docs/howto/ssi.html#apachetutorial:introductiontoserversideincludes

 
 
  © Copyright 2005-2010 Linuxtopia. All Rights Reserved.