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
- 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.
- 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.
- 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
- 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
- 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:
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
- 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.
|# fetches the source code of Mercurial
# extracts contents to folder mercurial-1.5.1/
# modify config if multiple Python versions are installed
# compile a version of Mercurial within this directory
# set up a place to archive what I need
# copy out everything I need
# package it up
# you now have a file mercurial.tar which has everything you need for distribution!
Packing and Exporting
- 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
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.