vim ~/.bash_profile
export LD_LIBRARY_PATH=”$HOME/packages/lib:$LD_LIBRARY_PATH”
export PYTHONPATH=”$HOME/packages/lib/python2.3/site-packages:$PYTHONPATH”
export PATH=”$HOME/packages/bin:$HOME/bin:$PATH”
source ~/.bash_profile
vim ~/.bashrc
PATH=$PATH:$HOME/bin:$HOME/packages/mercurial
source ~/.bashrc

Create folders (Please note, from now on my assumption is that your web directory is located at $HOME/public_html, please change the related parts if your configuration is different):

cd
mkdir install_files
mkdir packages
mkdir ~/public_html/hg
mkdir ~/public_html/hg/repos

Get Mercurial and install:

cd ~/packages
wget http://selenic.com/repo/hg-stable/archive/tip.tar.gz
tar zxf tip.tar.gz
mv tip.tar.gz ~/install_files/
mv Mercurial* mercurial
cd mercurial
#dont' forget to change the username
echo -e "[ui]\nusername=YOURUSERNAME <YOUREMAIL@WEB.com>" > ~/.hgrc
make local
./hg debuginstall

Running the last command should not show any problems and you would see :

Checking encoding (UTF-8)...
Checking installed modules (~/packages/mercurial/mercurial)...
Checking templates...
Checking commit editor...
Checking username...
No problems detected

In order to be able to push, mercurial provides a cgi script(hgweb.cgi) to handle push commands (http://mercurial.selenic.com/wiki/PublishingRepositories#hgweb). In addition, there is a need for apache authentication module to perform the authentication tasks and manage accesses to our repository. Before, we can use the repository we need to copy the hgweb.cgi script to our web directory, and customize it afterwards:

sed 's|#import sys|import sys|g;s|/path/to/python/lib|'$HOME'/packages/mercurial|g;s|/path/to/repo/or/config|'$HOME'/public_html/hg/hgweb.config|g' ~/packages/mercurial/hgweb.cgi > $HOME/public_html/hg/hgweb.cgi
chmod 755 ~/public_html/hg/hgweb.cgi

Create hgweb.config file. You can use *[collections] *instead of [paths] here, it depends on your personal taste. Here suggested to use paths instead of collection. So if you prefer to use [collections] instead, do not forget to remove all the lines related to hgweb.config when you initialize your repository:

echo [web] > ~/public_html/hg/hgweb.config
echo allowpull=true >> ~/public_html/hg/hgweb.config
echo [paths] >> ~/public_html/hg/hgweb.config

Create .htaccess file:

echo 'Options +ExecCGI' > ~/public_html/hg/.htaccess
echo 'RewriteEngine On' >> ~/public_html/hg/.htaccess
echo 'RewriteBase /hg' >> ~/public_html/hg/.htaccess
echo 'RewriteRule ^$ hgweb.cgi [L]' >> ~/public_html/hg/.htaccess
echo 'RewriteCond %{REQUEST_FILENAME} !-f' >> ~/public_html/hg/.htaccess
echo 'RewriteCond %{REQUEST_FILENAME} !-d' >> ~/public_html/hg/.htaccess
echo 'RewriteRule (.*) hgweb.cgi/$1 [QSA,L]' >> ~/public_html/hg/.htaccess
echo 'AuthUserFile /home/'$USER'/etc/hg-basic-auth' >> ~/public_html/hg/.htaccess
echo 'AuthName "HG Repositories"' >> ~/public_html/hg/.htaccess
echo 'AuthType Basic' >> ~/public_html/hg/.htaccess
echo 'Require valid-user' >> ~/public_html/hg/.htaccess

Create Passwd files:

cd
htpasswd -b -c -d ~/etc/hg-basic-auth HgUserName PASSWORD

For extra users:

htpasswd -b -d ~/etc/hg-basic-auth HgUserNameExtra PASSWORD

Initialize repositories (Do not forget to change all instances of PROJECT to your own project name):

cd ~/public_html/hg/repos
~/packages/mercurial/hg init PROJECT
echo 'PROJECT = '$HOME'/public_html/hg/repos/PROJECT' >> ~/public_html/hg/hgweb.config

For extra projects :

~/packages/mercurial/hg init ExtraPROJECT
echo 'ExtraPROJECT  = '$HOME'/public_html/hg/repos/ExtraPROJECT' >> ~/public_html/hg/hgweb.config

Now lets create hgrc files for each project :

echo '[web]' > ~/public_html/hg/repos/PROJECT/.hg/hgrc
echo 'contact=admin email address' >> ~/public_html/hg/repos/PROJECT/.hg/hgrc
echo 'description=My releases' >> ~/public_html/hg/repos/PROJECT/.hg/hgrc
echo 'allow_push=USER1, USERn' >> ~/public_html/hg/repos/PROJECT/.hg/hgrc
echo 'allow_archive=zip' >> ~/public_html/hg/repos/PROJECT/.hg/hgrc

By default, pushing is only allowed via HTTPS. To permit HTTP pushing you have to add this to your repository’s .hg/hgrc file (or your Web server user’s .hgrc file, such as/home/www-data/.hgrc, or a system-wide hgrc file like /etc/mercurial/hgrc):

I personally decided to put this in the hgrc file in my repository:

echo 'push_ssl = false' >> ~/public_html/hg/repos/PROJECT/.hgrc

You are basically done. You can access your repository using :

hg clone http://yourdomain.com/hg/PROJECT

<span class=‘st_facebook’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span st_via=‘saman_b’ class=‘st_twitter’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span class=‘st_email’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span class=‘st_sharethis’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span class=‘st_fblike’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span class=‘st_plusone’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'><span class=‘st_pinterest’ st_title=‘Mercurial on Bluehost’ st_url=‘http://www.samanbarghi.com/2011/08/26/mercurial-on-bluehost/'>