title: 500 internal server error deploying Django-Wagtail application on AWS Elastic Beanstalk
body: <p>I have tried everything I can think of and I have gone through <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html" rel="nofollow noreferrer">the AWS</a> and <a href="https://realpython.com/deploying-a-django-app-and-postgresql-to-aws-elastic-beanstalk/" rel="nofollow noreferrer">RealPython</a> guides. I am honestly at a loss.</p>
  
  <p>I have developed an application and it functions perfectly on my local machine, using a pipenv lockfile. Because of this there was no immediate need for a requirements.txt, however EB requires one and so, with the pipenv environment open I ran </p>
  
  <pre><code>pip freeze &gt; requirements.txt
  </code></pre>
  
  <p>to create one. It now contains:</p>
  
  <pre><code>beautifulsoup4==4.6.0
  certifi==2019.11.28
  cffi==1.13.2
  chardet==3.0.4
  cryptography==2.8
  defusedxml==0.6.0
  Django==2.1.1
  django-allauth==0.40.0
  django-modelcluster==4.4.1
  django-taggit==0.24.0
  django-treebeard==4.3.1
  djangorestframework==3.11.0
  draftjs-exporter==2.1.7
  html5lib==1.0.1
  idna==2.8
  oauthlib==3.1.0
  Pillow==5.4.1
  pycparser==2.19
  python3-openid==3.1.0
  pytz==2019.3
  requests==2.22.0
  requests-oauthlib==1.2.0
  six==1.14.0
  sqlparse==0.3.0
  Unidecode==1.1.1
  urllib3==1.25.7
  wagtail==2.5.2
  webencodings==0.5.1
  Willow==1.1
  </code></pre>
  
  <p>I had to downgrade to Django 2.1.1 because someone said that there are versioning issues with EB at 2.2. I am using python 3.6.8.</p>
  
  <p>I was receiving an error stating that "WSGIPath refers to a file that does not exist", I fixed this using</p>
  
  <pre><code>eb config
  </code></pre>
  
  <p>and searching for wsgi and changing the path to</p>
  
  <pre><code>application_name/wsgi.py
  </code></pre>
  
  <p>Now, upon running</p>
  
  <pre><code>eb create
  eb deploy
  </code></pre>
  
  <p>I receive the output</p>
  
  <pre><code>Creating application version archive "app-60c1-200116_214620".
  Uploading application_name/app-60c1-200116_214620.zip to S3. This may take a while.
  Upload Complete.
  2020-01-16 19:46:35    INFO    Environment update is starting.      
  2020-01-16 19:46:38    INFO    Deploying new version to instance(s).
  2020-01-16 19:47:00    INFO    New application version was deployed to running EC2 instances.
  2020-01-16 19:47:00    INFO    Environment update completed successfully.
  </code></pre>
  
  <p>I have also added the url into ALLOWED_HOSTS in base.py (wagtail version of settings.py).</p>
  
  <p>The application works locally but when I run it on the server I receive a 500 internal service error. The following is some of the contents of the log file:</p>
  
  <pre><code>-------------------------------------
  /var/log/httpd/error_log
  -------------------------------------
  [Thu Jan 16 19:40:47.104485 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] mod_wsgi (pid=4284): Exception occurred processing WSGI script '/opt/python/current/app/educess/wsgi.py'.
  [Thu Jan 16 19:40:47.104591 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] Traceback (most recent call last):
  [Thu Jan 16 19:40:47.104624 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]   File "/opt/python/current/app/educess/wsgi.py", line 16, in &lt;module&gt;
  [Thu Jan 16 19:40:47.104629 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]     application = get_wsgi_application()
  [Thu Jan 16 19:40:47.104636 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  [Thu Jan 16 19:40:47.104640 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]     django.setup(set_prefix=False)
  [Thu Jan 16 19:40:47.104645 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
  [Thu Jan 16 19:40:47.104649 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]     apps.populate(settings.INSTALLED_APPS)
  [Thu Jan 16 19:40:47.104655 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/registry.py", line 83, in populate
  [Thu Jan 16 19:40:47.104658 2020] [:error] [pid 4284] [remote 127.0.0.1:18388]     raise RuntimeError("populate() isn't reentrant")
  [Thu Jan 16 19:40:47.104672 2020] [:error] [pid 4284] [remote 127.0.0.1:18388] RuntimeError: populate() isn't reentrant
  [Thu Jan 16 19:46:46.365964 2020] [mpm_prefork:notice] [pid 4279] AH00169: caught SIGTERM, shutting down
  [Thu Jan 16 19:46:47.478417 2020] [suexec:notice] [pid 4716] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
  [Thu Jan 16 19:46:47.494121 2020] [so:warn] [pid 4716] AH01574: module wsgi_module is already loaded, skipping
  [Thu Jan 16 19:46:47.496176 2020] [http2:warn] [pid 4716] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
  [Thu Jan 16 19:46:47.496186 2020] [http2:warn] [pid 4716] AH02951: mod_ssl does not seem to be enabled
  [Thu Jan 16 19:46:47.496728 2020] [lbmethod_heartbeat:notice] [pid 4716] AH02282: No slotmem from mod_heartmonitor
  [Thu Jan 16 19:46:47.496790 2020] [:warn] [pid 4716] mod_wsgi: Compiled for Python/3.6.2.
  [Thu Jan 16 19:46:47.496794 2020] [:warn] [pid 4716] mod_wsgi: Runtime using Python/3.6.8.
  [Thu Jan 16 19:46:47.498977 2020] [mpm_prefork:notice] [pid 4716] AH00163: Apache/2.4.41 (Amazon) mod_wsgi/3.5 Python/3.6.8 configured -- resuming normal operations
  [Thu Jan 16 19:46:47.498995 2020] [core:notice] [pid 4716] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
  [Thu Jan 16 19:46:50.530525 2020] [:error] [pid 4721] [remote 127.0.0.1:0] mod_wsgi (pid=4721): Target WSGI script '/opt/python/current/app/educess/wsgi.py' cannot be loaded as Python module.
  [Thu Jan 16 19:46:50.530599 2020] [:error] [pid 4721] [remote 127.0.0.1:0] mod_wsgi (pid=4721): Exception occurred processing WSGI script '/opt/python/current/app/educess/wsgi.py'.
  [Thu Jan 16 19:46:50.531288 2020] [:error] [pid 4721] [remote 127.0.0.1:0] Traceback (most recent call last):
  [Thu Jan 16 19:46:50.531332 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/current/app/educess/wsgi.py", line 16, in &lt;module&gt;
  [Thu Jan 16 19:46:50.531337 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     application = get_wsgi_application()
  [Thu Jan 16 19:46:50.531344 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  [Thu Jan 16 19:46:50.531347 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     django.setup(set_prefix=False)
  [Thu Jan 16 19:46:50.531353 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
  [Thu Jan 16 19:46:50.531356 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     apps.populate(settings.INSTALLED_APPS)
  [Thu Jan 16 19:46:50.531362 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
  [Thu Jan 16 19:46:50.531365 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     app_config = AppConfig.create(entry)
  [Thu Jan 16 19:46:50.531371 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
  [Thu Jan 16 19:46:50.531374 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     module = import_module(entry)
  [Thu Jan 16 19:46:50.531379 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "/opt/python/run/venv/lib64/python3.6/importlib/__init__.py", line 126, in import_module
  [Thu Jan 16 19:46:50.531382 2020] [:error] [pid 4721] [remote 127.0.0.1:0]     return _bootstrap._gcd_import(name[level:], package, level)
  [Thu Jan 16 19:46:50.531388 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
  [Thu Jan 16 19:46:50.531393 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
  [Thu Jan 16 19:46:50.531399 2020] [:error] [pid 4721] [remote 127.0.0.1:0]   File "&lt;frozen importlib._bootstrap&gt;", line 953, in _find_and_load_unlocked
  [Thu Jan 16 19:46:50.531414 2020] [:error] [pid 4721] [remote 127.0.0.1:0] ModuleNotFoundError: No module named 'debug_toolbar'
  </code></pre>
  
  <p>Notice the ModuleNotFoundError at the end of the log. I have completely uninstalled debug_toolbar from the application as far as I know but somehow the server still believes it is present.</p>
  
  <p>Any assistance that could point me in the right direction would be greatly appreciated.</p>
  
  <p>Edit 1: Whether DEBUG is set to True or False in base.py, I still receive a 500 internal server error.</p>
  
  <p>Edit 2: I believe the problem is to do with versioning but I don't know what to change to correct it and whether it will require me to recreate the entire project or not.</p>
  
  <p>Thanks,<br>
  Joshua.</p>