{"id":678,"date":"2012-06-01T00:00:00","date_gmt":"2012-06-01T00:00:00","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2012\/06\/01\/how-do-i-configure-apache-to-serve-django\/"},"modified":"2021-07-31T16:21:27","modified_gmt":"2021-07-31T16:21:27","slug":"how-do-i-configure-apache-to-serve-django","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/Web-Development\/Django\/how-do-i-configure-apache-to-serve-django.html","title":{"rendered":"How do I configure Apache to serve my Django website ?"},"content":{"rendered":"
In order for Apache to serve your Django website WSGI is configured.<\/p>\n
The Web Server Gateway Interface (WSGI) defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language (wikipedia<\/a>).<\/p>\n Note :<\/em><\/p>\n [root@Fileserver \/]# tree \/opt\/django\/ First the WSGI module is compiled and installed. This is achieved via the following commands,<\/p>\n yum install httpd-devel Next create a new file within ‘\/<django root>\/<project>\/apache\/django.wsgi’.<\/p>\n cd \/opt\/django Within django.wsgi add the following :<\/p>\n import os, sys<\/p>\n path = ‘\/opt\/django\/yourproject’ os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘settings’<\/p>\n import django.core.handlers.wsgi<\/p>\n application = django.core.handlers.wsgi.WSGIHandler()<\/p>\n Within the Apache configuration file ‘\/etc\/httpd\/conf\/httpd.conf’ add the following line,<\/p>\n LoadModule wsgi_module modules\/mod_wsgi.so<\/p>\n Next create a new file ‘\/etc\/httpd\/conf.d\/django.conf’. This new file will contain,<\/p>\n # <VirtualHost *:80> <Directory \/opt\/django\/yourproject\/apache> Once done restart the Apache daemon by running the command ‘\/etc\/init.d\/httpd restart’.<\/p>\n","protected":false},"excerpt":{"rendered":" Summary In order for Apache to serve your Django website WSGI is configured. The Web Server Gateway Interface (WSGI) defines a simple and universal interface between web servers and web applications or frameworks for the Python programming language (wikipedia). Note : The following steps are based on a Linux Centos based distro. The following steps within … Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"yoast_head":"\n\n
\/opt\/django\/
|– yourproject
| | |– TEMPLATES
| | |– input.html
| | |– output.html
| |– __init__.py
| |– __init__.pyc
| |– apache<\/strong>
| | `– django.wsgi<\/strong>
| |– manage.py
| |– yourapp
| | |– __init__.py
| | |– __init__.pyc
| | |– models.py
| | |– models.pyc
| | |– tests.py
| | |– views.py
| | `– views.pyc
| |– settings.py<\/strong>
| |– settings.pyc
| |– urls.py
| `– urls.pyc<\/p>\nCompile<\/strong><\/h3>\n
yum install python-devel
cd ~
wget
tar -xvzf mod_wsgi-3.3.tar.gz
cd mod_wsgi-3.3
.\/configure
make
make install<\/p>\nConfigure Django<\/strong><\/h3>\n
cd project
mkdir apache ; cd apache<\/p>\n
if path not in sys.path:
sys.path.append(path)<\/p>\nConfigure Apache<\/strong><\/h3>\n
# Django settings.
#
NameVirtualHost *<\/p>\n
ServerAlias tools.www.fir3net.com
WSGIScriptAlias \/ \/opt\/django\/yourproject\/apache\/django.wsgi<\/p>\n
Order deny,allow
Allow from all
<\/Directory>
<\/VirtualHost><\/p>\n