How to … Publish multiple sites on a single computer with Apache

Unfortunately, when you use Internet Information Server on a Windows XP Professinal computer, it is not possible to have multiple sites with different base-URL’s. The only available base-URL is http://localhost and you must differentiate by folder structure from there on.

Fortunately there is the Apache HTTP Server Project. With this webserver you can have multiple base-URL’s on a single computer.

Here is how you do it:

Getting the necessary files

Install the Apache HTTP server

You can download the software at the website of the project which is here. I downloaded the 2.0.59 release using this link.

Installation on Windows is simple. Just download the binary version which is an installer package and execute it.

Configure for multiple base-URL’s

Configure Windows

I used Windows XP Professional. Go to the operating system installation folder (typically c:/WINDOWS) and navigate further down to system32/drivers/etc

Open the file “hosts” with Notepad and add a line which maps the base-URL you want to the local IP address. This goes like following:

127.0.0.1 mysite

So, at the end my file lookes like this:

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
127.0.0.1 mysite

Configure the Apache HTTP server

In the windows startmenu, navigate to

  • Apache HTTP Server 2.0.59
    • Configure

and choose the “Edit the Apache httpd.conf Configuration File” entry. You will now have Notepad open with the file http.conf.

Navigate to the end of the file where you will see following lines:

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.0/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

Remove the # from the line “#NameVirtualHost *:80”, so you get:

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.0/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

Add following to the end of the file:

<VirtualHost *:80>
   ServerAdmin webmaster@mysite.com
   DocumentRoot “F:\Serge\My Web Sites\folderformysite”
   ServerName mysite
   ErrorLog logs/mysite.error_log
   CustomLog logs/mysite.access_log common
</VirtualHost>

The doumentation of the server mentions that you must remove the # in front of the line with “NameVirtualHost *:80”. Allthough I suggest you do this, it worked for me without doing it.

Setup your website

Make a simple HTML file and place it in the folder you used for your website. In the above example this is the folder “F:\Serge\My Web Sites\folderformysite”. You can name teh file “sample.html”

Open your browser and type following URL:

http://mysite/sample.html&#8221;

If everything went fine you should now see the page you made.

Resources

[1] Apache HTTP Server
[2] The documentation for the <VirtualHost> tag

Updates

6 Januari 2007: original version

How to … Access Subversion from C#

Allthough there are a lot of language bindings available for Subversion, C# is not one of them. A few resources on the internet provide some kind of binding but they are all external to the Subversion project.

With IKVM however, you can compile the Java language binding of the Subversion project to make it accessible using C#.

Here is how you do it:

Getting the necessary files

Install IKVM.NET

You can download IKVM.NET from their website. Just go to the download section and click through to Sourceforge. Select the file with “bin” in its name because that file contains the binaries. Because I used version 0.30.0.0 the file was named ” ikvmbin-0.30.0.0.zip”. You can download it using this link.

After downloading this file, you must unzip it in some folder. This is the folder structure that will result:

ikvm.gif

Install the Subversion java language bindings

For this you must go to the Subversion website and select the “Documents & files” inside the “Project tools” item on the left. Next expand following nodes in the central tree structure:
subversion > Releases > Windows

Then look for a file named svn-win32-(version)_javahl.zip in which (version) is of course the version. I used version 1.3.1 which is not the most recent. You can find it in the “Windows Archive” node.

The file I used had thus the name “svn-win32-1.3.1_javahl.zip”.

Once downloaded you unzip it into a folder of your choice. After this you end up with following folderstructure:

subversionjava.gif

Using the Subversion java language bindings

Compiling the java language bindings for .NET

Copy the complete content of the IKVM.NET “bin” folder to the Subversion language bindings “javahl” folder. Like this all files are in the same folder.

Open a command window in this folder and type following on the commandline:

ikvmc svnjavahl.jar

IKVM.NET will compile the provided jar file and produce a dll with the same name. This dll contains the .NET version of the java classes.

Accessing a Subversion repository from C#

Create a console application in your favourite IDE.

Add references to the following files:

  • IKVM.GNU.Classpath.dll (which comes with IKVM.NET)
  • svnjavahl.dll (which you created by compiling svnjavahl.jzr with IKVM.NET)

Copy the following code in the project you just created:

using System;

using System.Collections.Generic;

 

namespace SubversionTest

{

    class MainClass

    {

        public static void Main(string[] args)

        {

            org.tigris.subversion.javahl.SVNClient svnClient

                = new org.tigris.subversion.javahl.SVNClient();   

 

            // replace the following string with the name of a

            //  subversion repsoitory available to you

            //  example “svn://localhost/MyProject”

            string moduleName = “<yourRepo>”;

 

            // replace the following string with the name of a

            //  folder available on your computer

            //  example “c:/MyProject”

            string destinationFolder = “<yourFolder>”;

            org.tigris.subversion.javahl.Revision revision =

                org.tigris.subversion.javahl.Revision.HEAD;

            bool recurse = true;

 

            svnClient.checkout(moduleName, destinationFolder, revision, recurse);

        }

    }

}

Do not forget to replace the strings with appropriate values for your setup.

Compile the project

Copy following files to the folder containing the build results (typically a subfolder bin\Debug for the debug version or bin\Release for the release version)

  • ikvm-native.dll
  • libsvnjavahl-1.dll

Hit the Run button.
If everything went well your repository shuold be chacked out on your computer.

Resources

[1] IKVM.NET and how to convert a java application to .NET
[2] Subversion and Documents & files
[3] Online documentation for javahl classes can be viewed here

Updates

21 December 2006: original version

How to … Make Subversion ignore files and folders

Excluding files from your repository
Sometimes you may have types of files or folders in your source code tree that you do not want to include in your source code repository. Everyne developing with Visual Studio will immediately know what I mean: VS automatically makes bin and obj subfolders for your project folder in which it puts the buildresults and also creates *.suo files with your personal settings for a solution.

It would be convenient if we could exclude these files from our repository once and for all without having to manually uncheck them each time we update our project. Fortunatly, Subversion allows us to do this. In fact, there are two possibilities for exclusion.

Global exclude

With the global exclude we can exclude a certain type of file of being added to any repository to which a certain client connects. To do this, you must edit the Subversion “config” file which you can find in your local Application Data folder. A typical location for this file is: “C:\Documents and Settings\[username]\Application Data\Subversion”.

When you open this file, look for the section [miscellany]. In this section find a line with global-ignores and remove the “#” signes in front of it (if you haven’t removed them allready). Now add the files signatures you want to ignore.

For example, to ignore the suo files, we would write:


global-ignores = *.suo

Local exclude

The local excludes are made on folders. This means you can tell subversion clients to ignore a specific file, type of file or folder. This is done by setting the svn:ignore property on the target folder with the signature of the file or folder to ignore.

For example, to ignore suo files in the solution’s folder, you would perform following command in the folder of the solution:

[TargetFolder]>svn propset svn:ignore *.suo .


Do not forget the final dot, it means that the target folder is the current folder. With the above command Subversion will ignore all files with extension “suo” in the target folder.

To ignore folders we have a similar syntax. To ignore for eample a folder “bin” in our target folder execute following command:

[TargetFolder]>svn propset svn:ignore bin .


Again, do not forget the final dot, it means that the target folder is the current folder.

To ignore multiple types of files and folders, you must have a newline delimited list of values for the svn propset command. Because this can not be done with the commandline (well, I do not know how to do it anyway), we create a text file with on each line the signature of a file and/or folder to ignore.
For example, we have a textfile with following content:

obj
bin

We save this file in the target folder and name it “ignore.txt”, and then issue the command in the target folder

[TargetFolder]>svn propset svn:ignore -F ignore.txt .


Again, do not forget the final dot, it means that the target folder is the current folder. With the above command all folders with names obj and bin in the target folder will be ignored by Subversion.

Resources

[1] svn:ignore in the Subversion documentation
[2] global-ignores in the Subversion documentation
[3] Scott Sanders :: blog :: Ignore a file in Subversion (svn ignore) (The inspiration for making this a seperate post)
[4] svn ignore property wierdness

Updates

5 December 2006: original version