how to run Django application in apache2
NickName:Rakesh Ask DateTime:2011-03-09T21:03:40

how to run Django application in apache2

Hi All i am not able to run a django application in apache2 webserver. I have went through all the document but it still did not work for me.This is my Apache2's httpd.conf file

<Location "/mysite/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonOption django.root /mysite
  PythonPath "['/home/djangotest/mysite'] + sys.path"
  PythonDebug On
</Location>

My django project location is at /home/djangotest/mysite in which i am running the polls application. Is there something i have to mention in settings.py or urls.py for this to work in apache2 it works fine in the dev server. or is there configuration i have to do in apache2 to work

Copyright Notice:Content Author:「Rakesh」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5246181/how-to-run-django-application-in-apache2

Answers
Nix 2011-03-09T13:08:16

\nDownload and install http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz\nAdd to the /etc/httpd/conf.d/ directory\n\n\n\n\n<VirtualHost *:80>\n ServerName --insert--\n\n ErrorLog /home/djangotest/mysite/error_log\n CustomLog /home/djangotest/mysite/access_log combined\n\n UseCanonicalName Off\n\n WSGIScriptAlias /g2 /home/djangotest/mysite/mysite.wsgi\n WSGIDaemonProcess iproj processes=7 threads=1 display-name=%{GROUP}\n\n</VirtualHost>\n\n\n\nAdd to LoadModules secion in /etc/httpd/conf/httpd.conf\n\nLoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so\nAdd to AddHandler section in /etc/httpd/conf/httpd.conf\n\nAddHandler wsgi-script .wsgi\nMake sure your the httpd user can access /home/djangotest/ as well as execute your python scripts\nCreate a mysite.wsgi file:\n\n\n\n\nimport os\nimport sys\n\nsys.path.append('/home/djangotest/mysite')\nos.environ['DJANGO_SETTINGS_MODULE'] = 'settings'\n\nimport django.core.handlers.wsgi\napplication = django.core.handlers.wsgi.WSGIHandler()\n\n\nOr as @Efazati said, read the manual ;)\n\n\n\nHopefuly this solves your final issue:\n\n\n no module named mysite.urls but there is a file urls.py\n\n\nCheck your settings file for \n\n\n ROOT_URLCONF = \"mysite.urls\"\n\n\nThis is the name of your urls file, I am guessing you dont have a module called mysite.urls.py ? It sounds like your property should read:\n\n\n ROOT_URLCONF = \"urls\"\n",


gladysbixly 2011-03-09T16:26:22

Try to add '/home/djangotest' to PythonPath:\n\n<Location \"/mysite/\">\n\n SetHandler python-program\n PythonHandler django.core.handlers.modpython\n SetEnv DJANGO_SETTINGS_MODULE mysite.settings\n PythonOption django.root /mysite\n PythonPath \"['/home/djangotest', '/home/djangotest/mysite'] + sys.path\"\n\n PythonDebug On\n</Location>\n\n\nYou need to add that if you import your project's files with the syntax ..\nThe other guys here are right, though; switch to mod-wsgi if you can. Django's mod_python support will be deprecated very soon. http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/\n\nedit: mod_python support is deprecated in Django 1.3, and will be removed entirely on Django 1.5.",


More about “how to run Django application in apache2” related questions

how to run Django application in apache2

Hi All i am not able to run a django application in apache2 webserver. I have went through all the document but it still did not work for me.This is my Apache2's httpd.conf file &lt;Location "/mys...

Show Detail

Django on Apache2, django-wkhtmltopdf without celery run shell subprocess

In the past in order to make any os binary calls from Django over WSGI on Apache2 with a Debian server, I've had to use celeryd to queue the message, open a subprocess (Apache2 would not create a new

Show Detail

How to run Django app with Apache2, mod_wsgi and Anaconda?

I'm trying to run a django application with Apache2, wsgi_mod, Anaconda environment with Python3.8 in Ubuntu. When I run 'sudo service apache2 start' , the page keeps re-loading and the same error

Show Detail

How to configure apache2 for django wsgi?

i was trying to run my django application using apache2 and i failed. Its giving me a 500 internal server error saying The server encountered an internal error or misconfiguration and was unable to

Show Detail

How can I run django using apache2?

I'm trying to run django on apache2 using mod_wsgi, but when I'm trying to connect "locatoka.ru" I get "Forbidden You don't have permission to access / on this server." My actions: I added to httpd.

Show Detail

Implement Apache2 + Django + Vuejs into one platform

I am stuck with the Integration of Django and vuejs with apache2 into one single application. Basically python manage.py runserver can run the django. Instead of running python manage.py runserver

Show Detail

how to deploy ec2 instance using ASGI django application (apache2 production)

please any one help to solve this issues how to deploy ec2 instance using ASGI django application (apache2 production) .

Show Detail

Host a Django project on Apache2 locally

I have finished a Django project and want to deploy it over Apache2 locally over LAN. I have figured out how to connect Django with Apache2 using mod_wsgi and it worked great because I was able to ...

Show Detail

django nginx gunicorn application showing apache2 default page - only on ip request not domain name

Very odd behavior from my Ubuntu 18.04 LTS server I have followed this tutorial here (twice) and it is all working properly except a couple odd things firstly, when I use my browser to visit the IP...

Show Detail

Deploy django app on ubuntu apache2

I want to run my Django app created in virtualenv on ubuntu with python3. Folder structure in virtualenv folder: -bin -include -lib -myapp -share pip-selfcheck.json The myapp folder contains..

Show Detail