Posted by: Josh | May 8, 2010

Pre-compiling the Mercurial Binary for Linux Shared Hosting Servers

I’m posting these instructions just in case you want to run your own Mercurial packages, or run your C/C++ binary on a shared hosting server which has the capability to execute but not compile.

In this example I’ll be demonstrating building Mercurial from source, but I suppose this could apply to other projects like Trac. To continue, it’d be best if you’ve had a little bit of experience with Linux and the bash terminal, to help trouble-shoot should a problem arise.

Replicating the Environment

  1. Find out what OS your shared host is running. Easiest way is to check the “stats” section in the cPanel, if you’re provided with one. Also take note of the architecture type “x86_64” (64-bit) or “x86” (32-bit) and any other dependencies.
    For the purposes of this article, I will only be detailing build instructions for Linux.
  2. Your current workstation might not match the OS & architecture combination you need. To run such an environment, we can run some virtualization software locally. My favourite is Sun VirtualBox, which you’ll need to install.
    * Usually you would require a 64-bit computer to virtualize a 64-bit OS, but apparently VirtualBox has made this possible with a 32-bit host OS. Details here.
  3. Now for setting up the OS “guest”, follow VirtualBox’s setup instructions here. In most cases, the default values are sufficient. When starting up the virtual machine for the first time, it’ll ask for a disc image to boot from. Here, I’ll be providing Debian-based instructions, so download and select to boot from one of these two disc images:
    Debian 64-bit “amd64” | Debian 32-bit “i386”
    * These are ~180 MB “small CD” network install disc image links
  4. Run through the Debian installer. It’s up to you whether you want a desktop environment and “guest additions” integration to accompany the installation.

Once the guest OS install is complete and you’ve booted into it with VirtualBox, you’re ready to continue.

Pulling the Source

  1. Figure out the dependencies you need – they are often outlined on the software’s site itself. Mercurial lists Python 2.4+ and a C compiler, and a bit of searching the Debian package repository will suggest these install packages:
    – build-essential
    – python2.4

    So under administrative privileges (log in with root in a terminal with command su or prepend sudo to the following instructions):
    apt-get install build-essential
    apt-get install python2.4

  2. We’re building from source as-opposed to using a pre-built package, since we want to be able to pick up the output and transplant it to our shared host (some install packages allow this, but it won’t be covered here).The following is Mercurial-specific shell interaction.
  3. # fetches the source code of Mercurial
    wget
    http://mercurial.selenic.com/release/mercurial-1.5.1.tar.gz

    # extracts contents to folder mercurial-1.5.1/
    tar –xvf mercurial-1.5.1.tar.gz

    # modify config if multiple Python versions are installed
    cd mercurial-1.5.1
    # changes PYTHON=python to PYTHON=python2.4 and saves
    sed -i ‘s/PYTHON=python/PYTHON=python2.4/g’ Makefile

    # compile a version of Mercurial within this directory
    make local

    # set up a place to archive what I need
    cd ..
    mkdir mercurial

    # copy out everything I need
    cp –R mercurial-1.5.1/mercurial/* mercurial
    cp –R mercurial-1.5.1/i18n mercurial
    cp –R mercurial-1.5.1/hgext mercurial
    cp mercurial-1.5.1/hgwebdir.cgi mercurial

    # package it up
    tar –cf mercurial

    # you now have a file mercurial.tar which has everything you need for distribution!

Packing and Exporting

  1. There’s quite a few ways to get changes off this server. You could e-mail it to yourself, check it in to source control, or send it over FTP/SFTP. Here, I wanted to use SFTP, so I needed to install it first (as an admin):

    apt-get install openssh-client
    sftp
    username@host.com

    and use the command “put” to upload the file. More on command-line SFTP.

And that should be all there is to it. You can create as many guest OSes as you need to match different server requirements.


Responses

  1. tank you,for your info..

  2. thanks for your information🙂

  3. Linux is typically a good match for Web hosting servers and applications because of its stability, the savings in running multiple servers without licensing costs, and the flexibility to customize code and applications for specific site or infrastructure needs.

  4. @Hilongos you bring up very strong points about Linux and thanks for your feedback. To the other visitors: remember that, like your choice in programming languages and plans in system architecture, every choice always gives both advantages and disadvantages, so fully evaluate your options before deciding!

  5. I can’t stand football nn teen
    :-DDD

  6. Cool site goodluck🙂 Cute Russian Models
    8P


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Categories

%d bloggers like this: