How to Set Up Server Side Includes in Apache

Setting up server side includes — or SSIs — in Apache is quite easy, we’ll show you how.


Most people set up SSIs to allow them to include text files within their Web pages, like a regular footer or nav bar. Of course you can do other useful things, like echoing a date or even executing CGIs — but first, you have to configure Apache to use server side includes.

The first thing to do is to open up Apache’s main config file — httpd.conf. Under Linux, that’s probably in /etc/httpd/conf/httpd.conf, under Windows, it’s in the “conf” directory under your installation location. Once you’ve got that open, you’ve got to add the following to any directory (marked by tags) for which you want includes to be turned on:

 Options +Include

That tells Apache to “turn on” SSIs for that directory (and every directory underneath it). Most people do this at the top level of their site, so that SSIs are turned on in every directory of their site. Next, you have to tell Apache which files to evaluate (or parse) for server side includes — usually, you wouldn’t want your server to parse every file for SSIs, so you’d limit it like this:

 AddType text/html .shtml
 AddHandler server-parsed .shtml

The first line says: Add a new type of file, shtml, and give it a mime-type of text/html. The second line says to Apache: any files that end with shtml, parse them for SSIs and send out the resulting document. There are other ways to specify which files should be parsed — one is the XBitHack, which parses all files who’s permissions are set as “executable.” For more on the XBitHack, see Apache.org.

Once you’ve updated your config, restart Apache, and you should be good to start using SSIs. Here are some simple, frequently used SSI examples:

Include a File:

 

Print Today’s Date:

 
 Today is 

Include results of a CGI program:

 

Facebook Comments

More Stuff

The US Again Has the World’s Most Powerful Supercomputer Plenty of people around the world got new gadgets Friday, but one in Eastern Tennessee stands out. Summit, a new supercomputer unveiled at Oak Ridge N...
Facebook fractures its secretive hardware division Roughly a year and a half ago, Regina Dugan, a former director for the US government’s Defense Advanced Research Projects Agency, took the stage at Fa...
WordPress to Static Site Generator (Hugo) Migration and Deployment TL;DR?—?This article will show you how to migrate a simple WordPress website to a static site generator (Hugo) and host it for free on either Netlif...
How to Access a Remote Server Using a Jump Host A jump host (also known as a jump server) is an intermediary host or an SSH gateway to a remote network, through which a connection can be made to ano...
Spread the love