Bill de hÓra has a great post for setting up Mercurial (Hg) in a shared host environment and specifically TextDrive. The method described by Bill requires an ssh enabled account and unfortunately I don’t. If you do I would recommend using his instructions because they are easier to follow. If you are developing solo then you can use ssh to push changes while anonymous users can pull without any security concerns over http. If you want to do the latter Patrick Mueller explains how.
I will explain how to setup Mercurial in bluehost WITHOUT ssh access and how to use https to avoid sending your password unencrypted over the network.
If you can find a binary package of mercurial this will save you some trouble but in bluehost the python version is 2.3.4 and the machine architecture is x86_64 so it will be quite unlikely to find a binary where you can simply upload and it will work.
So go here to download the latest stable snapshot of mercurial. Upload the file to your account in bluehost and save it under /home/yourusername/local/. Extract the tar.gz and rename the extracted folder from mercurial-revision to just mercurial.
Now we will use a perl cgi script to compile the mercurial with python 2.3.4 (I am not sure what the rational of bluehost is to uses this ancient version but anyway).
Create the perl script with the following code.
#!/usr/bin/perl
print "Content-type: text/plain";
system("cd /home/yourusername/local/mercurial/;
make local; ./hg debuginstall");
Remeber to replace “yourusersname” with your actual user name. Save the script compile.cgi and upload it using bluehost’s File Manager Interface (FMI) in the cgi-bin directory. (Remeber that the FMI truncates /home/yourusername and the folder /home/yourusername/local/mercurial will shown in FMI as /local/mercurial). Change the file’s permissions to 755 and point your browser to http://www.yourdomain.com/cgi-bin/compile.cgi.
This will hopefully compile mercurial for you. Check the output for any error messages. Once it is done delete the script from the server or change its permissions to 000.
Now using the FMI again; create the following two folders
/public_html/hg /public_html/hg/repos
Copy the hgwebdir.cgi from /local/mercurial to /public_html/hg andopen hgwebdir.cgi to uncomment the 6th and edit the 7th line. It should look like this
import sys sys.path.insert(0, "/home/youusername/local/mercurial")
Create a new file in /public_html/hg called hgweb.config with the following
[collections] /home/yourusername/public_html/hg/repos = /home/yourusername/public_html/hg/repos [web] allowpull=true
Create an .htaccess file in the same directory with the following.
Options +ExecCGI
RewriteEngine On
RewriteBase /~yourusername/hg
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
AuthUserFile /home/yourusername/etc/hg-basic-auth
AuthName "HG Repositories"
AuthType Basic
Require valid-user
Switch to your home workstation to create a password file with the following command and then upload it with the FMI in /etc/.
htpasswd -s -c hg-basic-auth myuser1 htpasswd -s hg-basic-auth myuser2
If you navigate to https://www.yourdomain.com/~yourusername/hg you should see the nice interface of mercurial.
It is time to finally create a ouR repositories using the same hack we used to compile mercurial. The cgi script this time contains the following.
#!/usr/bin/perl
print "Content-type: text/htmlnn";
system("cd /home/yourusername/public_html/hg/repos/;
/home/yourusername/local/mercurial/hg init projectA");
system("cd /home/yourusername/public_html/hg/repos/;
/home/yourusername/local/mercurial/hg init projectB");
Point your browser to the scripts URL and you are almost set. You can pull a repository with hg pull https://www.yourdomain.com/~yourusername/hg/projectA
However you can not push, because the allow_push user list is empty. To solve the problem you will have to create the hgrc file in the projects directory (.hg/hgrc) (i.e. /home/yoursuername/public_html/hg/repos/projectA/.hg/hgrc. A sample is shown below:
[web] contact= Projects contact e-mail description= Project description allow_push= myuser1, myuser2 allow_archive = bz2 gz zip
Finally you can push and pull over https but I would recommend to provide the http URL to anonymous users since https increases the load on bluehost’s server. The problem I have at the moment and I will keep you updated if I find the solution (please let me know if you do too) is that when I try to push a large repository, the push fails with the following error
searching for changes abort: error: Broken pipe
The problem seems to be that the repository is too big and the push operation uses a lot of swap before the transaction completes and bluehost kills the process. A solution might be to push a few revisions at a time. But I have not figure this out yet.
Enjoy!

9 responses so far ↓
1 Mercurial for Adium · Get Latest Mozilla Firefox Browsers // Oct 11, 2007 at 1:07 am
[…] After a bunch of googling around I found that others were having the same problem. Through tests it looked like I could push about 100 revisions at a time via http. This is totally unacceptable, as the repo has about 17,000 revisions, and they all need to go upstream. […]
2 GTTools.com » Blog Archive » Mercurial and Trac on bluehost // Mar 2, 2008 at 1:09 am
[…] Mercurial installation: (amended from http://www.blusb.eu/blog/2007/09/17/mercurial-scm-in-shared-hosts-bluehostcom/ )1.Get mercurial and installcd ~/packageswget http://www.selenic.com/mercurial-stable-snapshot.tar.gztar zxf mercurial-stable-snapshot.tar.gzmv mercurial-stable-snapshot.tar.gz ~/install_files/mv mercurial* mercurialcd mercurialmake local./hg debuginstall […]
3 Moar python on Bluehost | pko.ch // May 9, 2008 at 1:30 am
[…] It all began with me wanting Mergurial (hg for short) on Bluehost. I find mercurial as good as git but with more polish. I just followed some tutorial to get hg on Bluehost, and it was good. […]
4 FP // Jun 5, 2008 at 6:42 pm
Thanks for this, it worked like a charm, only had one problem which I’ll document below.
It worked right up until I enabled auth at which point “hg push” started giving me 404 errors. It turned out that when Apache generated a 401 response it tried to load a pretty error page called “401.shtml”, since that file didn’t exist, the 401s got turned into 404s. I solved the problem by adding the following line to my .htaccess:
ErrorDocument 401 default
5 SharedSSL Question // Nov 2, 2008 at 11:44 am
Are you using the shared SSL provided by Bluehost, or do you have your own dedicated IP and certificate? I am trying to use the shared SSL e.g. https://secure.bluehost.com/~yourusername/hg
but I get an ‘Internal Error’ following the instructions you posted.
And using regular http (no ’s’), I only get a blank page when I access:
http://www.yourdomain.com/~yourusername/hg
I found that if I change the RewriteBase from:
RewriteBase /~yourusername/hg
to:
RewriteBase /hg
I can then correctly access my repo (not blank) under non-SSL via:
http://www.yourdomain.com/~yourusername/hg
and also
http://www.yourdomain.com/hg
I found the ~yourusername in the path unnecessary.
However, if I try using the shared SSL path:
https://secure.bluehost.com/~yourusername/hg
I get a ‘404 Not Found’ error.
Do you have any suggestions on how I can fix this so it works under the shared SSL?
Thanks
6 SharedSSL Question // Nov 5, 2008 at 6:47 pm
Are you using the bluehost shared ssl or do you have a dedicated IP with certificate. I can’t get this to work under the shared ssl.
7 P.S. // Nov 5, 2008 at 9:27 pm
P.S. I posted a longer message describing my shared SSL problems in more detail, but the spam guard trapped it. Can you check your box?
8 Christos // Nov 6, 2008 at 9:12 am
Hi there,
The spam plugin filtered your comment as spam because there were too many urls I believe and I had to manually exclude it from the spam trap.
Regarding your question I am using the shared ssl certificate with the following .htaccess
SSLOptions +StrictRequire
SSLRequireSSL
ErrorDocument 403 https://www.domain.com/hg/
RewriteEngine On
RewriteBase /~username/hg
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
Options +ExecCGI
AuthUserFile /home/username/etc/basic-auth
AuthName "HG Repos"
AuthType Basic
Require valid-user
Then when I use http://www.domain.com/hg I am getting redirected to https://www.domain.com/~username/hg/. I put my username/password and I can see the repos all right.
The ~username in the path is not unnecessary if you are accessing the repos over SSL, but it is when it is accessed over http. This is because the default virtual host apache configuration for https is shared for all the users on that box.
What I should note is that your username is not the same as what you put on bluehost’s page to login. If your domain is something.com then your username is the first 8 characters of your domain. i.e. “somethin”. In other words, the username that you use to ssh to the box. I hope that helps.
Cheers,
Christos
9 Got Shared SSL working // Nov 6, 2008 at 11:16 pm
Thank you for the response. I finally got it working. I did not know you were allowed to use your own domain name for shared SSL if you use ~username. I thought it was required you go through https://secure.bluehost.com
Also, I was using a symlink for my hg directory in my public_html directory which is a something I picked up from a different tutorial. The symlink was causing a failure under https but not http so I didn’t realize that would be a problem until I tried changing that.
The redirect you listed from http to https was also handy, though I had to use https://www.domain.com/~username/hg/
to get it to work for me.
Thank you again
Leave a Comment