OppiaMobile Community

Unable to connect oppiamobile with Apache2

Hi,
I have

ubuntu@myhost:~/oppia$ python3 --version
Python 3.6.3

(env) ubuntu@myhost:~/oppia/django-oppia$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
July 23, 2020 - 13:23:04
Django version 2.2.13, using settings 'oppiamobile.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

/etc/apache2/apache2.conf has this configuration

    <VirtualHost *:89>
            ServerName my.host.com
            WSGIDaemonProcess localhost.oppia python-path=/home/ubuntu/oppia/django-oppia:/home/ubuntu/oppia/env/lib/python3.6/site-packages
            WSGIProcessGroup localhost.oppia
            WSGIScriptAlias / /home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py
            WSGIPassAuthorization On
            <Directory /home/ubuntu/oppia/django-oppia/oppiamobile/>
                    <Files wsgi.py>
                            Require all granted
                    </Files>
            </Directory>
            Alias /media /home/ubuntu/oppia/media/
            <Directory "/home/ubuntu/oppia/media/">
                    Options MultiViews FollowSymLinks
                    AllowOverride None
                    Require all granted
            </Directory>
            Alias /static /home/ubuntu/oppia/static/
            <Directory "/home/ubuntu/oppia/static/">
                    Options MultiViews FollowSymLinks
                    AllowOverride None
                    Require all granted
            </Directory>
            LogLevel warn
            ErrorLog /var/log/apache2/oppia-error.log
            CustomLog /var/log/apache2/oppia-access.log combined
    </VirtualHost>


However, the error says: 
==> /var/log/apache2/oppia-error.log <==
[Thu Jul 23 13:26:07.036985 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442] mod_wsgi (pid=28987): Target WSGI script '/home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py' cannot be loaded as Python module.
[Thu Jul 23 13:26:07.037039 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442] mod_wsgi (pid=28987): Exception occurred processing WSGI script '/home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py'.
[Thu Jul 23 13:26:07.037257 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442] Traceback (most recent call last):
[Thu Jul 23 13:26:07.037331 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py", line 12, in <module>
[Thu Jul 23 13:26:07.037341 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.core.wsgi import get_wsgi_application
[Thu Jul 23 13:26:07.037350 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 2, in <module>
[Thu Jul 23 13:26:07.037355 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.core.handlers.wsgi import WSGIHandler
[Thu Jul 23 13:26:07.037364 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/wsgi.py", line 6, in <module>
[Thu Jul 23 13:26:07.037369 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.core.handlers import base
[Thu Jul 23 13:26:07.037388 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 8, in <module>
[Thu Jul 23 13:26:07.037392 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.urls import get_resolver, set_urlconf
[Thu Jul 23 13:26:07.037400 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/urls/__init__.py", line 1, in <module>
[Thu Jul 23 13:26:07.037404 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from .base import (
[Thu Jul 23 13:26:07.037410 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/urls/base.py", line 9, in <module>
[Thu Jul 23 13:26:07.037414 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from .exceptions import NoReverseMatch, Resolver404
[Thu Jul 23 13:26:07.037421 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/urls/exceptions.py", line 1, in <module>
[Thu Jul 23 13:26:07.037425 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.http import Http404
[Thu Jul 23 13:26:07.037432 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/http/__init__.py", line 2, in <module>
[Thu Jul 23 13:26:07.037438 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.http.request import (
[Thu Jul 23 13:26:07.037445 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/http/request.py", line 10, in <module>
[Thu Jul 23 13:26:07.037449 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.core import signing
[Thu Jul 23 13:26:07.037456 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/core/signing.py", line 45, in <module>
[Thu Jul 23 13:26:07.037459 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     from django.utils.crypto import constant_time_compare, salted_hmac
[Thu Jul 23 13:26:07.037466 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]   File "/usr/local/lib/python3.5/dist-packages/django/utils/crypto.py", line 6, in <module>
[Thu Jul 23 13:26:07.037470 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442]     import secrets
[Thu Jul 23 13:26:07.037489 2020] [wsgi:error] [pid 28987] [remote 103.69.247.73:17442] ImportError: No module named 'secrets'

I am unable to figure out following things:

  1. Why is apache pointing to 3.5 here /usr/local/lib/python3.5? Once this points to 3.6 , I believe ‘screts’ error will be gone.
  2. Target WSGI script ‘/home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py’ cannot be loaded as Python module.

This is coming even when I have wsgi installed and could verify:
wsgi_module (shared)

My machine is Ubuntu16.04 , running on a ec2 m5.large instance with python3.5 and python3.6 both installed.

Please advise.

Hi!
As you point out, python3.6 is not being loaded, and the secrets module only exists on python 3.6 onwards. What is the output of doing python --version with the virtualenv active?

A couple of things to check:

  • Is your virtual environment env configured with your python 3.6 installation? If not, the python-path setting won’t make any effect as that directory won’t exist. If not, you’ll need to create a new virtualenv pointing to that python version.
  • Are you using Apache with the Python3 wsgi module (libapache2-mod-wsgi-py3)? Probably the wsgi loading error is related with the previous one, so first try to solve the other error.

Let me know your advances!

HI Joseba,

For point1 I see it is configured with 3.6.3
(env) ubuntu@myhost:~/oppia$ python --version
Python 3.6.3
And for point2 also I see this module installed
(env) ubuntu@myhost:~/oppia$ apt-cache policy libapache2-mod-wsgi-py3
libapache2-mod-wsgi-py3:
Installed: 4.3.0-1.1ubuntu1
Candidate: 4.3.0-1.1ubuntu1
Version table:
*** 4.3.0-1.1ubuntu1 500
500 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages
100 /var/lib/dpkg/status
4.3.0-1.1build1 500
500 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages

Hi satyadeep
Are running this on a local server? then why are you configuring apache to access it??
Is it a live server? then why running the python manage.py runserver command. Maybe some background on your setup with help in solving this.

Hi @hakimks,
A) I used Python manage.py runserver to show that this is running fine when I am trying it as standalone, whereas when I am trying to integrate it in Apache , it is giving error that I posted.

Please let me know if it is clear now.

Thanks

No, This is not clear. What url are you trying the access the application at? (You should temporarily set DEBUG = True in the settings.py or settings_secret file then reload apache) . this will give more information on the error in the application its self.

Hi @satyadeep ,

To follow up on Joseba’s response, you might want to check in the Apache config…
In the apache config file, check it’s pointing to the correct virtualenv… ie, in the WSGIDaemonProcess line, mine looks like:
WSGIDaemonProcess localhost.oppia python-path=/home/alex/data/Digital-Campus/development/core/django-oppia:/home/alex/data/Digital-Campus/development/core/oppia_core/env/lib/python3.6/site-packages

You mentioned that you have both Python 3.5 and 3.6 installed, so maybe it’s pointing at the wrong one?

Hope that helps?
Cheers,
Alex

Hi Alex,

Many thanks for the response.

My vhost block is :
<VirtualHost *:89>
ServerName my.host.com
WSGIDaemonProcess localhost.oppia python-path=/home/ubuntu/oppia/django-oppia:/home/ubuntu/oppia/env/lib/python3.6/site-packages
WSGIProcessGroup localhost.oppia
WSGIScriptAlias / /home/ubuntu/oppia/django-oppia/oppiamobile/wsgi.py
WSGIPassAuthorization On
<Directory /home/ubuntu/oppia/django-oppia/oppiamobile/>

Require all granted


Alias /media /home/ubuntu/oppia/media/
<Directory “/home/ubuntu/oppia/media/”>
Options MultiViews FollowSymLinks
AllowOverride None
Require all granted

Alias /static /home/ubuntu/oppia/static/
<Directory “/home/ubuntu/oppia/static/”>
Options MultiViews FollowSymLinks
AllowOverride None
Require all granted

LogLevel warn
ErrorLog /var/log/apache2/oppia-error.log
CustomLog /var/log/apache2/oppia-access.log combined

I see that this is matching the physical location:
ubuntu@my.host.com:~/oppia/env/lib/python3.6/site-packages$ pwd
/home/ubuntu/oppia/env/lib/python3.6/site-packages
My python3 is pointing to 3.6.3:
ubuntu@my.host.com:~$ python3 --version
Python 3.6.3

Any idea what could I be missing?

Thanks

I think the issue might be to do with ubuntu 16.04… since by default this runs python 3.5 and 2.7; so I wonder if apache is getting something mixed up here and so is still pointing to python 3.5, even though you have 3.6 installed too.
Not sure if it would be an option for you on this machine, but updating to Ubuntu 18.04 LTS I think would sort the problem out, since this uses Python 3.6 by default.
Cheers,
Alex

Hi @alex,
I spun a new instance with 18.04 and installation is satin smooth. Thank you very much for your help on this.
Will play around a bit with it!!

Thanks again.

Satyadeep

1 Like

Great to know you’ve got it up and running now!

Cheers,
Alex