This is not a sponsored post. I just want to show you the steps, that are needed to easily deploy a Django application.

Uberspace.de is an awesome german hosting company, where you can host your web application via shared hosting. That means, that your applicaton is running on a web server, that you share with other people. You get 10 GB of webspace and a lot of possibilities if you can handle a shell to access your web space. In difference to other hosting companies, where you are only able to deploy a PHP application, you have the choice to choose your tools. For example, if you want use Python and the Django framework, it is no problem, because you can install Django with pip, only with restriction to install it for your user.

If you want to deploy a Django application on a uberspace U7 host, then you can do the following steps:

Steps

Setup your project

First you have to install your requirements. For a simple Django application you will need Django of course.

1
pip3.6 install django --user

For a more advanced setup with the Django REST framework, CORS headers and a MySQL database you will need more.

1
2
3
4
pip3.6 install django --user
pip3.6 install djangorestframework --user
pip3.6 install django-cors-headers --user
pip3.6 install mysqlclient --user

Port

Because Uberspace is using a shared hosting environment and so you are sharing a host with other people, you cannot use the default port of an application like 8080 for the webserver. In order to deploy your applocation you need to have a public port nevertheless, which you get with this command. Run this command as long as it showing “try again”.

1
$(( $RANDOM % 4535 + 61000)); netstat -tulpen | grep $DJANGOPORT && echo "try again"

Deamon

1
2
cd ~/etc/services.d
nano gunicorn.init

Paste the following text, where gunicorn is the name of the deamon, which should be also the name of the file (gunicorn.ini). Then you have to exchange my port 63250 with the port of the above step.

1
2
[program:gunicorn]
command=bash -c '~/.local/bin/gunicorn --error-logfile - --reload --chdir ~/backend --bind 127.0.0.1:63250 backend.wsgi:application'

Then start the deamon with:

1
2
3
supervisorctl reread
supervisorctl update
supervisorctl start gunicorn

Routing with .htaccess

1
2
cd ~/html
nano .htaccess

Then paste this text, where you have to exchange the port numbers again.

1
2
RewriteEngine On
RewriteRule (.*) http://127.0.0.1:63250/$1 [P]

Updating the project

If you update your project, e.g. with a git pull or updating new code per FTP, you have to simply restart the deamon.

1
supervisorctl restart gunicorn

For more information, visit the Uberspace manual