Weblate: Weblate+Apache+MySQL+WSCGI setup docs are unusable (/ non-existent?)

Created on 5 Aug 2020  路  8Comments  路  Source: WeblateOrg/weblate

Describe the issue

Environment: Fresh Ubuntu 20.04 cloud vm (Python 3.8.2)

First problem was getting mysql set up as a database backend. Nowhere in the docs does it clearly indicate what system level & pip virtualenv level packages must be installed, so I had to trial and error through this. The setup steps should be listed clearly as expecting prior experience with a django/python stack to try to figure out which mysql libs are needed and how to install them is onerous.

However, I was able to successfully set up weblate in a virtual environment following the documentation and connect to it on localhost with lynx.

My next step was to try setting up apache for production use, but failed miserably and absolutely.

I started with this config from the docs.

Upon accessing the website, I got the following error in my apache logs:

[Wed Aug 05 04:54:10.913520 2020] [wsgi:error] [pid 4119:tid 140632917022464] [remote ip.ip.ip.ip:4955] mod_wsgi (pid=4119): Exception occurred processing WSGI script '/home/weblate/weblate-env/lib/python3.8/site-packages/weblate/wsgi.py'.
[Wed Aug 05 04:54:10.913571 2020] [wsgi:error] [pid 4119:tid 140632917022464] [remote ip.ip.ip.ip:4955]   File "/home/weblate/weblate-env/lib/python3.8/site-packages/weblate/wsgi.py", line 2
[Wed Aug 05 04:54:10.913576 2020] [wsgi:error] [pid 4119:tid 140632917022464] [remote ip.ip.ip.ip:4955] SyntaxError: Non-ASCII character '\\xc2' in file /home/weblate/weblate-env/lib/python3.8/site-packages/weblate/wsgi.py on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Following this stackoverflow note, I try adding this to the top of my /home/weblate/weblate-env/lib/python3.8/site-packages/weblate/wsgi.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

Now I get a different error on page load:

[Wed Aug 05 04:58:15.436260 2020] [wsgi:error] [pid 4119:tid 140633034520320] [remote ip.ip.ip.ip:4971] Traceback (most recent call last):
[Wed Aug 05 04:58:15.436286 2020] [wsgi:error] [pid 4119:tid 140633034520320] [remote ip.ip.ip.ip:4971]   File "/home/weblate/weblate-env/lib/python3.8/site-packages/weblate/wsgi.py", line 43, in <module>
[Wed Aug 05 04:58:15.436312 2020] [wsgi:error] [pid 4119:tid 140633034520320] [remote ip.ip.ip.ip:4971]     from django.core.wsgi import get_wsgi_application
[Wed Aug 05 04:58:15.436326 2020] [wsgi:error] [pid 4119:tid 140633034520320] [remote ip.ip.ip.ip:4971] ImportError: No module named django.core.wsgi

Okay... maybe I need to install something in my pip environment? (At this point I'm really feeling like I must be missing some missing documentation chapter, because it really seems like this should be documented somewhere instead of even more trial-and-erroring)

So I try

pip install django-wsgi2

Resulting in this hot mess:

(weblate-env) weblate@translate:~/weblate-env/lib/python3.8/site-packages/weblate$ pip install django-wsgi2
Collecting django-wsgi2
  Downloading django-wsgi2-1.0.2.tar.gz (5.4 kB)
Collecting WebOb>=1.5
  Downloading WebOb-1.8.6-py2.py3-none-any.whl (114 kB)
     |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 114 kB 16.9 MB/s
Requirement already satisfied: django>=3.0 in /home/weblate/weblate-env/lib/python3.8/site-packages (from django-wsgi2) (3                                                                                    .0.9)
Requirement already satisfied: setuptools in /home/weblate/weblate-env/lib/python3.8/site-packages (from django-wsgi2) (44                                                                                    .0.0)
Collecting six==1.10.0
  Downloading six-1.10.0-py2.py3-none-any.whl (10 kB)
Requirement already satisfied: sqlparse>=0.2.2 in /home/weblate/weblate-env/lib/python3.8/site-packages (from django>=3.0-                                                                                    >django-wsgi2) (0.3.1)
Requirement already satisfied: asgiref~=3.2 in /home/weblate/weblate-env/lib/python3.8/site-packages (from django>=3.0->dj                                                                                    ango-wsgi2) (3.2.10)
Requirement already satisfied: pytz in /home/weblate/weblate-env/lib/python3.8/site-packages (from django>=3.0->django-wsg                                                                                    i2) (2020.1)
Building wheels for collected packages: django-wsgi2
  Building wheel for django-wsgi2 (setup.py) ... done
  Created wheel for django-wsgi2: filename=django_wsgi2-1.0.2-py3-none-any.whl size=8119 sha256=8ade11d90a1ed4670cbbc491db                                                                                    96b97774f49fc947e1b936c805f81e50eaf2de
  Stored in directory: /home/weblate/.cache/pip/wheels/ff/1d/26/272a2ea1d3467dc35c99836c32294c663450a6317752a99613
Successfully built django-wsgi2
ERROR: jsonschema 3.2.0 has requirement six>=1.11.0, but you'll have six 1.10.0 which is incompatible.
ERROR: django-compressor 2.4 has requirement six>=1.12.0, but you'll have six 1.10.0 which is incompatible.
Installing collected packages: WebOb, six, django-wsgi2
  Attempting uninstall: six
    Found existing installation: six 1.14.0
    Uninstalling six-1.14.0:
      Successfully uninstalled six-1.14.0
Successfully installed WebOb-1.8.6 django-wsgi2-1.0.2 six-1.10.0

This command has now somehow managed to completely fsck my virtualenv pip -- can't even do pip list anymore.

(weblate-env) weblate@translate:~/weblate-env/six-1.15.0$ pip list
Traceback (most recent call last):
  File "/home/weblate/weblate-env/bin/pip", line 8, in <module>
    sys.exit(main())
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/commands/list.py", line 13, in <module>
    from pip._internal.cli.req_command import IndexGroupCommand
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
    from pip._internal.operations.prepare import RequirementPreparer
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 16, in <module>
    from pip._internal.distributions import (
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/distributions/__init__.py", line 2, in <module>
    from pip._internal.distributions.wheel import WheelDistribution
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/distributions/wheel.py", line 5, in <module>
    from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
  File "/home/weblate/weblate-env/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
    from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/home/weblate/weblate-env/lib/python3.8/site-packages/six.py)

I find this thread which helps me un-fsck it by manually installing the lib that's breaking it (and reminding me again why I hate python stacks)

Anyway, a couple hours later, now I appear to have it okay:

(weblate-env) weblate@translate:~/weblate-env/six-1.15.0$ pip list | grep wsgi
django-wsgi2           1.0.2

And yet I still get the same apache error: ImportError: No module named django.core.wsgi

So maybe I need some django-wsgi instead of django-wsgi2??? So I try pip install django-wsgi and proceed to re-fsck my pip install again ($#%@).

Anyway, I'm totally lost on this and I can't understand why this is so hard. Am I just missing the apache setup instructions? I must be doing something very wrong here.

Server configuration and status

On pip installed Weblate:

weblate list_versions
(had to run as www-data to get this to not error out)
(weblate-env) www-data@translate:/home/weblate$ weblate list_versions

  • Weblate: 4.1.1
  • Django: 3.0.9
  • siphashc: 1.3
  • Whoosh: 2.7.4
  • translate-toolkit: 3.0.0
  • lxml: 4.5.2
  • Pillow: 7.1.2
  • bleach: 3.1.5
  • python-dateutil: 2.8.1
  • social-auth-core: 3.3.3
  • social-auth-app-django: 3.4.0
  • django-crispy-forms: 1.9.2
  • oauthlib: 3.1.0
  • django-compressor: 2.4
  • djangorestframework: 3.11.0
  • django-filter: 2.3.0
  • django-appconf: 1.0.4
  • user-agents: 2.1
  • filelock: 3.0.12
  • setuptools: 44.0.0
  • jellyfish: 0.8.2
  • openpyxl: 3.0.4
  • celery: 4.4.7
  • kombu: 4.6.11
  • translation-finder: 2.1
  • html2text: 2020.1.16
  • pycairo: 1.19.1
  • pygobject: 3.36.1
  • diff-match-patch: 20181111
  • requests: 2.22.0
  • django-redis: 4.12.1
  • hiredis: 1.0.1
  • sentry_sdk: 0.15.1
  • Cython: 0.29.21
  • misaka: 2.1.1
  • GitPython: 3.1.7
  • borgbackup: 1.1.13
  • pyparsing: 2.4.6
  • Python: 3.8.2
  • Git: 2.25.1
  • chardet: 3.0.4
  • ruamel.yaml: 0.16.10
  • aeidon: 1.7.0
  • mysqlclient: 2.0.1
  • Redis server: 5.0.7
  • MySQL sever: 5.7.31
  • Database backends: django.db.backends.mysql
  • Cache backends: default:RedisCache, avatar:FileBasedCache
  • Email setup: django.core.mail.backends.smtp.EmailBackend: localhost
  • OS encoding: filesystem=utf-8, default=utf-8
  • Celery: redis://localhost:6379, redis://localhost:6379, regular
  • Platform: Linux 5.4.0-42-generic (x86_64)

Weblate deploy checks

(weblate-env) www-data@translate:/home/weblate$ weblate check --deploy
SystemCheckError: System check identified some issues:

CRITICALS:
?: (weblate.E003) Cannot send e-mail ([Errno 111] Connection refused), please check EMAIL_* settings.
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#out-mail
?: (weblate.E017) Correct the site domain
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#production-site
?: (weblate.E019) The Celery does not process tasks, or is too slow in processing them.
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#celery

ERRORS:
?: (weblate.E011) E-mail addresses for site admins is misconfigured
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#production-admins

WARNINGS:
?: (security.W004) You have not set a value for the SECURE_HSTS_SECONDS setting. If your entire site is served only over SSL, you may want to consider setting a value and enabling HTTP Strict Transport Security. Be sure to read the documentation first; enabling HSTS carelessly can cause serious, irreversible problems.
?: (security.W008) Your SECURE_SSL_REDIRECT setting is not set to True. Unless your site should be available over both SSL and non-SSL connections, you may want to either set this setting True or configure a load balancer or reverse-proxy server to redirect all connections to HTTPS.
?: (security.W012) SESSION_COOKIE_SECURE is not set to True. Using a secure-only session cookie makes it more difficult for network traffic sniffers to hijack user sessions.
?: (security.W018) You should not have DEBUG set to True in deployment.
?: (weblate.W025.ini) Failure in loading handler for ini file format: Missing iniparse library.
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#optional-deps
?: (weblate.W025.islu) Failure in loading handler for islu file format: Missing iniparse library.
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#optional-deps
?: (weblate.W025.laravel) Failure in loading handler for laravel file format: No module named 'phply'
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#optional-deps
?: (weblate.W025.php) Failure in loading handler for php file format: No module named 'phply'
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#optional-deps
?: (weblate.W033.Gerrit) Failure in loading VCS module for Gerrit: git: 'review' is not a git command. See 'git --help'.
(1)
HINT: https://docs.weblate.org/en/weblate-4.1.1/vcs.html
?: (weblate.W033.GitHub) Failure in loading VCS module for GitHub: [Errno 2] No such file or directory: 'hub'
HINT: https://docs.weblate.org/en/weblate-4.1.1/vcs.html
?: (weblate.W033.GitLab) Failure in loading VCS module for GitLab: [Errno 2] No such file or directory: 'lab'
HINT: https://docs.weblate.org/en/weblate-4.1.1/vcs.html
?: (weblate.W033.Mercurial) Failure in loading VCS module for Mercurial: [Errno 2] No such file or directory: 'hg'
HINT: https://docs.weblate.org/en/weblate-4.1.1/vcs.html
?: (weblate.W033.Subversion) Failure in loading VCS module for Subversion: git: 'svn' is not a git command. See 'git --help'.

The most similar commands are
fsck
mv
show
(1)
HINT: https://docs.weblate.org/en/weblate-4.1.1/vcs.html

INFOS:
?: (weblate.I021) Error collection is not set up, it is highly recommended for production use
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/install.html#collecting-errors
?: (weblate.I028) Backups are not configured, it is highly recommended for production use
HINT: https://docs.weblate.org/en/weblate-4.1.1/admin/backup.html

System check identified 19 issues (1 silenced).

question wontfix

All 8 comments

This issue looks like a support question. We try to answer these reasonably fast, but in case you are looking for faster resolution, please consider purchasing support subscription and make Weblate stronger.

First problem was getting mysql set up as a database backend. Nowhere in the docs does it clearly indicate what system level & pip virtualenv level packages must be installed, so I had to trial and error through this.

Have you read https://docs.weblate.org/en/latest/admin/install/venv-debian.html?

SyntaxError: Non-ASCII character

You are probably using Python 2, Weblate requires Python 3. Try installing libapache2-mod-wsgi-py3 instead of libapache2-mod-wsgi.

So maybe I need some django-wsgi instead of django-wsgi2???

You don't need either of them.

Thank you, that was just the tip I needed to get it up and running under apache. I also appreciate you adding the needed package to the docs.


Regarding the URL you provided, yes, I followed that tutorial and it was useful generally speaking -- however, it assumes a postgre install. So my trial and erroring was with regards to the steps/packages are needed for mysql.


I also ran into this issue today. Digging around in search engines, I managed to find that django apps need a special setting in /etc/apache2/envvars

export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

This fixed the issue, but I think a note should be added about this somewhere in the apache setup tips. More ideally there would be a similar step by step guide for setting up apache like there is for setting up the direct server guide, including all the needed steps. Perhaps prior apache setup experience can be assumed, but a lot of potential users will not have prior django setup experience. Ideally, no prior knowledge is assumed.


Finally, I've run into a problem with celery: The Celery does not process tasks, or is too slow in processing them. I think I have not configured it correctly, but I'm a bit lost in the documentation. Is there a page explaining how to set it up? Or maybe it is assumed django knowledge that I don't have.

I get this in the Celery logs, making me think I haven't set up whatever it's supposed to connect to:

root@translate:~# tail /var/log/celery/weblate-celery.log
[2020-08-06 05:51:33,000: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.
Trying again in 32.00 seconds... (16/100)

it assumes a postgre install.

Yes, because it's recommended setup for new installations. MySQL/MariaDB are still supported, but it is primarily intended for existing installs (the original intention was to drop their support in the 4.0 release, but I got convince to keep it for existing installs, see https://github.com/WeblateOrg/weblate/issues/2825).

I managed to find that django apps need a special setting in /etc/apache2/envvars

Thanks for figuring this out, I've included this in docs.

More ideally there would be a similar step by step guide for setting up apache like there is for setting up the direct server guide, including all the needed steps

Contributions are always welcome. The installation docs is mostly including shared bits, so adding another variant should not be hard, see for example https://github.com/WeblateOrg/weblate/blob/master/docs/admin/install/venv-redhat.rst which ends up as https://docs.weblate.org/en/latest/admin/install/venv-redhat.html.

Cannot connect to amqp:

It doesn't seem to use correct configuration. There is https://docs.weblate.org/en/latest/admin/install.html#celery describing the Celery setup.

the original intention was to drop their support in the 4.0 release

Ah, well, I'm glad that didn't happen, heh. I've standardized on mysql for all our databases, which has made it a lot easier since only one database skillset is needed (and can use the same backup mechanisms, etc) and IMO there is more robust tooling (phpmyadmin to me is far more polished than similar tools available for postgre). So to my personal evaluation, having to learn & maintain a whole new database system would be a major disadvantage vs other solutions. (This is also the main reason I'm attempting the manual install method instead of using a container, to maximize the performance within a single VM since it doesn't have to use a database. If I went the container route, I'd have to manually disable the database service and retune apache every new release). That is not to say there are not some tradeoffs or MySQL is a perfect choice, of course, but MySQL is still used more widely than Postgre.

It doesn't seem to use correct configuration.

Yep, that's the exact config I'm using, including the daemon scripts. I've placed those three lines into /home/weblate/weblate-env/lib/python3.8/site-packages/weblate/settings.py, which seems like the right place for them?

I've tried with and without the 'app instance' setting -- I haven't used celery before, so I'm not sure as to whether it's needed. I'm assuming I don't need it since I don't use celery for anything else.

FWIW, things seem to be working fine without Celery, so my current plan is to just go without. Our install should have relatively low traffic, so I'm hoping this will be okay.

The only other setup wrinkle I had was on getting subversion set up. I thought it was a Weblate/git-svn issue, but apparently the most recent versions of subversion silently force disable plaintext password storage (and don't provide any non-interactive persistent keyring options). A good thing to do is test updating the svn depot twice to see if its actually caching credentials before setting it up in Weblate.

Anyway, we're up and running now; translators seem really happy with the system, and the status image embed is really nifty for getting more people interested. 馃憤

FWIW, things seem to be working fine without Celery, so my current plan is to just go without. Our install should have relatively low traffic, so I'm hoping this will be okay.

CELERY_TASK_ALWAYS_EAGER should work, but it might lead to some issues (for example GitHub hooks being disabled because they don't respond on time).

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings