Posts Tagged ‘x86’
How to Install the Latest Version of Mercurial Web Repository on Windows 2008 Server R2
It’s a super pain to install HG on Windows 2008 Server R2. This post is based on Firegarden’s article and has additional information from other resources.
Prerequisites
- Windows 2008 Server R2
- The latest version of Python: 2.7.3 (at the moment of writing)
- The latest version of PyWin32: Build 217 (at the moment of writing)
- The latest version of Mercurial: 2.2.2 (at the moment of writing)
Setup Process
Please note that if your choice of Python has to be consistent. In other words, if you choose Python of x86 version, all other applications have to be x86 version; if you choose Python of x64 version, all other applications have to be x64 version; otherwise, this will not be working for your system.
1. Installing Python.
As Mercurial doesn’t support Python 3.x, the latest version of Python we can use is 2.7.x.
- Go to the Python download page. http://www.python.org/download/releases
- Download the latest 2.7.x version of Python. Choose the platform carefully, if to be x86 or x64.
- Install Python downloaded. Make sure that the installation must be conducted by an administrator permission. During the installation process, let the installer set the default installation directory, which will be
C:\Python2x
. - Add the Python path to the system environment path.
- Open “
Control Panel
” > “System and Security
” > “System
” > “Advanced System Settings
“ - Click “
Environment Variables...
” and find the “Path
” variable under “System variables
” section. - Append “
;C:\Python2x;
” to the “Path
” value. Make sure that the path value is delimited by semi-colons. - Open a command prompt and type “
python
” at any directory and you will get into the python console. PressCTRL+Z
to exit from the console. - If you can’t run the “
python
” command on the command prompt, check the step4.3
again. If the path has been correctly set, your server might need to reboot.
- Open “
2. Installing PyWin32
Again, your choice of platform has to be consistant; if you have installed Python of x86 version, this also has to be x86 version; if you have installed Python of x64 version, this also has to be x64 version.
- Go to the Python for Windows Extensions download page. http://sourceforge.net/projects/pywin32/files/pywin32
- Go to the latest build and download an appropriate one corresponding to your Python version and platform. The filename looks like “pywin32-xxx.win32-py2.7.exe”
- Install the PyWin32 downloaded. Make sure that the installation must be conducted by an administrator permission.
- In case of error you might face at the end of the installation process. The message will look like:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderrThis is because of your administrator permission. For workaround of this: http://sourceforge.net/mailarchive/message.php?msg_id=29300152
- Click “
Start Menu
” > Right click on “Computer
” > Click “Manage
“. - Go to “
System Tools
” > “Local Users and Groups
” > “Users
“ - Create a new account named “
Admin
” and assign it to the “Administrators
” group. - Open a command prompt as an administrator and type
runas /user:Admin pywin32-xxx.win32-py2.7.exe
and type password you set previously.
- If you get an error “
Access is denied
“, close the command prompt and open it again as an administrator.
- Click “
3. Building and Installing Mercurial from the Source Code.
As the latest version of Mercurial installer (2.2.2 at the moment of writing) is built with Python 2.6.6, the installer will not be running on our server. So, we need to build the source with Python that we have installed into our system.
- Go to the Mercurial download page. http://mercurial.selenic.com/downloads
- Download the source code and unzip it. We assume that the unzipped directory is “
C:\hg-source
“. - Open a command prompte as an administrator and move to the unzipped directory.
- Run the following command to build Mercurial
python setup.py --pure build_py -c -d . build_ext -i build_mo --force
Even if you meet a warning like “
warning: hgbuildmo: could not find msgfmt executable, no translations will be built
“, just ignore it. - Run the following command to install Mercurial
python setup.py --pure install --force
Mercurial will have been installed at “
C:\Python2x\Lib\site-packages\mercurial
“ - In order to execute to “
hg
” command at anywhere, try the followings:- Copy “
c:\python2x\scripts\hg.bat
” to “c:\python2x
“ - Open
hg.bat
and modify the line
"%~dp0..\python" "%~dp0hg" %*
to
"%~dp0python" "%~dp0\scripts\hg" %*
- Copy “
4. Installing ISAPI-WSGI Module
For better performance, we need to install ISAPI-WSGI module to build a DLL file.
- Go to the ISAPI-WSGI download page. http://code.google.com/p/isapi-wsgi/downloads/list
- Download the latest version of the source code. The precompiled version will not work for our setup.
- Unzip it. We assume that the unzipped directory is “
C:\isapi-wsgi-source
“. - Run the following command to compile the source
python setup.py install
5. Seting up IIS for the Mercurial Web Repository
As IIS doesn’t recognise Python and Hg natively, we need to setup IIS manually.
- Open IIS Manager.
- Create an application pool called “
Mercurial
” with the following configurations:- Set “
.NET Framework Version
” to “No Managed Code
“ - Set “
Enable 32-Bit Applications
” to “True
“, only if you have installed x86 version of Python.
- Set “
- Create a website on IIS for the web repository. We assume that the directory is “
C:\inetpub\hg
” and its URL is “hg.myserver.com
“. This has to point the application pool “Mercurial
“. - Copy the “
hgwebdir_wsgi.py
” file from the Mercurial source code downloaded to “C:\inetpub\hg
“. It is located in “C:\hg-source\contrib\win32
“. - Open the “
hgwebdir_wsgi.py
“, find and edit the parameters below:
hgweb_config = r'c:\inetpub\hg\hgweb.config'
path_prefix = 0
- Create a new “
hgweb.config
” file in “C:\inetpub\hg
” and place the following into it.
[paths]
/ = c:\Repositories\*
- Open a command prompt as an administrator and move to the directory “
C:\inetpub\hg
“. - Run the following command to build the ISAPI-WSGI library.
python hgwebdir_wsgi.py
- Open Handler Mappings and click “
Add Wildcard Script Map...
” with followings:- Set “
Executable
” to “c:\inutpub\hg\_hgwebdir_wsgi.dll
” that has been created from the step5.8
. - Set “
Name
” to “Mercurial-ISAPI
“. - If you are asked to allow the ISAPI extension, click “
YES
“.
- Set “
So far, if everything is done smoothly, you can browse the web repository by typing the URL “http://mg.myserver.com
” into your brower’s lcation bar.
This is optional. If you want to tie basic authentication function to the web repository, try the following steps.
6. Setting up Basic Authentication of IIS onto the Web Repository
- Create users and a user group.
- Click “
Start Menu
” > Right click on “Computer
” > Click “Manage
“. - Go to “
System Tools
” > “Local Users and Groups
” > “User Groups
“ - Create a user group, named “
Mercurial Users
“ - Go to “
System Tools
” > “Local Users and Groups
” > “Users
“ - Create as many users as you want and assign the users to the “
Mercurial Users
” group.
- Click “
- Set the permission for the “
Mercurial Users
” group to only allow the access to “C:\inetpub\hg
“. - Create a self-signed certificate and bind the
HTTPS
protocol with “hg.myserver.com
“.
Once everything is done, type “https://hg.myserver.com
” and you will be asked to login to the site.
It would be great if you guys who are reading this article share your experiences regardless of success or failure.