python - Unable to run Django project under Apache -
i have django project nice , running @ 127.0.0.1:8000. run via:
$ python manage.py runserver
now, want run under apache
.
this tried:
installed , enabled mod_wsgi. working indeed, because when installed saw in console:
"apache2_invoke: enable module wsgi"
edited
000-default.conf
file in way:<virtualhost *:80> wsgiscriptalias / /home/jacobian/django/apps/apps/wsgi.py <directory /home/jacobian/django/apps/apps/> <files wsgi.py> require granted </files> </directory> errorlog ${apache_log_dir}/error.log customlog ${apache_log_dir}/access.log combined
that's it. i'm not sure i'missing, after restart apache
, go localhost
, in browser see page /var/www
folder. whereas expect see django application. guess need edit apache2.conf
(how?) , other magic tricks (like download , install magic stuff, make magic apache configuration etc).
i tried dozens of tutorial, none of them helped - either apache not restarted or django project not rendered in browser. so, need basic steps follow make work.
edit
when try start apache without tag files
inside tag directory
, apache fails that, @ same time see no additional messages in error.log
. if, however, use tag like:
<directory /home/jacobian/django/apps/apps/> <files wsgi.py> require granted </files> </directory>
then bunch of error messages in error.log
. whole list:
[mon sep 21 13:55:45.901935 2015] [wsgi:warn] [pid 39222:tid 140543251101568] mod_wsgi: compiled python/2.7.8. [mon sep 21 13:55:45.901995 2015] [wsgi:warn] [pid 39222:tid 140543251101568] mod_wsgi: runtime using python/2.7.9. [mon sep 21 13:55:45.902149 2015] [mpm_event:notice] [pid 39222:tid 140543251101568] ah00489: apache/2.4.10 (ubuntu) mod_wsgi/4.3.0 python/2.7.9 configured -- resuming normal operations [mon sep 21 13:55:45.902186 2015] [core:notice] [pid 39222:tid 140543251101568] ah00094: command line: '/usr/sbin/apache2' [mon sep 21 13:55:46.851442 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] mod_wsgi (pid=41314): target wsgi script '/home/jacobian/django/apps/apps/wsgi.py' cannot loaded python module. [mon sep 21 13:55:46.851498 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] mod_wsgi (pid=41314): exception occurred processing wsgi script '/home/jacobian/django/apps/apps/wsgi.py'. [mon sep 21 13:55:46.851526 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] traceback (most recent call last): [mon sep 21 13:55:46.851557 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/home/jacobian/django/apps/apps/wsgi.py", line 14, in <module> [mon sep 21 13:55:46.851696 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] application = get_wsgi_application() [mon sep 21 13:55:46.851734 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/usr/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application [mon sep 21 13:55:46.851800 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] django.setup() [mon sep 21 13:55:46.851818 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/usr/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup [mon sep 21 13:55:46.851874 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] configure_logging(settings.logging_config, settings.logging) [mon sep 21 13:55:46.851892 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__ [mon sep 21 13:55:46.851994 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] self._setup(name) [mon sep 21 13:55:46.852013 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup [mon sep 21 13:55:46.852038 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] self._wrapped = settings(settings_module) [mon sep 21 13:55:46.852053 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] file "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 98, in __init__ [mon sep 21 13:55:46.852072 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] % (self.settings_module, e) [mon sep 21 13:55:46.852097 2015] [wsgi:error] [pid 41314:tid 140543032010496] [client 127.0.0.1:50601] importerror: not import settings 'apps.settings' (is on sys.path? there import error in settings file?): no module named apps.settings
i'm not sure can wrong wsgi.py
file. it's standard file created $ django-admin startproject apps
. miss wsgipythonpath
variable in apache conf
file. i'm not sure should point in real world case , not in abstract case. if follow tutorials , set wsgipythonpath /home/jacobian/django/apps/
, apache unable start. so, not know can do.
usually easy configure apache2 + wsgi django; if miss out step can cumbersome trace out issue; try iterate on steps mentioned below, trace out issue.
please find django documenatation on here.
here steps might want try:
[edit fit user needs]
*renamed fields make more easier understand
lets created django project in /home/jacobian/django/
django_project/ |-- django_project | |-- __init__.py | |-- settings.py | |-- urls.py | |-- wsgi.py `-- manage.py
it should similar above tree path wsgi specified in apache be:
/home/jacobian/django/django_project/django_project/wsgi.py
or in other terms
project_path mean /home/jacobian/django/
project_name mean django_project
[specific ubuntu]
install apache
apt-get install apache2
install mod_wsgi
apt-get install libapache2-mod-wsgi
make wsgi handler script; usaully go depending on version of django installation:
import os os.environ.setdefault("django_settings_module", "django_project.settings") django.core.wsgi import get_wsgi_application application = get_wsgi_application()
put in apache conf writing new file
sitename.conf
in/etc/apache2/sites-available/
<virtualhost *:80> wsgiscriptalias / project_path/project_name/project_name/wsgi.py alias /static project_path/project_name/static/ alias /media project_path/project_name/media/ servername www.example.com <directory /> options -indexes </directory> <directory project_path/project_name/> order allow,deny allow options -indexes </directory> </virtualhost>
enable site
sudo a2ensite sitename.conf
restart apache
sudo service apache2 restart
Comments
Post a Comment