Posted by: Josh | November 10, 2009

Setting up Mercurial on a shared server with FTP

Mercurial logo.png

This guide assumes you want to set up your own private Mercurial repositories, but want to do so on a server where:

  • you have no SSH or shell access, just an FTP connection/file manager 
  • it has Python 2.4 or greater already installed
  • is a Linux host (although a Windows host should work similarly with this procedure)

Previous guides I’ve come across on the web here and here require you to build Mercurial from source, which might not work depending on how strict your host is at giving you access to programs like the GCC compiler. Our solution here will be to package our own pre-compiled Mercurial binary.

A simpler installation technique is now available! Click here for details.
A new version of Mercurial has been released! Click here for details.


Step 1. Finding out a bit about your host. We’ll need to find out if they run 64-bit processors (there’s a good chance they do), and the version of Python they run. If we don’t know this info, we can assume its 64-bit and Python 2.4, and correct ourselves later.

Step 2. Re-packaging the binary.

Just download the appropriate archive below. For further information on how I arrived at creating these packages, read the rest of this step.

For Python 2.4 | For Python 2.5

These binaries were built from source independently for each version of Python. Inside is already a copy of hgwebdir.cgi, which you will need for the next step.

To compile: For a Debian compilation environment, you’ll need the packages (Python 2.4 for example) python2.4, python2.4-dev, gcc, build-essential, make, in addition to the Mercurial source. You may also need to modify Makefile with PYTHON=python2.4, modify hg with #!/usr/bin/env python2.4 and execute the final install script with Python:
make local
./hg debuginstall

Step 3. Configuring hgwebdir.cgi. The cgi script has to be made aware of the Mercurial files we plan to upload. Open it up in a text editor, and on lines 6, 7, 13, 14, remove the hashes. Also change /path/to/python/lib with your own path. Mine was:

import sys
sys.path.insert(0, "/home/joshjcarrier/python/mercurial")

import cgitb

Step 4. Uploading the binary and hgwebdir.cgi. Now that we have the binaries, we need to upload them – I put mine at /home/joshjcarrier/python, so the complete path is /home/joshjcarrier/python/mercurial . You’ll also now need to upload the script which will act as the web front-end: hgwebdir.cgi, which can be extracted from Mercurial source or the binaries in step 2. Since my host requires .cgi scripts to be run from cgi-bin, I placed the .cgi in /home/joshjcarrier/public_html/hg/cgi-bin . You’ll also need to change the .cgi’s permissions to 755 – if your FTP client doesn’t support that, see if there’s a web-based file manager that your host provides.

At this point, you should be able to load Mercurial from your web browser. It should be similar to

If you see the Mercurial repositories page, then success! If you see an error about a missing, then try step 2 again but for a different version of Python.

Step 5. Creating a repository. I suppose you could write a fancy script to help facilitate this, but I’m going to keep this as simple as possible – just upload an existing Mercurial repository, with the root of the repository folder in the same directory as hgwebdir.cgi.

Step 6. UI tweaks and registering a repository listing.

In the same directory as hgwebdir.cgi, you can create a hgweb.config file, and with it you can change the web UI template:

style = coal
baseurl =
/home/joshjcarrier/public_html/hg/cgi-bin/yourhgrepo = your hg repo  

Other styles nice include “gitweb” and “paper”. Since my /public_html/hg acts as a sub-domain, I have set my baseurl = <blank>. If you haven’t set this up that way, you might specify “hg” or not include it at all.

Step 8. Permissions and URL clean up.

Since I’ve set this up as a HTTP connection, we’ll need to allow push without SSL. In addition, we can provide information to be displayed on the directory listing.

In your hg repo folder, navigate to .hg/ and edit the hgrc file, adding something similar to the following:


default = http://yourwebsiteaddress/hg/yourreponame


contact = Josh Carrier

description = Hello world

push_ssl = false

allow_archive = gz zip bz2

allow_push = joshjcarrier

allowpull = true

allow_read = *

More configuration options are listed at Selenic.

Now for authentication, first password protect your entire repository directory. Most web hosts run cPanel or an equivalent, and our goal will be to use the output for our final step. The users you create here will be Mercurial user accounts. You might consider creating a guest account to be used for read-only access. On password-protecting my /hg directory, a .htaccess file is generated. Open it up and look for the particular line:

AuthUserFile "/home/joshjcarrier/.htpasswds/public_html/hg/passwd"

Now you’re ready to finish authentication. Overwrite the .htaccess file in the /hg directory with something like this.

AuthName "Hg Repository. Read-only=guest/guest"
AuthUserFile “/home/joshjca1/.htpasswds/public_html/”
AuthType Basic
require valid-user

DirectoryIndex cgi-bin/hgwebdir.cgi
<IfModule mod_rewrite.c>
Options +ExecCGI
RewriteEngine On
RewriteRule ^$ cgi-bin/hgwebdir.cgi  [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) cgi-bin/hgwebdir.cgi/$1  [QSA,L]


And if all is well, you now have access at http://yourwebsiteaddress/hg/ for the directory listings and you can specify http://yourwebsiteaddress/hg/yourreponame for push/pull.

Tip 1: for some reason, I couldn’t authenticate if my password contained certain special characters, so if you can’t authenticate right away, try dumb-ing down your password complexity… any input on why this is so would be great.

Tip 2: make sure the repository is exactly as listed on the directory. Easiest way is to copy the link URL under the “Name” column. This includes escape characters, like %20.

image image

And the implementation is available at (user=guest,pass=guest).

A simpler installation technique is now available! Click here for details.
A new version of Mercurial has been released! Click here for details.


  1. Hi Josh,

    Nice tutorial !

    I’ve followed your instructions, and I get a traceback with the following error : /my/path/cgi-bin/mercurial/ cannot open shared object file: No such file or directory

    From what I’ve found after searching on the web, this error is probably due to the fact that my host is 32-bit, not 64-bit.

    Can you give a little more detailed instructions on how I can compile mercurial for 32-bit, knowing that I’m on a windows machine ? Or maybe do you know a place where I can download the precompiled binary ? Thanks !

  2. Update : I’ve extracted the 32-bit precompiled version of from the mercurial debian package, and now I’m struck with the error ImportError: /lib/tls/ version `GLIBC_2.4′ not found (required by /my/path/cgi-bin/mercurial/…

  3. @Greg sorry for the very long delay. That’s probably because the Mercurial compilations I’ve provided are for x86_64/64bit server architectures. I just finished classes, so once I build a couple VMs, expect the latest Mercurial builds up, this time in more flavors 😀

    To do this, all I get the appropriate architecture of Debian and the right version of Python and run that compilation step listed above.

  4. […] my previous guide, but use this file in place of the one […]

  5. […] Mercurial installed to /home/jcarrier/public_html/hg Hereby refered to as ~/hg (links to my previous Hg shared host install guide) […]

  6. The missing file is locate in mercurial/pure folder, just copy it directory up.
    Works fine:)

  7. Down load And Perform Minecraft My own These days And you’ll Be a Fan right away

    An advanced pc and also gaming lover then minecraft my very own is a thing make an attempt your hands out there. At first written in Java by creator Markus “Level” Persson, minecraft is currently readily designed for Personal computer as well as Google android os. This kind of will be the popularity of the game that you’ll
    be absolutely addicted in no time. Hrs may pass and you may not understand that you’ve already recently been recently playing this sandbox online video sport. Minecraft downloading are actually intended for just about almost most – Home house glass microsoft windows 7, Mac pc and Linux.

  8. Thanks for a marvelous posting! I actually enjoyed reading it, you
    can be a great author.I will remember to bookmark your blog and
    will often come back very soon. I want to encourage one to
    continue your great job, have a nice day!
    My spouse and I absolutely love your blog and find many of your post’s to be exactly what I’m looking for.
    Does one offer guest writers to write content to suit your needs?
    I wouldn’t mind writing a post or elaborating on a number of the subjects you write with regards to here. Again, awesome website!
    My spouse and I stumbled over here by a different website and thought I may as well check things out. I like what I see so i am just following you. Look forward to checking out your web page repeatedly.
    I love what you guys tend to be up too. This type of clever work and reporting! Keep up the very good works guys I’ve included you guys to blogroll.

    Hi there I am so excited I found your blog page, I really found you by
    error, while I was researching on Bing for something else, Anyhow I am here now and would just like to say kudos for a incredible post and a
    all round interesting blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and also included your RSS feeds, so when
    I have time I will be back to read much more, Please do keep up the excellent work.

    Admiring the commitment you put into your site
    and detailed information you provide. It’s nice to come across a blog every once in a while that isn’t the same outdated rehashed information.
    Excellent read! I’ve saved your site and I’m including your RSS feeds to my Google account.

    Hi! I’ve been reading your site for some time now and finally got the courage to go ahead and give you a shout out from Humble Texas! Just wanted to tell you keep up the excellent work!
    I am really enjoying the theme/design of your web site. Do you ever run into any web browser compatibility problems? A handful of my blog visitors have complained about my blog not operating correctly in Explorer but looks great in Chrome. Do you have any ideas to help fix this issue?
    I am curious to find out what blog system you’re using?
    I’m having some minor security problems with my latest blog and I would like to find something more risk-free. Do you have any suggestions?
    Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what
    I had written and say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still
    new to everything. Do you have any suggestions for newbie
    blog writers? I’d genuinely appreciate it.
    Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between
    user friendliness and visual appeal. I must say you have done a amazing job with
    this. Also, the blog loads extremely fast for me on Firefox.

    Superb Blog!
    Do you mind if I quote a couple of your articles as long as I provide
    credit and sources back to your weblog? My blog is in the very same
    niche as yours and my visitors would really benefit from some of the information you
    present here. Please let me know if this alright with
    you. Many thanks!
    Hello would you mind letting me know which hosting company you’re working with? I’ve loaded
    your blog in 3 completely different internet browsers and I must say this
    blog loads a lot quicker then most. Can you suggest a good internet hosting
    provider at a fair price? Cheers, I appreciate
    Great blog you have here but I was wanting to know if you knew of
    any forums that cover the same topics talked about here?
    I’d really like to be a part of community where I can get suggestions from other experienced people that share the same interest. If you have any suggestions, please let me know. Appreciate it!
    Hi! This is my first comment here so I just wanted to give a quick shout out and tell you I really enjoy reading your articles. Can you recommend any other blogs/websites/forums that cover the same subjects? Appreciate it!
    Do you have a spam issue on this blog; I also am a blogger, and I was curious about your situation; many of us have created some nice practices and we are looking to exchange strategies with other folks, please shoot me an email if interested.
    Please let me know if you’re looking for a author for your site.
    You have some really great posts and I think I would be a good asset.
    If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine. Please blast me an email if interested. Thanks!
    Have you ever considered about adding a little bit more than just your articles? I mean, what you say is fundamental and all. Nevertheless think of if you added some great visuals or videos to give your posts more, “pop”! Your content is excellent but with images and clips, this site could certainly be one of the best in its field. Very good blog!
    Cool blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple adjustements would really make my blog jump out. Please let me know where you got your design. Thank you
    Hello would you mind sharing which blog platform you’re using?
    I’m looking to start my own blog soon but I’m having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!
    Hey there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Chrome. I’m not sure if this is a format issue or something to do
    with web browser compatibility but I thought I’d post to let you know. The design and style look great though! Hope you get the issue resolved soon. Cheers
    With havin so much content do you ever run into any problems of plagorism or copyright infringement? My website has a lot of completely unique content I’ve either written myself or
    outsourced but it seems a lot of it is popping it up
    all over the internet without my permission. Do you know any techniques to
    help reduce content from being stolen? I’d definitely appreciate it.
    Have you ever considered writing an e-book or guest authoring on other sites? I have a blog based on the same subjects you discuss and would really like to have you share some stories/information. I know my viewers would enjoy your work. If you are even remotely interested, feel free to send me an e-mail.
    Hi! Someone in my Facebook group shared this site with us so I came to give it a look. I’m definitely
    loving the information. I’m book-marking and will be tweeting this to my followers! Superb blog and brilliant design.
    Wonderful blog! Do you have any helpful hints for aspiring writers? I’m planning to start my
    own blog soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .
    . Any recommendations? Many thanks!
    My coder is trying to persuade me to move to .net from PHP.

    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using
    WordPress on various websites for about a year and am worried about switching to another platform.
    I have heard excellent things about Is there a
    way I can transfer all my wordpress posts into it?
    Any kind of help would be really appreciated!
    Does your site have a contact page? I’m having trouble locating it but, I’d like to send you an email.
    I’ve got some recommendations for your blog you might be interested in hearing. Either way, great website and I look forward to seeing it improve over time.
    It’s a shame you don’t have a donate button! I’d most certainly donate to this superb blog!
    I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Talk soon!
    Greetings from Florida! I’m bored to death at work so I decided to browse your site on my iphone
    during lunch break. I love the info you provide here and can’t wait to take a look when I get home. I’m shocked
    at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyways, great site!
    Hi! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog article or vice-versa? My website addresses a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you’re interested feel free to shoot me an email.
    I look forward to hearing from you! Awesome blog by the way!

    Right now it seems like Movable Type is the best blogging platform out there right now.
    (from what I’ve read) Is that what you are using on your blog?
    Outstanding post but I was wondering if you could write a litte more on this subject? I’d be very thankful if
    you could elaborate a little bit further. Kudos!

    Hey! I know this is somewhat off topic but I was wondering
    if you knew where I could find a captcha plugin for my comment form?

    I’m using the same blog platform as yours and I’m having trouble finding one?

    Thanks a lot!
    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added
    I get three e-mails with the same comment. Is there any way you can remove people from
    that service? Many thanks!
    Hi there! This is my first visit to your blog! We are a collection of volunteers and starting a new initiative
    in a community in the same niche. Your blog provided
    us useful information to work on. You have done a outstanding job!

    Howdy! I know this is somewhat off topic but I was wondering which blog
    platform are you using for this website? I’m getting tired of WordPress because I’ve had problems with hackers and I’m looking at options for another platform. I would be fantastic if you could point me in the direction of a good platform.
    Howdy! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this write-up to him. Pretty sure he will have a good read. Thanks for sharing!
    Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us something informative to read?
    Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
    Today, while I was at work, my sister stole my apple ipad and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!
    I was curious if you ever thought of changing the structure of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or 2 images. Maybe you could space it out better?
    Howdy, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you stop it, any plugin or anything you can suggest? I get so much lately it’s driving
    me crazy so any help is very much appreciated.
    This design is wicked! You definitely know how to keep a reader
    entertained. Between your wit and your videos, I was
    almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
    I really loved what you had to say, and more than that, how you presented it.

    Too cool!
    I’m really enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more pleasant
    for me to come here and visit more often. Did you hire out
    a designer to create your theme? Superb work!
    Hey! I could have sworn I’ve been to this site before but after browsing through some of the post I realized it’s new to
    me. Anyhow, I’m definitely happy I found it and I’ll be book-marking
    and checking back frequently!
    Hi there! Would you mind if I share your blog with
    my zynga group? There’s a lot of folks that I think would really enjoy your content. Please let me know. Thanks
    Hey, I think your blog might be having browser compatibility issues. When I look at your blog in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, terrific blog!
    Wonderful blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there!
    Hello there! This is kind of off topic but I need some help from an established blog.
    Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating my own but I’m not sure where to start. Do you have any tips or suggestions? With thanks
    Hi there! Quick question that’s totally off topic. Do you know
    how to make your site mobile friendly? My site looks weird when browsing from my iphone4.
    I’m trying to find a theme or plugin that might be able to fix this issue. If you have any recommendations, please share. With thanks!
    I’m not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll
    go ahead and bookmark your website to come back in the future.
    Many thanks
    I really like your blog.. very nice colors & theme.

    Did you design this website yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to construct my own blog and would like to know where u got this from. thanks
    Amazing! This blog looks exactly like my old one! It’s on a completely
    different subject but it has pretty much the same layout and design.
    Superb choice of colors!
    Heya just wanted to give you a brief heads up and let you know a
    few of the images aren’t loading correctly. I’m not sure why but I think its a linking issue.
    I’ve tried it in two different web browsers and both show the same outcome.
    Hi there are using WordPress for your site platform? I’m new to the blog world
    but I’m trying to get started and create my own. Do you need any coding expertise to make your own blog? Any help would be greatly appreciated!
    Hey there this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting
    a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience.

    Any help would be greatly appreciated!
    Hi there! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up
    losing several weeks of hard work due to no backup.
    Do you have any methods to prevent hackers?
    Hi there! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new posts.

    Hi! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any suggestions?
    Good day! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m
    not seeing very good gains. If you know of any please share.
    I know this if off topic but I’m looking into starting my own blog and was curious what all is needed to get set up? I’m assuming having a blog like
    yours would cost a pretty penny? I’m not very internet smart so I’m not 100% sure.

    Any recommendations or advice would be greatly appreciated.

    Hmm is anyone else having problems with the images on this blog loading?

    I’m trying to figure out if its a problem on my end or if it’s the
    blog. Any responses would be greatly appreciated.

    I’m not sure why but this blog is loading very slow for me. Is anyone else having this issue or is it a problem on my end? I’ll check
    back later on and see if the problem still exists.
    Hey! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the superb work!
    Wow that was unusual. I just wrote an really long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Regardless, just wanted to say wonderful blog!

  9. Toller Text! Ihre Homepage lädt auch sehr schnell! Welchen Webhosting Anbieter benutzen Sie denn?

  10. If you want a Premium Minecraft Account check out
    this generator. With it you can generate a unique Minecraft Premium
    Account which no one else has! You can Download the Free
    Premium Minecraft Account Generator http://MINECRAFTFREEDL.

    I am extremely impressed with your writing skills and also with
    the layout on your weblog. Is this a paid theme
    or did you customize it yourself? Anyway keep up the excellent quality writing, it’s rare to see a nice blog like this one these days.

  11. Warte gespannt auf neuwertige Beiträge. Kann Ihre Webseite einfach nicht verlassen, ohne noch schnell zu erwähnen, dass ich es toll
    finde, wie sie in Ihrem Blog nützliche Informationen für Ihre Leser zur verfügung stellen.

  12. Hätte da noch einzelne Fragen zu spezifischen Punkten.

    Ich bräuchte einen Experten auf dem Themengebiet, der mir gegen Bezahlung
    die Fragestellungen geklärt.

  13. Weiter so! Ansprechender Text, reichlichen Dank für die
    praktische Darlegung.

  14. Posting yang bagus….

  15. Greetings! I know this is somewhat off topic but I was wondering if you knew where
    I could locate a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m
    having trouble finding one? Thanks a lot!

  16. Because the admin of this website is working, no doubt very rapidly it will be well-known, due to its quality contents.

  17. De Hecho No estoy excesivamente en consonancia con lo que comunicas.

    Creo que el post no se encuentre demasiado documentado.

  18. Me ha gustado mucho la manera como has escrito referente a el asunto.
    ¿Donde podria adquirir mas post acerca dee el asunto?.

    Me apasiona tu web.

  19.  Extraordinario! Absolutamente Toda la texto que has desarrollado me es de ingente asistencia!
    Me Presento ansiando ser capaz interpretar muchos mas.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s


%d bloggers like this: