What do I need to know about Server Side Includes (SSI)?
A Server Side Include, with an acronym SSI, are sets of directives placed in HTML pages and are used to direct the web server to generate data for the web page whenever it is requested. It is so useful as it allows you to add dynamically generated data without the need to serve the entire page through a CGI program. As such, it helps you save time in doing tasks such as accessing and displaying server specific information like the current server time and the visitor’s IP address.
The most basic use of SSI is that it is used to include one or more files into the web browser. It is usually used to add or insert small pieces of content or a batch of contents to another file. SSI is especially useful in insuring the boilerplate components like headers and footer remains the same throughout the web page. It can also be used to execute programs and then insert the results. The most basic format of SSI is <–#command tag=”value”…> where the value #command can be any or one of the various commands that is supported by the web browser. Its simplest command, which is the #include, is used to insert contents of another file. Though not a requirement, almost all web pages that contain SSI end with a .shtml extension. This extension enables the web server to differentiate pages that need processing before being sent to the browser to those that do not.
It is worthy of note that there is no official standard for SSIs which means each website may choose to support SSIs in different manners. However, the commands #include and #exec have automatically become industry standards.
How can I enable SSI support in my Apache web server?
It is quite easy to enable SSI support in your Apache web server. Although, technically there are a number ways of enabling SSI, which is largely dependent upon the type of server you are using, below is the most common method used. For Apache web servers, simply follow the instructions below and you should have SSI support in your Apache web server in no time:
- First, you need to ensure that the mod_include module is already installed and enabled in your server;
- Next, enable Includes by editing your httpd.conf file. This file is typically found in /etc/httpd/conf. You should set the directive as follows: Options +Includes
- It is important to remember that not all files automatically support SSI. As standard practice, it is recommended not to configure the server to support SSI on all files. Servers automatically scan web pages the support SSI for includes before they are displayed which adds additional burden for the system performance. To do this, you may choose between the following options:
- Configure Apache to parse any file with a particular specific extension, such as .shtml. To configure the server, put the following directives in the http.conf file:
- AddType text/html .shtml
- AddHandler server-parsed .shtml
- Through the use of the XBitHack in the httpd.conf file:
- Use the XBitHack On directive, which tells the Apache server to parse files for SSI directive.
- If you choose to configure Apache to parse files, do not forget to uncomment these lines by deleting the # before the AddType and AddHandler.
- Then, make sure that the DirectoryIndex setting has included the index.shtml and may look like this:
- Restart the Apache and SSI should now be enabled on your system.
What should I do to check whether my system already has SSI support?
The task of checking whether your server already has SSI support or if it is inactive is relatively simple, though laborious. Laborious because you may actually need to do a small test by following these steps:
- First, you need to create a new HTML document and you may name it “test.shtml”, if you want. For the coding, enter the following code:
<!–#echo var=”DATE_LOCAL” –>
- You need to remember these few essential points:
- It is very important that you copy everything correctly including the spacing.
- Please do not forget to put the letter “s” in the .shtml file name extension as it is a very important factor for it to work correctly. The “s” stands for Server, which should tell the host server that the page requires special attention since it is using a special function. Not all host servers, though, require the use of the extra letter but some do. Anyway, putting an extra “s” will not harm the server’s performance even if it is not needed, so better put it in since you don’t know if the host needs it or not.
- Double check for errors and after making sure that everything is correct, upload the page to your online area and then view it. If SSI is enabled in your system, you should see the current date displayed. However, if your system displays a blank page, then it means that SSI is not yet enabled.
Does Server Side Includes (SSI) work on all servers?
Generally, SSI does not work on all servers. It works on some, though not automatically, even though and even if the server is capable of running SSI’s. To allow SSI’s to run, servers have to be configured appropriately. The Apache web server is the most popular web server presently in the market that allows SSI on their system. This is because SSI are basically designed and created for the Apache server.