6

On AWS Elastic Beanstalk, on the "64bit Amazon Linux 2017.09 v2.6.0 running Python 3.6" platform, there seems to be a problem with the mod_wsgi configuration. I see this in /etc/httpd/conf.d/wsgi.conf:

WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
  python-home=/opt/python/run/venv/ \
  python-path=/opt/python/current/app:/opt/python/run/venv/lib64/python3.6/site-packages:/opt/python/run/venv/lib/python3.6/site-packages user=wsgi group=wsgi \
  home=/opt/python/current/app

However, I get this in /var/log/httpd/error_log:

[Mon Nov 20 19:54:44.565076 2017] [:error] [pid 32080] mod_wsgi (pid=32080): Call to 'site.addsitedir()' failed for '(null)', stopping.
[Mon Nov 20 19:54:44.565444 2017] [:error] [pid 32080] mod_wsgi (pid=32080): Call to 'site.addsitedir()' failed for '/opt/python/run/venv/lib64/python3.6/site-packages:/opt/python/run/venv/lib/python3.6/site-packages'.

Trying to access the site results in this error:

[Mon Nov 20 21:21:21.304605 2017] [:error] [pid 2886] [remote 71.236.217.102:39802] ModuleNotFoundError: No module named 'myappname'

If I change the WSGIDaemonProcess directive to the following (thus removing the colon-separated paths):

WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
  python-home=/opt/python/run/venv/ \
  python-path=/opt/python/current/app user=wsgi group=wsgi \
  home=/opt/python/current/app

Then I no longer get the ModuleNotFoundError.

This appears to be the same bug outlined in https://github.com/GrahamDumpleton/mod_wsgi/issues/92 which was fixed in mod_wsgi 4.4.15. However, the AMI comes pre-installed w/ mod24_wsgi-python36.x86_64==3.5-1.24.amzn1.

If I try to fix the WSGIDaemonProcess using an .ebextensions script, it's unfixed by one of the baked-in deploy hooks, and anyway, the defaults as baked appear to be broken by default. How in the world do I fix this?

6

I encountered the same problem today ("64bit Amazon Linux 2017.09 v2.6.0 running Python 3.6", mod_wsgi errors).

I have a workaround, though I'm not sure it is a proper or the most direct solution.

In short

Install the latest mod_wsgi.

Longer explanation...

Check it works manually

First I did the following manually to check it works, then I scripted it so it wouldn't be destroyed on a later deploy.

Installing mod_wsgi will need apxs, so go to the instance and find packages:

eb ssh
yum provides apxs

In my case there were 3. The oldest worked on the ssh console, so I added to .ebextensions/01_packages.config:

packages:
  yum:
    ...
    httpd24-devel-2.4.27-3.75.amzn1.x86_64: []

Then in ssh I followed this sequence to test the manually built version od mod_wsgi (I couldn't get any yum package to work - though it can probably be done).

sudo -s  # become root
cd /tmp
wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz"
tar -xzf '4.4.21.tar.gz'
cd ./mod_wsgi-4.4.21
./configure --with-python=/usr/bin/python3.6
make
make install

Assuming all is good so far, restart Apache:

service httpd restart

Then look in var/log/httpd/error_log and hopefully you'll see:

... [pid 2088] AH00163: Apache/2.4.27 (Amazon) mod_wsgi/4.4.21 Python/3.6.2 configured -- resuming normal operations

I reloaded the Python app page and it's working (well it had a different error but mod_wsgi is working).

Now to make this part of the deployment.

Scripting

After a few iterations, I settled on this in the .ebextensions/... file:

packages:
  yum:
    git: []
    gcc-c++: []
    httpd24-devel-2.4.27-3.75.amzn1.x86_64: []

files:
  "/tmp/update-wsgi.sh" :
    mode: "000755"
    owner: root
    group: root
    content: |
      # update mod_wsgi
      cd /tmp
      wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz" && \
      tar -xzf '4.4.21.tar.gz' && \
      cd ./mod_wsgi-4.4.21 && \
      sudo ./configure --with-python=/usr/bin/python3.6 && \
      sudo make && \
      sudo make install && \
      sudo service httpd restart

commands:
  mod_wsgi_update:
    command: /tmp/update-wsgi.sh
    cwd: /tmp

Some notes:

  • the gcc dependency is needed for mod_wsgi to build
  • the httpd24-devel dependency is for the apsx tool
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.