Guide: Installing Mercurial server on Red Hat Enterprise Linux
Disclaimer: The credit for this guide goes to the guys who figured out all the difficult parts: Jake Murzy and Bill Carroll for solving Red Hat related issues and Declan Sciolla-Lynch for showing how to integrate Apache and Domino LDAP. I only brought it all together in one blog post.
If you are using Mercurial as a source control system, you probably wish you had a central repository with which all of the developers could sync. You might use one of the public domain servers, but chances are that you would want your own server that is completely under your control. Declan has showed how to install and configure Mercurial on Ubuntu server. But, what if you use Red Hat or some of its clones, like CentOS or Scientific Linux? Mercurial, being built for Debian, won't install on a Red Hat-based system and. But, don't despair - it is actually quite easy to install it on Red Hat. Just follow the steps. This guide is tested using Red Hat, CentOS and Scientific Linux, both versions 5.x and 6.x, but only 32-bit. The rest is based on CentOS 6, but you can choose whicever you prefer, as there is no difference between them for our purpose. I won't go into installation of the server itself. It has become straight forward, even for Linux beginners. When you install, it is enough to choose Basic Server as a the installation type. This will install basic things, without much overhead. If you wish, choose Gnome / KDE desktop and X Window System (and anything else for that matter), so that you can have GUI. You won't need GUI to install Mercurial, though. Even though it is not advisable, I have logged in as root and performed all of the following tasks. I suggest that you update complete system before proceeding, simply issue the following in terminal:
# yum update OK, now it's time to do some business. First let's install Apache server and confirm version # yum install httpd # httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jul 7 2011 11:27:40 Now, the Python should already be installed. Let's check the version:
# python -V
Python 2.6.5 You can have several Python environments installed on the server (something like JRE), depending on what different applications demand. Mercurial works fine with this version and we won't be running any conflicting applications, so we'll use this system installation. We'll be building Mercurial and mod_wsgi from source, so we need some tools and libraries.
Make should already be installed on the system, let's check:
# make -v
GNU Make 3.81 If not, install by running
# yum install make Now, install gcc
# yum install gcc Install rpm-build
# yum install rpm-build Install the libraries:
# yum install httpd-devel
# yum install python-devel Now cd to a temporary / download directory. I usually use /tmp for this:
# cd /tmp Download mod_wsgi source:
# wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz Unpack:
# tar xvfz mod_wsgi-3.3.tar.gz Build the module:
# cd mod_wsgi-3.3
# ./configure
# make
(You will see some warnings here, but it is OK.)
# make install This will install the library mod_wsgi.so in /etc/httpd/modules. Now we need to do the similar thing with docutils. # cd /tmp
# wget http://prdownloads.sourceforge.net/docutils/docutils-0.8.1.tar.gz?download
# tar xvfz docutils-0.8.1.tar.gz
# cd docutils-0.8.1
# ./setup.py install This will install docutils in /usr/lib/python2.6/site-packages/docutils. We can now finally start installing Mercurial. We are going to make an rpm file, which you can keep and use to install Mercurial on other servers. # cd /tmp
# wget http://mercurial.selenic.com/release/mercurial-2.0.2.tar.gz
# tar xvfz mercurial-2.0.2.tar.gz Now you need to edit the file mercurial-2.0.2/contrib/mercurial.spec. Open this file in text editor and search for the line starting with "Version:" (near the top of the file) and replace "snapshot" with "2.0.2".
Then, go several lines down until you come to line starting with "BuildRequires:". Remove "python-docutils >= 0.5" from the list, so that the line looks like this:
BuildRequires: python >= 2.4, python-devel, make, gcc, gettext
(For some reason, rpm-build does not see the docutils that we built in previous step, so we need to remove it as a prerequisite. But, it is there and Mercurial will use it.) If you are feeling geeky, you can do the same by issuing the following in the terminal:
# cd /tmp/mercurial-2.0.2/contrib/
# sed -i -e's/snapshot/2.0.2/' mercurial.spec
# sed -i -e's/, python-docutils >= 0.5//' mercurial.spec Piece of cake :-) Now, we need to repackage everything:
# tar cvf - mercurial-2.0.2 | gzip > mercurial-2.0.2.tar.gz Create the rpm:
# rpmbuild -tb mercurial-2.0.2.tar.gz If everything goes well, you'll see
+ exit 0
as the last line. We have our rpm now, we are almost there. The created rpm could be in a few places. If you were doing everything like me and as the root, then yours should be in /root/rpmbuild/RPMS/i386/:
# ls /root/rpmbuild/RPMS/i386/
mercurial-2.0.2-0.i386.rpm Now we can install and check version:
# rpm -ivh /root/rpmbuild/RPMS/i386/mercurial-2.0.2-0.i386.rpm
Preparing... ########################################### [100%]
1:mercurial ########################################### [100%]
[root@code1 tmp]# hg --version
Mercurial Distributed SCM (version 2.0.2)
And that was installation done. Now it's time to configure it.
Open /etc/httpd/conf/httpd.conf in a text editor (you might want to make a copy first). First, set these values (I show you my values, you should enter yours):
ServerAdmin admin@cs-computing.com
ServerName code1.cs-computing.com:80
NameVirtualHost *:80 (You will need to uncomment ServerName and NameVirtualHost) Find section with number of LoadModule lines. Add the following:
LoadModule wsgi_module modules/mod_wsgi.so Find section with AddHandler lines. Add the following:
AddHandler wsgi-script .wsgi (In case that you installed specific version of Python to be used with Mercurial, add something like this as well:
WSGIPythonHome /usr/lib/python2.7
) Now, scroll all the way to the end, and let's add following VirtualHosts: First, an empty declaration, to trap requests with unrecognized host name:
<VirtualHost *:80>
</VirtualHost> Then, add a declaration for our Mercurial server (in my environment, the server's host name is code1.cs-computing.com. However, I also created a DNS Alias hg.cs-computing.com that points to code1.cs-computing.com and which I use to access the Mercurial server):
<VirtualHost *:80>
ServerName hg.cs-computing.com
ErrorLog /var/log/httpd/hg.cs-computing.com-error_log
CustomLog /var/log/httpd/hg.cs-computing.com-access_log common
WSGIScriptAlias / /var/www/vhosts/hg.cs-computing.com/cgi-bin/hgweb.wsgi
</VirtualHost> We need to create directories to hold our Mercurial repositories (repos) and configurations (cgi-bin):
# cd /var/www/
# mkdir -p vhosts/hg.cs-computing.com/cgi-bin
# mkdir -p vhosts/hg.cs-computing.com/repos Copy file hgweb.wsgi from unpacked Mercurial source package to the cgi-bin directory:
# cp /tmp/mercurial-2.0.2/contrib/hgweb.wsgi /var/www/vhosts/hg.cs-computing.com/cgi-bin/ Open hgweb.wsgi in text editor and edit line starting with config to read:
config = "/var/www/vhosts/hg.cs-computing.com/cgi-bin/hgweb.config" Create new file called hgweb.config in /var/www/vhosts/hg.cs-computing.com/cgi-bin:
# touch vhosts/hg.cs-computing.com/cgi-bin/hgweb.config Open this file in text editor and add the following:
[paths]
/ = /var/www/vhosts/hg.cs-computing.com/repos/**
[web]
allow_push = *
push_ssl = false
We are nearing the end, hold on! :-) It' time to create a test repo.
# cd /var/www/vhosts/hg.cs-computing.com/repos/
# hg init hgtest We need to change owner and permissions (since we are running this as root):
# chgrp -R apache hgtest/
# chmod -R g+rwx hgtest/ Start the Apache:
# service httpd start
Starting httpd: [ OK ] Open your browser and enter the address that you used for your Mercurial virtual host (hg.cs-computing.com in my case). You should see the Mercurial repos:
So, now you have working Mercurial server. We only need to add some sort of authentication. Let's use Domino LDAP, just like Declan did in his series. There is no special steps required to configure Domino LDAP, it should just work. Open /etc/httpd/conf/httpd.conf in a text editor and scroll down to the definition of Mercurial virtual host. Add directory specification to the VirtualHost specification, so that it looks like this one:
<VirtualHost *:80>
ServerName hg.cs-computing.com
ErrorLog /var/log/httpd/hg.cs-computing.com-error_log
CustomLog /var/log/httpd/hg.cs-computing.com-access_log common
WSGIScriptAlias / /var/www/vhosts/hg.cs-computing.com/cgi-bin/hgweb.wsgi
<Directory "/var/www/vhosts/hg.cs-computing.com/">
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthName "Mercurial Server: Login with your Domino credentials"
AuthLDAPURL "ldap://ldap.cs-computing.com:389/O=Computing?CN"
Require valid-user
</Directory>
</VirtualHost> Some explanations:
AuthType Basic says how to send password. Basic means in clear text, so this is not the most secure environment, but enough for our testing.
AuthBasicProvider ldap says Apache to use LDAP for authorization.
AuthzLDAPAuthoritative on means that LDAP is only way to authorize with this server. If we had some other mean of authentication (e.g. Apache built-in users), that we could set this to off and the Apache would first try with LDAP and if it fails continue with other options. (BTW, this is default).
AuthName "Mercurial Server: Login with your Domino credentials" - this will be shown on login window.
AuthLDAPURL "ldap://ldap.cs-computing.com:389/O=Computing?CN" - URL to your LDAP server. In this case we are looking from the top of the directory tree (O=Computing) and are using common name (CN) to authenticate. The other parameters that Declan has in his example are all defaults, so I didn't use them.
Require valid-user - means that any user that successfully authenticates will have access. Save the file and restart the Apache:
# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ] Now try to log in. The Apache should ask for user name and password. Log in as you would in Notes client or iNotes. And that's all! We now have Mercurial server running on a Red Hat server, with LDAP authentication, waiting for XPages stuff :-) Let me know if something is not clear or you encounter problems. I'll do my best to help you.


