home   articles   archive   forum   masthead  
Published at 28.9.2000
Author: Ronny Ziegler
Translator: Andy Ziegler
Languages: de nl
Printer printer-version
Support Us!
 

SSI for Apache

Apache Configuration Bored with static HTML sites?
SSI generates parts of HTML sites upon requests by a visitor and enables you to design your sites differently.

(The configuration is based on an Apache web server 1.3.x)

Server Side Included

Static HTML sites always look the same, and this can become boring.
Features like SSI or PHP generate HTML sites after a request. The computer has to work more but the sites can be more interesting.
You could present news all the time without changing your site by hand for every new entry.

Also you can include output of programs and CGI scripts into your sites.

Configuration

Before using this feature you have to change a few configuration files because SSI is turned of by default.

First you need an entry in the file /etc/httpd/acess.conf. In the line options you need the two entries Include and ExecCGI:

/etc/httpd/acess.conf
  
   # This may also be "None", "All", or any combination of "Indexes",
   # "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
  
   # Note that "MultiViews" must be named *explicitly* --- "Options All"
   # doesn't give it to you.
  
   Options   Indexes   FollowSymLinks  Includes  ExecCGI
   #                                                       ^^^^^^^^^^^^^^^^added
  
  

In addition, you have to set the config file so that files with the suffix .shtml and files with .html are checked for SSI commands.
To save CPU power, you could restrict the server to files with .shtml that have to be checked.

The file /etc/httpd/srm.conf gets the following lines (sometimes you just have to de-comment the already existing lines):

/etc/httpd/srm.conf
   # To use server-parsed HTML files
   AddType text/html .shtml
   AddType text/x-server-parsed-html .html
   AddHandler server-parsed .shtml
  


Then you have to restart the Apache Web-Server to use the new configuration. The easiest way uses the existing init-script. With SuSE the command is

 >> /sbin/init.d/apache restart
RedHat places the init-scripts at /etc/rc.d/init.d/.
If the restart worked, you would step into the world of SSI.

The HTML-files

The server was configured correctly but how do you use SSI in HTML sites?

The easiest example is the inclusion of an external file into a site. The visitor will see this file instead of the SSI command.
The SSI lines are cloaked as a comment. If SSI was not active, a visitor will not see the command at all.
You include a file with a line like:

   <!--#include file="./file.txt" -->
  
Here comes an example to make it more clear:

ssi.html
  <html>
  <head>
  <title>SSI Testing
  </title>
  </head>
  <body>
  <center>
  Test with SSI<br>
  The next line executes an SSI command
  </center>
  <p>
   <!--#include file="./test.txt" -->
  </body>
  </html>
  


Of course you need the included file test.txt.

test.txt
  <h1> this is the included test-text file
  <br> Yes, it works!
  </h1>
  


Copy both files to the server and then have a look at ssi.html with any web browser. The page should look like:

Output of ssi.html
SSI Testing
Test with SSI
The next line executes an SSI command

this is the include test-text file
Yes, it works!



If the file to be included was not in the specified directory, you get a message like:

  [an error occurred while processing this directive]
  
If you neither got an error message nor the file test.txt was shown, you should look into the source code of your HTML site using your browser. If you found the line
  <!--#include file="./test.txt" -->
  
in it you might have configured the webserver incorrectly.
It seems that the server does not execute any SSI commands but interprets this line as a comment.

Besides including text files, also you can look at the output of CGI programs. Therefore you need the command

  <!--#exec cgi="/cgi-bin/programm.cgi" -->
  
Instead of this line the text or picture appears that is presented by the CGI program.


Links:
http://hoohoo.ncsa.uiuc.edu/docs-1.5/tutorials/includes.html Information about the use of SSI



Talkback Area




Enter Own Comment