Ugacomp

How to configure Apache to enable server-side includes (SSI)?

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM

CLOUD VPS M

$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM

CLOUD VPS L

$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Server-Side Includes (SSI) are a powerful tool for web developers, allowing them to embed dynamic content within HTML pages served by the Apache web server. This feature can be particularly useful for creating consistent headers and footers, managing reusable code snippets, and dynamically updating content without relying on client-side scripting.

In this comprehensive guide, we will explore the steps to configure Apache to enable Server-Side Includes.

Enable mod_include module

Before configuring Apache for SSI, ensure that you have administrative access to your server and that Apache is installed. Additionally, make sure that the mod_include module is enabled.

To check if mod_include is enabled, run the following command:

apachectl -M | grep include

If the module is not listed, you’ll need to enable it. Use the following command to enable mod_include:

a2enmod include

After enabling the module, restart Apache to apply the changes:

service apache2 restart

Once mod_include is enabled, you can configure Apache to process SSI directives by adding the appropriate directives to your Apache configuration files.

Step 1: Identify the Apache Config Files

The main Apache configuration file is often named httpd.conf and is located in the /etc/apache2 directory. However, on some systems, configuration files might be organized differently. Common locations for Apache configuration files include:

  • /etc/httpd/conf/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/apache2/sites-available/your-site.conf

Step 2: Edit the Configuration File

Use a text editor to open the Apache configuration file in a terminal. For example:

nano /etc/apache2/apache2.conf

Step 3: Enable SSI module

Add the following lines to enable Server-Side Includes:

<IfModule mod_include.c>
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

These lines specify that files with the .shtml extension should be processed for SSI directives.

Step 4: Configure Directory Options

To enable SSI within specific directories, you need to set the Options directive. Locate the <Directory> section for the directory where you want to enable SSI and add or modify the Options line:

<Directory "/path/to/your/directory">
    Options +Includes
    AddOutputFilter INCLUDES .html
</Directory>

Replace /path/to/your/directory with the actual path to the directory where you want to enable SSI.

Step 5: Test Your Configuration

Create a new HTML file (e.g., index.shtml) in the configured directory and add an SSI directive. For example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SSI Test</title>
</head>
<body>
    <!--#echo var="DATE_LOCAL" -->
</body>
</html>

Access the file through your web browser, and if everything is configured correctly, you should see the local date and time displayed on the page.

Conclusion

Configuring Apache for Server-Side Includes provides a powerful mechanism for dynamic content generation within HTML pages. By following the steps outlined in this guide, you can enhance your web development workflow and create more modular and maintainable websites. Always remember to test your configuration changes and consult the Apache documentation for additional customization options and security considerations.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.
 

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.