For all the time the web development experience had to deal with various hosting sites on which the websites worked: from those that support only text formats (a la narod.ru) to virtual machines that have root access.
Relatively recently, I ran into a problem: a website was being developed on a shared hosting with a sufficient set of technologies for a regular website for content like news. One of the major problems was the lack of a version control system. It was not possible to establish it in the traditional way. Searches have been started to solve this problem.
The task was completed, and how it was solved is described step by step below.
1. Access to shared hosting should be done via ssh. Connect to hosting:
')
$ ssh user@host
2. Go to your home directory. All actions will be performed on it:
$ cd ~
2. Check that python is installed on shared hosting:
$ python --version Python 2.6.6 $
4. Create a python directory in order to place there modules that are required for mercurial to work, but which are not on shared hosting:
$ mkdir -p python
5. Download Mercurial source code:
www.mercurial-scm.org/release $ wget https://www.mercurial-scm.org/release/mercurial-3.7.tar.gz
6. Extract the contents of the archive into the current directory:
$ tar xvf mercurial-3.7.tar.gz
7. Rename the folder to mercurial:
$ mv mercurial-3.7 mercurial -v
8. Go to the mercurial folder:
$ cd mercurial
9. Install mercurial from source:
$ python setup.py --pure build_py -c -d . build_ext -i build_mo --force
10. Since the installation from source codes is considered non-standard, it is necessary to do the following to install the modules:
$ python setup.py --pure install --prefix ../../python --force
11. If the installation was completed correctly, then in the
~ / python / lib {type} / python {version} / site-packages / directory there will be the following list of files:
$ ls -l ~/python/lib64/python3.7/site-packages/ total 12 drwxr-xr-x 5 user group 4096 Oct 2 2014 hgext drwxr-xr-x 6 user group 4096 Oct 2 2014 mercurial -rw-r--r-- 1 user group 238 Oct 2 2014 mercurial-3.7-py3.7.egg-info $
And the ~ / python / bin / directory will contain the compiled hg:
$ ls ~/python/bin/ -l total 4 -rwxr-xr-x 1 user group 770 Oct 1 2014 hg $
12. Create a file .profile or .bash_profile (depends on the settings of the shared-hosting), if there is none:
$ touch ~/.profile
13. Write the following to the file:
export PATH=~/python/bin:$PATH export PYTHONPATH=~/python/lib64/python3.7/site-packages
The first line adds the path to the folder with Mercurial to the PATH environment variable. The second line adds the path to the python modules. Adding these lines allows you to work with Mercurial online.
14. To check that everything is done correctly, you need to create a new ssh connection and test the performance of Mercurial:
$ hg --version
If everything is done correctly, a message will be displayed:
Mercurial Distributed SCM (version 3.7)
Copyright (C) 2005-2016 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15. For Mercurial to work in non-interactive mode, you need to add a
.bashrc file :
export PATH=~/python/bin:$PATH export PYTHONPATH=~/python/lib64/python3.7/site-packages
After saving the changes, you must try the command in non-interactive mode:
$ ssh user@host hg --version
If a message like this is displayed:
Mercurial Distributed SCM (version 3.7)
Copyright (C) 2005-2016 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
then setup is complete.
If there is a message like:
sh: hg: command not found
This suggests that shared hosting does not allow the user to override
.bashrc .
You can pass the necessary environment variables directly when executing a command in non-interactive mode:
$ssh user@host "export PATH=~/python/bin:$PATH;declare -x PYTHONPATH=~/python/lib64/python3.7/site-packages;hg --version"
A message should be displayed:
Mercurial Distributed SCM (version 3.7)
Copyright (C) 2005-2016 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
When working with a remote repository hosted on a shared-hosting, the presence of environment variables is required for commands that connect to the remote repository:
- clone
- outgoing
- incoming
- pull
- push
To connect the necessary environment variables, use the
--config option, adding the path to hg:
$ hg --config ui.remotecmd='export "PATH=~/python/bin:$PATH";export "PYTHONPATH=~/python/lib64/python3.7/site-packages";~/python/bin/hg' inc
Or specify this setting in
.hg / hgrc in the [ui] section:
[ui]
config ui.remotecmd = export "PATH=~/python/bin:$PATH";export "PYTHONPATH=~/python/lib64/python3.7/site-packages";~/python/bin/hg
With such settings, the remote command may not be executed, due to the presence of quotes.
In this case, you can create an alias in
.bash_profile on the machine connecting to the shared hosting for the hg command with this parameter:
alias hg="hg --config ui.remotecmd='export "PATH=~/python/bin:$PATH";export "PYTHONPATH=~/python/lib64/python2.6/site-packages";~/python/bin/hg'"
After that, you can execute commands in the usual way:
$ hg inc
References to the used materials:
- Installing Mercurial on a Shared Web Server without Root Access
- Installing Python Modules
- Python Windows Install (Description for Windows, but Windows was not used here)
- Mercurial - CommonProblems
- Configuration files for Mercurial
- Linux man page - bash