Note that you may need to make further configurations in addition to the ones below in order to make your server safe from hacking. The guide below only covers how to set up the server to get the basics going, and I only used it for testing. One specific example of issues to keep in mind is where you place your Django code. For more info on that see the “Where should this code live” section in the Django tutorial at the following link (replace 1.11 in the link with the Django version number you are using): https://docs.djangoproject.com/en/1.11/intro/tutorial01/
This process has been tested on Windows 7 and Windows XP with Apache HTTP Server 2.2.22 using mod_wsgi 3.3 and Django 1.4.0.
1. Download the 2.2.x version of the Apache HTTP Server named “Win32 Binary including OpenSSL 0.9.8t (MSI Installer)” from here: http://httpd.apache.org/download.cgi
2. If you only want to test your server, follow the “Steps to Installing Apache 2.2 on Windows Vista” found in the link below (step nr. 2 on the website is not necessary for Windows 7): http://www.thesitewizard.com/apache/install-apache-on-vista.shtml
If you want to deploy your webpage on the internet, follow the instructions in the following link instead: http://httpd.apache.org/docs/2.2/platform/windows.html
3. Download the Apache module mod_wsgi for Windows and Apache 2.2 from here: http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2
4. Rename the downloaded file to “mod_wsgi.so”. Then place it in the “\Apache Software Foundation\Apache2.2\modules” folder of your Apache Server installation.
5. Open the conf\httpd.conf file of your Apache installation as an administrator. Then add the text “LoadModule wsgi_module modules/mod_wsgi.so” to the file at the place where the other modules are loaded (i.e. the place where you find many “LoadModule” statements). Also comment out “LoadModule dir_module modules/mod_dir.so” if you don’t want to use its functionality.
6. Restart the Appache server. If all is okay, you should see a line of the form: “[notice] Apache/2.2.22 (Win32) mod_wsgi/3.3 Python/2.7.3 configured — resuming normal operations” in the logs/error.log file of your Apache installation.
7. Copy the Django project’s root folder into the folder you want to use for your server’s files, e.g. “C:\server_files”. Note that Apache runs as a special user on your computer (defined in the conf\httpd.conf file, search for “User” or “Group”), and therefore cannot access your private folders, such as home, documents or desktop (see this presentation for more info). Because of this, always put the server files on a shared location, otherwise you will get a “403 Forbidden” error from the server.
8. At an empty spot in the conf\httpd.conf file of your Apache installation, paste the text below, and replace DJANGO_PROJECT_FOLDER with your Django project folder’s name (e.g. “myproject”), DJANGO_SETTINGS_FOLDER with the name of the Django project’s settings folder (this folder contains settings.py and wsgi.py, usually the name is the same as your project name e.g. “myproject”) and DJANGO_APP_FOLDER with the name of the Django app where you store static files (e.g. “myapp”), assuming you’ve chosen to store the static files within the apps. Also note that all folder-paths have to use UNIX-style “/” instead of Windows style “\”.
# Sets default charset to utf-8. You should make sure AddDefaultCharset is not already set in the conf\httpd.conf file.
# Change Python path used by the server.
# Make calls to http://localhost/ refer to the Python/WSGI-script located at the specified location.
WSGIScriptAlias / “C:/server_files/DJANGO_PROJECT_FOLDER/DJANGO_SETTINGS_FOLDER/wsgi.py”
# Make calls to http://localhost/static refer to the specified folder.
Alias /static “C:/server_files/DJANGO_PROJECT_FOLDER/DJANGO_APP_FOLDER/static”
# Make the file wsgi.py accessible through the server (everything is inaccessible by default).
Allow from all
# Make the specified directory and its content accessible through the server (everything is inaccessible by default).
Allow from all
9. Open the “\server_files\DJANGO_PROJECT_FOLDER\DJANGO_SETTINGS_FOLDER\settings.py” file of the Django project. Locate and update the database settings to match the database on the server. Then run the “manage.py syncdb” command from a terminal/command prompt located at the Django project’s root folder (where manage.py can be found) to set up all the necessary database structures on the server.
10. Restart the Apache server (this must be done every time you want the Apache server to use new or modified files).
11. Navigate to http://localhost/ and the website should load.
Tips and Tricks
> If you run into trouble, this link may contain some solutions: http://pradyumnajoshi.wordpress.com/2009/06/09/setting-up-mod_wsgi-for-apache-and-django-on-windows/
and this link discusses another problem: http://serverfault.com/questions/313770/django-and-wsgi-and-apache2-site-is-perfect-in-test-server-wont-load-with-ap