Configuring mod_wsgi for wamp server on windows
Question: I am new in Django development. I have created an Django application and
tested in development server i.e. 127.0.0.1:8080/mysite. Then I decided to run
this app on Apache server 2.4.9. As all we know the best option is configuring
mod_wsgi. My problem is Apache server never runs after configuring as bellow:

  1. Keep mod_wsgi.so [ downloaded ](https://modwsgi.googlecode.com/files/mod_wsgi-win32-ap22py27-3.3.so)on 'C:\wamp\bin\apache\apache2.4.9\modules\'. 
  2. Insert "LoadModule wsgi_module modules/mod_wsgi.so" to httpd.conf
  3. Restart wamp server

I am using 32 bit of Python,Apache and mod_wsgi. Python is installed for all
user. Please help me -


Answer: First of all copy mod_wgi in modules folder, then add following to httpd.conf
modules list:

    
    
    LoadModule wsgi_module modules/mod_wsgi.so
    

attention that naming is important (should suffix with _module)

Add the following to your httpd.conf

    
    
    Include path_to_your_proj/django_wsgi.conf
    

django_wsgi.conf file:

    
    
     WSGIScriptAlias path_to/django.wsgi
    
    <Directory project_path>
       Allow from all
       Order allow,deny
    </Directory>
    
    Alias /static path_to_static_files
    

django.wsgi file:

    
    
    import os
    import sys
    
    #Calculate the path based on the location of the WSGI script.
    CURRENT_DIR = os.path.dirname(__file__).replace('\\','/')
    PROJECT_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir))
    SETTINGS_DIR = os.path.join(PROJECT_ROOT,'proj_dir_name')
    
    if PROJECT_ROOT not in sys.path:
        sys.path.append(PROJECT_ROOT)
    if SETTINGS_DIR not in sys.path:
        sys.path.append(SETTINGS_DIR)
    
    os.chdir(SETTINGS_DIR)
    os.environ['DJANGO_SETTINGS_MODULE'] = 'proj_name.settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

**If you're using a virtualenv (that I suggest) do as follows:**

httpd.conf file:

    
    
    # virtual env02
    <VirtualHost ip-adddress_or_dns:port_if_other_than_80>
        ServerName just_a_name     # like : app01
        ServerAlias just_an_alias #  like : app01.mydomain.com
        ErrorLog "logs/env02.error.log"
        CustomLog "logs/env02.access.log" combined
        WSGIScriptAlias /  direct_path_to_you_wsgi_with_forward_slashes # like:  C:/virtual/venv01/proj_name/wsgi.py
        <Directory proj_dir_with_forward_slashed>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
        Alias /static path_to_static_folder_with_forward_slashes
        <Directory path_to_static_folder_with_forward_slashes>
            Require all granted
        </Directory>  
    </VirtualHost>
    # end virtual env02
    

wsgi.py file:

    
    
    activate_this = 'c:/virtual/env02/scripts/activate_this.py'
    # execfile(activate_this, dict(__file__=activate_this))
    exec(open(activate_this).read(),dict(__file__=activate_this))
    
    import os
    import sys
    import site
    # Add the site-packages of the chosen virtualenv to work with
    site.addsitedir('c:/Organizer/virtual/env02/Lib/site-packages')
    
    # Add the app's directory to the PYTHONPATH
    sys.path.append('c:/virtual/proj_name')
    sys.path.append('c:/virtual/proj_name/default_app_name')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'default_app_name.settings'
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "default_app_name.settings")
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

