Run python-based applications on Netcup hosting

Many webhosting contracts from the German company Netcup include Python as interpreted language, but it’s a bit quirky how it can be used. As an example, I’ll describe how the feed enhancer morss can be installed. But please make sure your contract in fact includes Python before following the instructions below!

Firstly we’ll clone the code of the application somewhere outside the web root:

git clone https://github.com/pictuga/morss.git /apps/morss

Some files have to be on the web root of our subdomain (which is /www/morss in this example), so we’ll link them there:

ln -s ../../apps/morss/www/index.html /www/morss/
ln -s ../../apps/morss/www/logo.svg /www/morss/
ln -s ../../apps/morss/www/sheet.xsl /www/morss/

We have to apply a small patch because the import style in the Python files is not compatible with how Phusion Passenger runs the application:

curl https://zephyrsoft.org/wp-content/uploads/morss-patch.txt >/tmp/morss-patch.txt
cd /apps/morss
git apply /tmp/morss-patch.txt

Now we go into the “Webhosting Control Panel” and create a subdomain, create a certificate and configure the web root /www/morss for it. Additionally we go to the “Python” submenu and set the “App Root” to /apps/morss/morss (with the extra “morss” because there’s a subdirectory which we want to use) and the “Startup Datei” to wsgi.py – the rest of the options can be left at the default.

The basic setup is done now, and when we call our subdomain, at least something should work – but not all yet because the dependencies of the Python application are still missing. And sadly we can’t simply run pip, so we have to use a trick: we download the dependencies locally (hopefully you have a Linux machine for that) and then upload them into the app root so they appear as local dependencies. And this is how:

  • check the Python version provided by Netcup (it’s 3.11.2 at the time of writing)
  • download the source code for exactly this version from https://www.python.org/downloads/
  • extract the downloaded package with tar xvJf filename (if it’s XZ) or tar xvzf filename (if it’s GZIP)
  • go to the extracted directory
  • execute ./configure –enable-optimizations
  • execute make (this takes some time)
  • create a venv with the newly created Python executable: ./python -m venv venv
  • activate the venv: . venv/bin/activate
  • install the dependencies of morss: pip3 install lxml bs4 python-dateutil chardet redis diskcache gunicorn setproctitle pylint pyenchant
  • go where the dependencies are located: cd venv/lib/python3.11/site-packages
  • upload the directories so morss can import the dependencies: scp -r * user@netcupserver:/apps/morss/morss/

Now the application should fully work. Enjoy!

The following German articles helped me putting this together: