Server Side Includes (SSI) is a simple interpreted server-side scripting language used almost exclusively for the web. It is utilized for managing web content through the inclusion of “directives” within web pages, which are parsed and executed by the web server. For instance, they can allow the inclusion of the contents of one or more files into a web page on a web server, or display the current date and time.
Enabling SSI on your Apache server is not an overly complicated task, but it does require a clear understanding of server configurations. Below, we will explore a step-by-step guide on how to enable Server Side Includes in Apache.
- Access to a server with Apache installed.
- Basic knowledge of command-line interface usage.
- Administrative access, or sudo privileges.
Please note that the instructions are based on the assumption that you are running a Unix-like server, such as Ubuntu or CentOS.
Step 1: Enable the mod_include Module
The first thing you need to do is ensure the `mod_include` module is enabled. This module provides the Server Side Includes functionality. To enable it, use the a2enmod command, followed by the name of the module.
sudo a2enmod include
After running this command, you’ll need to restart the Apache server to load the new module:
sudo systemctl restart apache2
Step 2: Allow Server Side Includes for a Directory
After enabling mod_include, you will need to set the Options +Includes directive in the configuration file of the directory where you wish to enable SSI. This can be done in the main Apache configuration file (often located at /etc/apache2/apache2.conf or /etc/httpd/httpd.conf), a virtual host file, or a .htaccess file.
Open the configuration file using a text editor, such as nano or vim:
sudo nano /etc/apache2/sites-available/000-default.conf
Then, within the
Step 3: Set the AddType or AddOutputFilter Directive
In addition to enabling includes with Options +Includes, you need to tell Apache that files with a certain extension should be parsed for SSI directives. This is done using either the AddType or AddOutputFilter directive.
To parse .shtml files for SSI directives, you could add the following line to the same configuration file:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
With this configuration, any file ending with .shtml will be parsed for SSI directives.
Step 4: Save and Close the Configuration File
After you’re done with the configurations, save the changes and close the file. If you’re using nano, you can do this by pressing `Ctrl + X`, then `Y` when prompted to save the changes, and finally Enter to confirm the filename.
Step 5: Restart Apache
The final step is to restart the Apache server so that the changes can take effect:
sudo systemctl restart apache2
Now, SSI should be enabled for your Apache server.
Testing Your SSI Configuration
You can quickly test your configuration by creating a .shtml file with a simple SSI directive.
Here is a simple command that will do this:
echo "" > /var/www/html/test.shtml
This creates a file named test.shtml in the /var/www/html directory. The file contains an SSI directive that tells the server to print the current date and time.
You can view the result by visiting http://your-server/test.shtml in your web browser. If you see the current date and time displayed, that means Server Side Includes are working correctly on your Apache server.
By following the steps outlined in this guide, you have now successfully enabled Server Side Includes (SSI) in Apache. This feature can be very useful for dynamically including content in your web pages without having to resort to more complex scripting languages. Remember to use SSI judiciously and keep your server configurations secure.