I don't even know how much I tried to deploy a django app with apache and mod_wsgi but still gets the same error again and again, this is wsgi.py file:
"""
WSGI config for progress_bar project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/tone/entornos/progressbar/lib/python2.7/site-packages')
sys.path.append('/var/www/html/progress_bar/progress_bar')
sys.path.append('/var/www/html/progress_bar')
# Add virtualenv and activate for apache
activate_env=os.path.expanduser("/home/tone/entornos/progressbar/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "progress_bar.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
And virtual-host config:
<VirtualHost *:80>
#WSGIDaemonProcess python-path=/home/tone/entornos/progressbar/lib/python2.7/site-packages
#WSGIPythonPath /home/tone/entornos/progressbar/bin:/home/tone/entornos/progressbar/lib/python2.7/site-packages
WSGIScriptAlias /progress-django-upload /var/www/html/progress_bar/progress_bar/wsgi.py
<Directory /var/www/html/progress_bar>
Require all granted
</Directory>
</VirtualHost>
But always I tried to acces I have a nice error 500 and log says the same:
[Fri Mar 13 13:19:12.427639 2015] [:error] [pid 4217] [client 150.214.108.153:50376] mod_wsgi (pid=4217): Target WSGI script '/var/www/html/progress_ba$
[Fri Mar 13 13:19:12.427799 2015] [:error] [pid 4217] [client 150.214.108.153:50376] mod_wsgi (pid=4217): Exception occurred processing WSGI script '/v$
[Fri Mar 13 13:19:12.427894 2015] [:error] [pid 4217] [client 150.214.108.153:50376] Traceback (most recent call last):
[Fri Mar 13 13:19:12.427981 2015] [:error] [pid 4217] [client 150.214.108.153:50376] File "/var/www/html/progress_bar/progress_bar/wsgi.py", line 24,$
[Fri Mar 13 13:19:12.428421 2015] [:error] [pid 4217] [client 150.214.108.153:50376] execfile(activate_env, dict(__file__=activate_env))
[Fri Mar 13 13:19:12.428567 2015] [:error] [pid 4217] [client 150.214.108.153:50376] IOError: [Errno 13] Permission denied: '/home/tone/entornos/progre$
[Fri Mar 13 13:19:14.450602 2015] [:error] [pid 4216] [client 150.214.108.153:50377] mod_wsgi (pid=4216): Target WSGI script '/var/www/html/progress_ba$
[Fri Mar 13 13:19:14.450722 2015] [:error] [pid 4216] [client 150.214.108.153:50377] mod_wsgi (pid=4216): Exception occurred processing WSGI script '/v$
[Fri Mar 13 13:19:14.450811 2015] [:error] [pid 4216] [client 150.214.108.153:50377] Traceback (most recent call last):
[Fri Mar 13 13:19:14.450889 2015] [:error] [pid 4216] [client 150.214.108.153:50377] File "/var/www/html/progress_bar/progress_bar/wsgi.py", line 24,$
[Fri Mar 13 13:19:14.451162 2015] [:error] [pid 4216] [client 150.214.108.153:50377] execfile(activate_env, dict(__file__=activate_env))
[Fri Mar 13 13:19:14.451249 2015] [:error] [pid 4216] [client 150.214.108.153:50377] IOError: [Errno 13] Permission denied: '/home/tone/entornos/progre$
Before you answer... yes, I set permission for apache with chown -R apache:apache /home/tone/entornos/progressbar/bin even to activate_this.py to chomd 777 ... and even disable SELinux temporaly for this and nothing... always the same with permissions... some one has the magic wand for this problem?
Regards!
Finally sudo chmod -R 755 /home/tone did the work! I don't know if it's a good practice to do that, simply grant permission all groups for read and execution of entire home directory but well, it's a good workaround for now.
Related
I have been trying to move a django project on my Linode server into production. After trying to use Apache and wsgi by following an online tutorial by Corey Schafer, I have encountered the following problem. I cannot for the life of my understand why this is happening, and have included error logs, my wsgi.py and my .conf file below.
[Tue Sep 29 23:20:35.753537 2020] [wsgi:error] [pid 143850:tid 140318623627008] [remote 90.214.108.58:50288] from django.core.wsgi import get_wsgi_application
[Tue Sep 29 23:20:35.753556 2020] [wsgi:error] [pid 143850:tid 140318623627008] [remote 90.214.108.58:50288] ModuleNotFoundError: No module named 'django'
[Tue Sep 29 23:28:18.507904 2020] [mpm_event:notice] [pid 143849:tid 140318652456000] AH00491: caught SIGTERM, shutting down
[Tue Sep 29 23:28:18.590367 2020] [mpm_event:notice] [pid 143989:tid 139664706964544] AH00489: Apache/2.4.41 (Ubuntu) mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
[Tue Sep 29 23:28:18.590439 2020] [core:notice] [pid 143989:tid 139664706964544] AH00094: Command line: '/usr/sbin/apache2'
[Tue Sep 29 23:28:24.089588 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] mod_wsgi (pid=143990): Failed to exec Python script file '/home/myname/projects/uw5-backend/u>
[Tue Sep 29 23:28:24.089643 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] mod_wsgi (pid=143990): Exception occurred processing WSGI script '/home/myname/projects/uw5-b>
[Tue Sep 29 23:28:24.095135 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] Traceback (most recent call last):
[Tue Sep 29 23:28:24.095172 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] File "/home/myname/projects/uw5-backend/uw5tables/wsgi.py", line 13, in <module>
[Tue Sep 29 23:28:24.095178 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] from django.core.wsgi import get_wsgi_application
[Tue Sep 29 23:28:24.095195 2020] [wsgi:error] [pid 143990:tid 139664678135552] [remote 90.214.108.58:50411] ModuleNotFoundError: No module named 'django'
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
# add the hellodjango project path into the sys.path
sys.path.append('home/myname/projects/uw5-backend')
# add the virtualenv site-packages path to the sys.path
sys.path.append('home/myname/projects/uw5-backend/venv2/bin')
# poiting to the project settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uw5tables.settings')
application = get_wsgi_application()
.conf
<Directory /home/myname/projects/uw5-backend/uw5tables>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/myname/projects/uw5-backend/uw5tables/wsgi.py
WSGIDaemonProcess django_app python-path=/home/myname/projects/uw5-backend python-home=/home/myname/projects/uw5-backend/venv2
WSGIProcessGroup django_app
</VirtualHost>
I'm deploying a Django web app on ubuntu server. Configuration are set. But, somehow, it show an 500 Internal Server Error. I checked the apache error log and found the following error entry :
[Tue Mar 26 08:50:56.540300 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Target WSGI script '/var/www/backend/backend/wsgi.py' cannot be loaded as Python module.
[Tue Mar 26 08:50:56.540376 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Exception occurred processing WSGI script '/var/www/backend/backend/wsgi.py'.
[Tue Mar 26 08:50:56.540498 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] Traceback (most recent call last):
[Tue Mar 26 08:50:56.540542 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] File "/var/www/backend/backend/wsgi.py", line 12, in <module>
[Tue Mar 26 08:50:56.540553 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] from django.core.wsgi import get_wsgi_application
[Tue Mar 26 08:50:56.540584 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] ImportError: No module named 'django'
I have tried the solutions for the same error found on stackoverflow. Is there anything I'm still missing on these configurations ?
Apache Configuration
Listen 8000
<VirtualHost *:8000>
WSGIDaemonProcess backendapp python-home=/var/www/backend/venv python-path=/var/www/backend
WSGIProcessGroup backendapp
WSGIPassAuthorization On
WSGIScriptAlias / /var/www/backend/backend/wsgi.py
ErrorLog /var/www/backend/error.log
CustomLog /var/www/backend/access.log combined
</VirtualHost>
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
application = get_wsgi_application()
using python 3.6 and mod_wsgi is enabled on server.
I'm trying to run a simple app on AWS AMI that should use OpenCV library. I created a virtual machine and i installed OpenCV. For the installation I followed this tutorial http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/ and seems to be ok also because I able to run the example. The problem arises when I try to run my Flask-app because I'm getting the following error:
[Tue Sep 20 09:58:14.117753 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] Traceback (most recent call last):
[Tue Sep 20 09:58:14.117778 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.wsgi", line 25, in <module>
[Tue Sep 20 09:58:14.117822 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from app import app as application
[Tue Sep 20 09:58:14.117831 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/app.py", line 13, in <module>
[Tue Sep 20 09:58:14.117878 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from flask import (Flask, abort, flash, g, jsonify, make_response, render_template, request, session, url_for)
[Tue Sep 20 09:58:14.117887 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/flask/__init__.py", line 19, in <module>
[Tue Sep 20 09:58:14.117916 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2 import Markup, escape
[Tue Sep 20 09:58:14.117923 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
[Tue Sep 20 09:58:14.117951 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2.environment import Environment, Template
[Tue Sep 20 09:58:14.117965 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
[Tue Sep 20 09:58:14.118148 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2 import nodes
[Tue Sep 20 09:58:14.118157 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
[Tue Sep 20 09:58:14.118287 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from jinja2.utils import Markup
[Tue Sep 20 09:58:14.118296 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] File "/var/www/flaskapp/env/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module>
[Tue Sep 20 09:58:14.118418 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] from markupsafe import Markup, escape, soft_unicode
[Tue Sep 20 09:58:14.118436 2016] [:error] [pid 15068] [remote 77.246.17.229:18121] ImportError: No module named markupsafe
but I checked all the installed modules on the virtual machine with the command pip freeze i get the following:
click==6.6
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
numpy==1.11.1
Werkzeug==0.11.11
So MarkupSafe is installed and updated a the last version.
So started thinking the problem could be in my .wgsi file or in the httpd.conf
Here app.wsgi:
import sys
import site
import os
# Add virtualenv site packages
site.addsitedir(os.path.join(os.path.dirname(__file__), '/var/www/flaskapp/env/lib/python2.7/site-packages'))
#activate_this = '/var/www/flaskapp/env/bin/activate_this.py'
#execfile(activate_this, dict(__file__=activate_this))
# Path of execution
sys.path.insert(0,'/var/www/flaskapp')
#import the app
from app import app as application
And this one is the httpd.conf:
Listen 80
<VirtualHost *>
ServerName ec2...
WSGIDaemonProcess app threads=5 home=/var/www/flaskapp/ python-path=/var/www/flaskapp/env/lib/python2.7/site-packages threads=1
DocumentRoot /var/www/flaskapp
WSGIScriptAlias / /var/www/flaskapp/app.wsgi
<Directory /var/www/flaskapp>
WSGIProcessGroup app
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
But I'm not able to figure out the problem. Any idea about why I get this error?
If I try to reference my app.wgsi to lib64 instead of just lib the error becomes : ImportError: numpy.core.multiarray failed to import. I checked the differente site-packages present in lib and lib64 and I have this configuration:
lib :
click - easy_install.pyc - itsdangerous.py - markerlib - setuptools - click-6.6-py2.7.egg-info - flask - itsdangerous.pyc - pip - setuptools-12.0.5.dist-info - cv2.so - Flask-0.11.1.dist-info - jinja2 - pip-6.0.8.dist-info - werkzeug - easy_install.py - itsdangerous-0.24-py2.7.egg-info - Jinja2-2.8.dist-info - pkg_resources - Werkzeug-0.11.11.dist-info
while in lib64 I have:
markupsafe MarkupSafe-0.23-py2.7.egg-info numpy numpy-1.11.1-py2.7.egg-info
It seems the mod_wsgi is configured for python 2.6.9 and I'm using python 2.7. could that be the problem?
You cannot take a mod_wsgi compiled for Python 2.6 and try and force it to use a Python virtual environment using Python 2.7. You will need to uninstall mod_wsgi and reinstall it from a binary package or source, but where it is compiled for Python 2.7. It is not a configuration option to change what version of Python is used. It must be compiled for the correct Python version to start with.
The goal is to run Django in daemon mode on Apache via WSGI. I plan to run it on port 8000 to keep it separate from PHP files running at the root of server's URL (unless there's a better way to keep my web applications separate). It's setup with Virtualenv.
Server is named server.family.local
The simplified file structure is:
/home
/wwww
/django
/my_project
/app1
/app2
/project
wsgi.py
/env
/lib
/python3.5
/site-packages
The system runs properly when I activate the Virtualenv and use the manage.py file:
/home/www/django/my_project/manage.py runserver 0.0.0.0:8000
I'm trying to setup the WSGI on Apache so I don't have to manually run that command every time. My wsgi.py file consists of this:
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/www/django/my_project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
The VirtualHost file for Apache, server_django.conf, has this:
<VirtualHost *:8000>
WSGIScriptAlias / /home/www/django/my_project/project/wsgi.py
WSGIProcessGroup my_project
WSGIDaemonProcess my_project python-path=/home/www/django/my_project/vision:/home/www/django/env/lib/python3.5/site-packages
Alias /static /home/www/django/my_project/project/static
<Directory /home/www/django/my_project/project/static>
Require all granted
</Directory>
<Directory /home/www/django/my_project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
I've enabled the site using a2ensite. I checked that I have only libapache2-mod-wsgi-py3 installed (not libpache2-mod-python or libpache2-mod-wsgi). I think permissions are safe. Owner is my name but group is www, which is what Apache uses. The virtualenv directory has the same owner, group, and 775 permissions tag. The Python version could be an issue but I don't think it should be. When I'm in the virtualenv and run python -V, I get Python 3.5.1+. Outside the virtualenv, I get Python 2.7.12. My understanding is that this is why we use virtualenv - to isolate versions. So, if the Apache Virtual Host and the wsgi.py files are configured correctly, this shouldn't be the problem (I think).
When I try to reach my site at http://server.family.local:8000 I get a 500 Internal Server Error and find the following statements in the Apache error log.
[Wed Jul 27 22:56:05.850055 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:05.850199 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:05.850645 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:05.850721 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:05.850735 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:05.850787 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.062315 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.062405 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.062573 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.062625 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.062637 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.062684 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.467512 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.467594 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.467757 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.467809 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.467822 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.467868 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
[Wed Jul 27 22:56:06.658228 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Target WSGI script '/home/www/django/my_project/project/wsgi.py' cannot be loaded as Python module.
[Wed Jul 27 22:56:06.658312 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] mod_wsgi (pid=1003): Exception occurred processing WSGI script '/home/www/django/my_project/project/wsgi.py'.
[Wed Jul 27 22:56:06.658476 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] Traceback (most recent call last):
[Wed Jul 27 22:56:06.658527 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] File "/home/www/django/my_project/project/wsgi.py", line 13, in <module>
[Wed Jul 27 22:56:06.658540 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] from django.core.wsgi import get_wsgi_application
[Wed Jul 27 22:56:06.658587 2016] [wsgi:error] [pid 1003] [remote 192.168.14.185:3382] ImportError: No module named 'django'
I'm not an expert but seems that the problem starts with it's unable to load the wsgi.py file but I can't see why that would be any problem. Any help would be great. Thank you.
I've pushed my Flask app to ElasticBeanstalk but am getting 500 errors on every page and Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module. showing up in /var/log/httpd/error_log.
Here's the full stacktrace in /var/log/httpd/error_log:
[Wed Mar 18 22:02:36.815358 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] mod_wsgi (pid=21701): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Wed Mar 18 22:02:36.815389 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] mod_wsgi (pid=21701): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.
[Wed Mar 18 22:02:36.815410 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] Traceback (most recent call last):
[Wed Mar 18 22:02:36.815435 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] File "/opt/python/current/app/application.py", line 5, in <module>
[Wed Mar 18 22:02:36.815466 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] from charts import *
[Wed Mar 18 22:02:36.815478 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] File "/opt/python/current/app/charts.py", line 6, in <module>
[Wed Mar 18 22:02:36.815494 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] from scipy.stats import linregress
[Wed Mar 18 22:02:36.815514 2015] [:error] [pid 21701] [remote 50.23.**2.10:0] ImportError: No module named scipy.stats
Here's what the first portion of my application.py looks like:
from flask import Flask, jsonify, request
import os
import logging
from logging import StreamHandler
from charts import *
application = app = Flask(__name__)
I'm assigning my flask app to the application object, which is all the docs say I need to do. Any clue what I'm doing wrong?
Thanks!