Diff for "ServerSideIncludes"


Differences between revisions 1 and 16 (spanning 15 versions)
Revision 1 as of 2006-07-26 02:41:01
Size: 2110
Editor: S0106001150603f7d
Comment: move from wiki.u.c
Revision 16 as of 2012-03-25 18:23:14
Size: 3232
Editor: dsmythies
Comment: Fix bad information about includes and index files. Old way could lead to directory listing avilable when undesired.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
How to set up [http://httpd.apache.org/docs/2.0/howto/ssi.html Server Side Includes] on [:ApacheMySQLPHP:Apache], assuming you already have Apache installed. <<Include(Tag/StyleCleanup)>>

How to set up Server Side Includes (SSI) on [[ApacheMySQLPHP|Apache]], assuming you already have Apache installed.

Server Side Includes are a very simple way of performing a limited Server Side Programming. For instance, you can have the server assemble one single document by merging smaller ones (with the #include directive), you can display data on the file itself (with the date_local directive, and many more), and if security is none of your concern, you can even execute local programs.
Line 7: Line 11:
cd /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/include.load
sudo a2enmod include
Line 11: Line 14:
This creates a SymbolicLink in mods-enabled of the config file in mods-available. See also RootSudo. This creates a symlink in mods-enabled of the config file in mods-available.
Line 27: Line 30:
 # This directive allows us to have apache2's default start page
 # in /apache2-default/, but still have / go to the right place
 # Commented out for Ubuntu
 #RedirectMatch ^/$ /apache2-default/
</Directory>
}}}
and edit it to look like this:
{{{
<Directory /var/www/>
 Options Indexes FollowSymLinks MultiViews Includes
 AllowOverride None
 Order allow,deny
 allow from all
Line 34: Line 42:
and edit it to look like this: You need to add `Includes` to the end of the end of the `Options`. If you only want to
run server side includes from your user directory, the /etc/apache2/mods-available/userdir.conf file aready has a `IncludesNoExec` in the `Options` line.

If you want includes in index pages then edit the /etc/apache2/mods-availables/dir.conf file from this:
{{{
<IfModule mod_dir.c>
          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
}}}
to this (indent changed to fit onto one line in this document):
{{{
<IfModule mod_dir.c>
 DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml
</IfModule>
}}}

Note that on some older versions of Ubuntu, the /etc/apache2/mods-available/mime.conf might not contain the required `AddType` and `AddOutputFilter` directives for .shtml. and so another two lines will be required in /etc/apache2/sites-available/default:
Line 37: Line 61:
 Options Indexes FollowSymLinks MultiViews +Includes  Options Indexes FollowSymLinks MultiViews Includes
Line 41: Line 65:
 # This directive allows us to have apache2's default start page
 # in /apache2-default/, but still have / go to the right place
 # Commented out for Ubuntu
 #RedirectMatch ^/$ /apache2-default/
Line 50: Line 70:
You need to add `+Includes` to the end of the end of the `Options`, and two new lines after the commented-out lines.
Line 52: Line 71:
== Restart Apache2 ==
== Restart Apache ==

For the changes to effect you will need to restart Apache with
Line 72: Line 94:
If your browser displays the local date (eg Saturday, 06-Aug-2005 23:05:21 CEST), SSI is working! If your browser displays the local date (eg Sunday, 18-Mar-2012 11:12:56 PDT), SSI is working!

Tested on Ubuntu 9.04, 12.04
Line 75: Line 99:
Based on [http://www.unet.univie.ac.at/%7Ea9826090/en/projects/linux/ubuntu-apache2-ssi.html Rafael Gattringer's Ubuntu Apache2 SSI Installation guide], with permission. Based on [[http://www.unet.univie.ac.at/%7Ea9826090/en/projects/linux/ubuntu-apache2-ssi.html|Rafael Gattringer's Ubuntu Apache2 SSI Installation guide]], with permission.

For usage examples, see also [[http://httpd.apache.org/docs/2.2/howto/ssi.html|SSI on apache.org]], but do not use it as a how to enable SSI reference, use this guide.
Line 77: Line 103:
CategoryCleanup

Tag/tag.png

Style Cleanup Required
This article does not follow the style standards in the Wiki Guide. More info...

How to set up Server Side Includes (SSI) on Apache, assuming you already have Apache installed.

Server Side Includes are a very simple way of performing a limited Server Side Programming. For instance, you can have the server assemble one single document by merging smaller ones (with the #include directive), you can display data on the file itself (with the date_local directive, and many more), and if security is none of your concern, you can even execute local programs.

Enable the Includes module

sudo a2enmod include

This creates a symlink in mods-enabled of the config file in mods-available.

Editing config

Open the /sites-available/default file...

gksudo gedit /etc/apache2/sites-available/default

find this section...

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>

and edit it to look like this:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews Includes
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>

You need to add Includes to the end of the end of the Options. If you only want to run server side includes from your user directory, the /etc/apache2/mods-available/userdir.conf file aready has a IncludesNoExec in the Options line.

If you want includes in index pages then edit the /etc/apache2/mods-availables/dir.conf file from this:

<IfModule mod_dir.c>
          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

to this (indent changed to fit onto one line in this document):

<IfModule mod_dir.c>
 DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml
</IfModule>

Note that on some older versions of Ubuntu, the /etc/apache2/mods-available/mime.conf might not contain the required AddType and AddOutputFilter directives for .shtml. and so another two lines will be required in /etc/apache2/sites-available/default:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews Includes
        AllowOverride None
        Order allow,deny
        allow from all
        AddType text/html .shtml
        AddOutputFilter INCLUDES .shtml
</Directory>

Restart Apache

For the changes to effect you will need to restart Apache with

sudo apache2ctl restart

Test it works

Create a SSI test file and save it under /var/www/ssi-test.shtml.

<html>
<head>
<title>SSI Test Page</title>
</head>
<body>
<!--#echo var="DATE_LOCAL" -->
</body>
</html>

In your WebBrowser, go to http://127.0.0.1/ssi-test.shtml.

If your browser displays the local date (eg Sunday, 18-Mar-2012 11:12:56 PDT), SSI is working!

Tested on Ubuntu 9.04, 12.04


Based on Rafael Gattringer's Ubuntu Apache2 SSI Installation guide, with permission.

For usage examples, see also SSI on apache.org, but do not use it as a how to enable SSI reference, use this guide.


ServerSideIncludes (last edited 2014-06-06 13:03:12 by ya-bo-ng)