Bruce Crowthorne
Posts: 67
Joined: Wed Jan 11, 2012 7:19 pm

How to enable Server Side Includes on Apache2 on Raspian

Mon Apr 16, 2018 7:15 pm

I am trying to enable Server Side Includes on my Apache server.
Having Googled and searched for answers I still can't find anything. Closest I got was at http://forum.kitz.co.uk/index.php?topic=12356.0 but that doesn't work.

Has anyone got this working? Or a link to a good site?
Thanks
Bruce

PS I have only just learned about this Apache capability and it makes site easier to update and maintain. Basically it allows you to separate the menu system and headers etc into one file and then "include" that in each of the sub pages, so you only maintain the menu system and headers once!

knute
Posts: 351
Joined: Thu Oct 23, 2014 12:14 am

Re: How to enable Server Side Includes on Apache2 on Raspian

Mon Apr 16, 2018 7:50 pm

1. sudo a2enmod include
2. add the following to your config file in /etc/apache2/sites-available/000-default.conf (you might have changed this file's name)

Code: Select all

    <Directory /var/www/html>
        Options +Includes
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
        XBitHack on
    </Directory>
3. sudo apachectl restart or sudo systemctl restart apache2
4. Write some SSI includes

The above turns on two methods of showing documents with includes, either HTML documents with the .shtml extension or enabling the execution bit, XBitHack, on a regular HTML document (sudo chmod +x doc.html).

Another note, install the apache manual, it is very good and has the complete description on how to do this.

sudo apt update
sudo apt install apache2-doc

You can get to it with this address: http://localhost/manual

Bruce Crowthorne
Posts: 67
Joined: Wed Jan 11, 2012 7:19 pm

Re: How to enable Server Side Includes on Apache2 on Raspian

Tue Apr 17, 2018 8:11 am

Hi Knute, I had already found the manual page and had done everything except the "XBitHack on".

I had tried all the other bits, but my index.html has the "html" extension. I had tried renaming it with an "shtml" extension, but of course it didn't load.
So it looks like the XBitHack was what was wrong - phew!

Now I can carry on with the next part of my testing.

Thanks again for your help
Regards
Bruce

knute
Posts: 351
Joined: Thu Oct 23, 2014 12:14 am

Re: How to enable Server Side Includes on Apache2 on Raspian

Tue Apr 17, 2018 5:05 pm

.shtml should work unless you missed something. It doesn't require the XBitHack on statement to work.

mfa298
Posts: 1273
Joined: Tue Apr 22, 2014 11:18 am

Re: How to enable Server Side Includes on Apache2 on Raspian

Tue Apr 17, 2018 5:57 pm

The other bit of config that might need updating is

Code: Select all

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
(this is was from a non Pi web server)

This lists the files that will be used when you don't specify a specific file (e.g. when you go to http://my.site.org)

You would probably want to add index.shtml somewhere in that list if you want that to be used in the same way as index.html or index.php

tpyo kingg
Posts: 203
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: How to enable Server Side Includes on Apache2 on Raspian

Wed Apr 18, 2018 11:23 am

You might also be interested in the IncludesNOEXEC option for Apache2 and exploring the advantages between it and the Includes option. So remember the Principle of Least Privilege.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 11 guests