Home > Software, Web > Web publishing system with Apache and Subversion – part 1

Web publishing system with Apache and Subversion – part 1



Introduction

What does a versioning system have to do with the web and more specifically with a publishing system?

When developing small websites (mainly presentation ones) you usually don’t need a versioning system. This post will come very handy to you if you work on a bigger team developing an enterprise (not necessarily, presentation) website. There a versioning system is clearly needed: user concurrency, history backup, a central repository, basically the main features of such a system.

I have chosen Subversion as the concurrent versioning system, not only as being the latest in style😉, but also for some features which makes it perfect, easy to use and easy to setup. In a few words we want a web publishing system that:

  • mandatory: is free
  • mandatory: is easy to setup for administrators
  • mandatory: is very easy to use for (web) developers
  • mandatory: features versions for the web pages, so you will be able to see changes in time and revert to previous versions
  • mandatory: provides an authentication and authorization system
  • nice to have: the authorization system can be configured per module, meaning that different groups of developers can have read/write access to different sections of the website
  • nice to have: able to send notifications every time a web page is modified
  • nice to have: is customizable and able to perform specific tasks whenever a change is made (add/edit/delete web pages)
  • nice to have: running on multiple OSes

Taking all this into account, what is the solution? I will continue by describing the steps how to setup and use such a system.


Installation


First of all, download and install Apache 2.2 and Subversion. The installation is very easy and I will not enter here in any details (there are even binary packages, aka installers, for all the main operating systems:) ).


Configuration


Now let’s get to the server configuration. For the sake of the example, let’s suppose that we will use the /wps or c:\wps (for Windows) folder for the entire thing. We will create the svnrepo subfolder as a parent for all Subversion repositories and then create a Subversion repository for the website using the svnadmin command:

svnadmin create /wps/svnrepo/web

or in Windows

svnadmin create c:\wps\svnrepo\web

Let’s go now and configure Apache so that you can access Subversion repository through it. We don’t use the lightweight svnserve standalone server because we already have Apache installed as a web server. The configuration steps are:

  1. Copy the files mod_dav_svn.so and mod_authz_svn.so from <svn-dir>/bin to <apache-dir>/modules, where <svn-dir> is the Subversion installation directory and <apache-dir> is the Apache installation directory (usually C:\Program Files\Apache Software Foundation\Apache2.2 in Windows).
  2. Add the following line to the Apache configuration file <apache-dir>conf/httpd.conf:

    Include conf/extra/wps.conf

  3. Create and edit with your favorite text editor the file <apache-dir>conf/extra/wps.conf.Paste the below content into:

    LoadModule dav_svn_module 
      modules/mod_dav_svn.so
    LoadModule authz_svn_module 
      modules/mod_authz_svn.so
    
    <IfModule dav_svn_module>
    # if the module was loaded succesfully
    
    # to exclude SVN files from web published folders
    <Directory ~ "/.svn">
        Order allow,deny
        Deny from all
    </Directory>
    
    # if you want a virtual host for Subversion
    <VirtualHost *:80>
        ServerAdmin administrator@domain.com
        ServerName svn.domain.com
        
        <Location / >
            DAV svn
            SVNParentPath /wps/svnrepo
            SVNListParentPath On
        </Location>
        
        ErrorLog "logs/wps.log"
    </VirtualHost>
    
    # the Subversion folder
    <Location /svn >
    
        DAV svn
        SVNParentPath /wps/svnrepo
        SVNListParentPath On
    
    </Location>
    

If you restart your Apache web server you will be able to access the SVN repository at http://domain.com/svn/web or at http://svn.domain.com/web.

Now we will create a web folder to host the website files and then checkout the web repository into it. Note that if you’re going to use a trunk/tags/branches directory organization (which I definately recommend) in the repository then you should checkout in the web folder only the trunk:

svn checkout http://domain.com/svn/web/trunk /wps/web

As you noticed by now the /wps/web is a working copy of the repository. But checking out the repository is not enough, you have to set up a commit hook to automatically update the working copy every time a change is made. Create a file post-commit in Unix (don’t forget to change the x mode – chmod 775 post-commit) and post-commit.bat in Windows with the following content:

svn update /wps/web

Every time a change is commited into the Subversion repository that change gets into the web directory too. Of course a .svn directory is created under each directory. You don’t have to delete them, the Directory ~ "\.svn" Apache section in wps.conf will deny access to these directories.

Now you have only to add a few lines to wps.conf to enable access to the web folder:

DocumentRoot "/wps/web"
ServerAlias www.domain.com

<Directory "/wps/web">
    Options Indexes FollowSymLinks
    AllowOverride None
    Allow from all
</Directory>

Note: Please don’t forget to restart Apache every time you change the configuration files.

Now everything should be up and ready. But everyone can commit to your web repository and you definately don’t want this.

In the next parts I will explain how to setup an authentication and authorization system and how to create a second web repository accessible only within your organization.

Part 2Part 3

Download configuration files.

  1. September 18, 2008 at 12:55 pm

    Great post!

    I think the command

    should be

    as per your later remark. Please fix.

    bests,
    Animesh

  2. September 18, 2008 at 2:29 pm

    Hi,
    I meant

    <Directory ~ “/.svn”>

    should be

    <Directory ~ “\.svn”>

  3. September 18, 2008 at 2:32 pm

    Not sure about what command you’re talking. If you put custom tags in comments these are removed. Please use &lt; and &gt; instead of < and >.

  4. September 18, 2008 at 2:36 pm

    Actually <Directory ~”\.svn”> will work only on Windows, but <Directory ~”/.svn”> will work on both Windows and Unix.

  5. Anonymous
    February 9, 2012 at 2:41 am

    Use svn export instead of svn update; it avoids the .svn directory issue.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: