I have tried to figure this out for a day now and cannot seem to make any headway.
I'm getting the following Apache error:
[wsgi:error] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
[wsgi:error] Did you install mysqlclient?
[wsgi:error] [remote 10.10.10.90:35990] mod_wsgi (pid=14165): Target WSGI script '/var/www/vhosts/project_vision/web/web/wsgi.py' does not contain WSGI application 'application'.
pip3 freeze states mysql-connector and mysql-connector-python is installed. The mysql-connector-python versions matches mysql-community rpm's installed.
File structure is this (web is the name of the Django project within the larger Project_vision project):
/var/www/vhosts/project_vision
|- venv/
|- web/
|- static
|- templates
|- vision_web
|- models/
|- migrations/
|- ...
|- web
|- settings.py
|- wsgi.py
|- ...
/var/www/vhosts/project_vision/web/web/wsgi.py
import os
import signal
import sys
import time
import traceback
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/vhosts/project_vision')
sys.path.append('/var/www/vhosts/project_vision/web')
sys.path.append('/var/www/vhosts/project_vision/venv')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'web.settings')
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
/etc/httpd/conf.d/vision.conf
<VirtualHost *:80>
ServerName my_project_vision.com
DocumentRoot /var/www/vhosts/project_vision/web
Alias /static/ /var/www/vhosts/project_vision/web/static/
<Directory /var/www/vhosts/project_vision/web/static>
Require all granted
</Directory>
WSGIDaemonProcess my_project_vision.com \
processes=2 threads=15 display-name=%{GROUP} \
python-home=/var/www/vhosts/project_vision/venv \
python-path=/var/www/vhosts/project_vision/web
WSGIProcessGroup my_project_vision.com
WSGIApplicationGroup %{GLOBAL}
# Insert the full path to the wsgi.py-file here
WSGIScriptAlias / /var/www/vhosts/project_vision/web/web/wsgi.py
<Directory /var/www/vhosts/project_vision>
AllowOverride all
Require all granted
Options FollowSymlinks
</Directory>
</VirtualHost>
Where in the world am I going wrong? It must be something minor but important...
Related
I'm very new in django and I am in deploying phase of a project. But after all setup, it shows 500 internal server error and the apache2 error log says ImportError: No module named 'backend'
I tried to edit wsgi.py as I thik this is the one giving this error
this is content of my wsgi.py file
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
application = get_wsgi_application()
settings/dev.py
DEBUG = True
ALLOWED_HOSTS = ['my_ip_address']
WSGI_APPLICATION = 'backend.wsgi.application'
manage.py
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.dev')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Directory Structure:
atms
--backend
--wsgi.py
--urls.py
--settings
--dev.py
--manage.py
pip freeze:
cairocffi==0.9.0
CairoSVG==2.2.1
cffi==1.11.5
cssselect2==0.2.1
defusedxml==0.5.0
Django==2.1.5
django-countries==5.3.2
django-weasyprint==0.5.4
djangorestframework==3.9.1
gunicorn==19.9.0
html5lib==1.0.1
Pillow==5.4.1
pycparser==2.19
Pyphen==0.9.5
pytz==2018.9
six==1.12.0
tinycss2==0.6.1
WeasyPrint==44
webencodings==0.5.1
whitenoise==4.0
atms.conf in /etc/apache2/sites-avalible
Alias /static /home/atms/atms/public/static
<Directory /home/atms/atms/public/static>
Require all granted
</Directory>
Alias /media /home/atms/atms/media
<Directory /home/atms/atms/media>
Require all granted
</Directory>
<Directory /home/atms/atms/backend>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/atms/atms/backend/wsgi.py
WSGIDaemonProcess django_app python-path=/home/atms/atms/backend python-home=/home/atms/venv
WSGIProcessGroup django_app
the error log says
ImportError: No module named 'backend'
You've put backend directly on your python-path, which means that is not itself an importable name. You should put the parent directory there instead:
WSGIDaemonProcess django_app python-path=/home/atms/atms python-home=/home/atms/venv
I'm trying to deploy a django project on CentOS 7, but I keep getting ImportError: No module named site on my httpd error log.
This is my config file for httpd located at /etc/httpd/conf.d:
<VirtualHost *:8008>
WSGIProcessGroup programa_registos
WSGIDaemonProcess programa_registos python-home=/var/www/html/programa_registos/.env python-path=/var/www/html/programa_registos
Alias /static /var/www/html/programa_registos/static
<Directory /var/www/html/programa_registos/static>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/programa_registos/programa_registos/wsgi.py
<Directory /var/www/html/programa_registos/programa_registos>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
My project is located at /var/www/html/programa_registos and my virtualenv at /var/www/html/programa_registos/.env.
Here is my wsgi.py file, located at /var/www/html/programa_registos/programa_registos:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "programa_registos.settings")
application = get_wsgi_application()
I am a newbie to Django, trying to test run with Apache and mod_wsgi with Windows.
This is my httpd conf:
WSGIScriptAlias /hm "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite/wsgi.py"
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/mysite/mysite">
Options Indexes FollowSymLinks +ExecCGI
Order deny,allow
Allow from all
Allow from all
AddHandler wsgi-script .py
</Directory>
I have this project structure:
mysite
-manage.py
-mysite
-settings.py
-wsgi.py
In my wsgi, I have:
import os, sys
base = os.path.dirname(os.path.dirname(__file__))
sys.path.append(base +"\\mysite" )
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Why do I get import error: no module named mysite ?
I am running a site that was previously running on django 1.4, but now I shifted it on django 1.6.
I am able to run my site on both version using python manage.py shell.
I am running it nicely on Apache when i keep django 1.4 virtual environment python path in Apache site-enabled, but it does not work when i keep django 1.6 virtual environment python path there.
For django 1.6 it throws error:
ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
What can be problem? Any changes required in wsgi.py file for django 1.6? Please help.
my virtualhost file is :
<VirtualHost *:80>
ServerAdmin vidya.sagar0911#gmail.com
DocumentRoot /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/
ServerName www.vidblog.com
<Directory /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo>
#Order deny,allow
#Allow from all
Options FollowSymLinks
AllowOverride None
</Directory>
Alias /media /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/vidyamedia/
Alias /static /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/static/
WSGIDaemonProcess www.demo.com user=www-data group=www-data processes=8 threads=75\
python-path=/home/vidya/workspace/djnago1.6/lib/python2.7/site-packages
WSGIProcessGroup www.vidblog.com
WSGIScriptAlias / /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/demo/wsgi.py
</VirtualHost>
This is the issue when you are migrating your old projects from django-1.x(<1.6) to django-1.6 you need to define DJANGO_SETTINGS_MODULE before you call get_wsgi_application
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I get an 500 internal server error and in the log files it writes:
[Thu Jun 14 16:30:22 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings
here is my httpd.conf:
ServerName localhost
<VirtualHost *:80>
ServerAdmin ttt#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite/
LogLevel warn
WSGIDaemonProcess processes=2 maximum-requests=500 threads=1
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
Alias /media /var/www/mysite/mysite/static/media/
</VirtualHost>
wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
This problem is covered in both the mod-wsgi documentation http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango and the Django deployment documentation https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/ which note that the project must be on your Python path. You can use the WSGIPythonPath directive or set the python-path in your WSGIDaemonProcess directive from the Django documentation. Or you can add it to the sys.path in your wsgi file as the mod-wsgi docs state.