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.