WebNull

Jan 14 2010

Installing Mercurial hgwebdir.cgi on Windows 2003, Apache2

UPDATE:

Clay Lenhart sent me the following solution to the timeout issue:

cd \inetpub\AdminScripts\
cscript adsutil.vbs GET /W3SVC/CGITimeout
cscript adsutil.vbs SET /W3SVC/CGITimeout 3000

Thank you!

As I posted previously I had installed Mercurial cgi-bin on Windows 2003 and IIS 6. After some promising rounds I decided to use it in production. At least this was my idea.

No matter how many times I tried cloning one of my project (about 40MB)  the hg clone command (over https) always returned an error like this:

transaction abort!
rollback completed
abort: premature EOF reading chunk (got 36750 bytes, expected 131164)

I had no choice but to install Apache2.

Here is my walkthrough.

  1. Download and install Python 2.6.4 to C:\Mercurial\Python
  2. Download and install MiniGW 5.1.6
    • Choose the Download and Install Option.
    • Choose the Current Package Option to Install.
    • For the Components to Install Select the “Minimal” option. Install to C:\Mercurial\MinGW
  3. Add to path “C:\Mercurial\Python\Scripts;C:\Mercurial\Python;C:\Mercurial\MinGW\bin”
  4. Download and unzip Mercurial source to C:\Mercurial\Source
  5. Build Mercurial from command line:
    python setup.py build --force -c mingw32
    python setup.py install --force --skip-build
  6. Create default hgrc from command line type:
    cd %userprofile%
    copy con .hgrc
    [ui]
    username = Firstname Lastname <firstname.lastname@example.net>
    verbose = True
    • CTRL-Z
    • ENTER
  7. hg debuginstall should display “No problems detected”
  8. Download and install Apache2.2 + OpenSSL. Default settings are fine except path where use c:\Mercurial\httpd
  9. Open c:\Mercurial\httpd\conf\http.conf with a text editor.
    Replace
    Listen 80
    with
    Listen 8080
    Replace
    #LoadModule ssl_module modules/mod_ssl.so
    with
    LoadModule ssl_module modules/mod_ssl.so
    Replace
    #Include conf/extra/httpd-ssl.conf
    with
    Include conf/extra/httpd-ssl.conf
  10. Open c:\Mercurial\httpd\conf\extra\httpd-ssl.conf with a text editor.
    Replace
    Listen 443
    with
    Listen 8088
    Replace
    <VirtualHost _default_:443>
    with
    <VirtualHost _default_:8088>
    Replace
    SSLCertificateFile "C:/Mercurial/httpd/conf/server.crt"
    with
    SSLCertificateFile "C:/Mercurial/httpd/conf/localhost.cert"
    *use your domain instead of localhost
    Replace
    SSLCertificateKeyFile "C:/Mercurial/httpd/conf/server.key"
    with
    SSLCertificateKeyFile "C:/Mercurial/httpd/conf/localhost.key"
  11. Open a command prompt and type the following. When asked for common name use te actual domain (localhost in this example)
    cd  c:\Mercurial\httpd\bin
    openssl req -config ../conf/openssl.cnf -new -out localhost.csr -keyout 
    openssl rsa -in localhost.pem -out localhost.key
    openssl x509 -in localhost.csr -out localhost.cert -req -signkey localhost.key -days 365
    copy localhost.cert ..\conf
    copy localhost.key ..\conf
  12. Create a C:\Mercurial\Repositories directory
  13. Copy the hgwebdir.cgi file from the C:\Mercurial\Source to C:\Mercurial\httpd\cgi-bin\
  14. Create hgweb.config in C:\Mercurial\httpd\cgi-bin\
  15. Insert text in hgweb.config
    [paths]

    / = C:\Mercurial\Repositories\
  16. Create a test repository
    cd C:\Mercurial\Repositories
    md test
    cd test
    hg init
  17. Enable push for this repository
    • create hgrc file with notepad in cd C:\Mercurial\Repositories\test.hg
    • insert the following text
    [web]

    allow_push = *

  18. Open c:\Mercurial\httpd\cgi-bin\hgwebdir.cgi with a text editor able to handle unix style now line breaks. Replace
    #!/usr/bin/env python
    with
    #!C:/Mercurial/Python/python.exe
    Replace
    #sys.path.insert(0, "/path/to/python/lib")
    with
    #sys.path.insert(0, "C:/Mercurial/Python/Lib")
  19. This is an optional step. If you don’t want authentication skip to the next step.
    Open c:\Mercurial\httpd\conf\http.conf with a text editor
    Replace
    <Directory "C:/Mercurial/httpd/cgi-bin">

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

    </Directory>
    with
    <Directory "C:/Mercurial/httpd/cgi-bin">

    Order allow,deny

    Allow from all

    AuthName "frantic"

    AuthType Basic

    Require valid-user

    AuthUserFile "C:/mercurial/htpasswd"

    </Directory>

    Open a command prompt and type the following
    cd C:\Mercurial\httpd\bin
    htpasswd -c htpasswd YourUserName
    copy htpasswd c:\mercurial
  20. Test your newly configured website: eg. http://localhost:8088/cgi-bin/hgwebdir.cgi
Page 1 of 1