How to deploy a django project in Apache and deploy django in apache

Source: Internet
Author: User
Tags web hosting web hosting services website hosting website hosting services

How to deploy a django project in Apache and deploy django in apache

We have been using django manage until now. py runserver command to run the django application, but this is only our development environment. This is not feasible when the project is actually deployed and launched, we must deploy our project to a specific web server.

Install apache

Apache is a very famous web server software. It is almost impossible for us to run web projects.

Apache Official Website: http://httpd.apache.org/

Select a version for download based on your environment. Apache official website does not have windows 64-bit version, can be downloaded through the following link: win7 64-bit: http://www.apachelounge.com/download/win64/

After the download and installation are complete, the directory structure of apahche is as follows:

Modify the conf/httpd. conf file:

...... ServerRoot "D:/pydj/Apache24 "...... Listen 127.0.0.1: 8089 # modify the port number ...... ServerName www.example.com: 8089 ...... DocumentRoot "D:/pydj/Apache24/htdocs" <Directory "D:/pydj/Apache24/htdocs"> ...... ScriptAlias/cgi-bin/"D:/pydj/Apache24/cgi-bin /"...... <Directory "D:/pydj/Apache24/cgi-bin"> AllowOverride None Options None Require all granted </Directory> ......

If you are not able to start the httpd.exe program of apache, check the configuration.

Start the bin/httpd.exe Program

Access through a browser: http: // 127.0.0.1: 8089/

Now, apache works properly.

Install mod_wsgi

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface.

The module wocould be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.

(The purpose of mod_wsgi is to implement a simple WSGI interface that can be used by any Python application to support Python using the Apache module. This module will be applicable to high-performance production websites of hosts and general self-managed website hosting services .) Google Translate directly.

Mod_wsgi Website: http://code.google.com/p/modwsgi/

: Http://www.lfd.uci.edu /~ Gohlke/pythonlibs/# mod_wsgi

Such as win7 64-bit, python 2.7.6, apache (httpd-2.4.10) corresponding version: mod_wsgi-3.5.ap24.win-amd64-py2.7.zip

Decompress the package and copy the mod_wsgi.so file to the Apache24 \ modules \ directory.

Configure apache and django Projects

Because your directory must be the same as mine, I would like to emphasize my directory:

Apache storage directory: D: \ pydj \ Apache24

Django project directory: D: \ pydj \ myweb

Call the apache configuration file httpd. conf again:

...... # Add mod_wsgi.so module LoadModule wsgi_module modules/mod_wsgi.so # specify wsgi for the myweb project. py configuration file path WSGIScriptAlias/D:/pydj/myweb/wsgi. py # specify the project path WSGIPythonPath D:/pydj/myweb <Directory D:/pydj/myweb> <Files wsgi. py> Require all granted </Files> </Directory>

Modify the preceding path according to your actual situation.

Configure the myweb/wsgi. py file as follows:

……import osos.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb.settings")from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application() 

This information has been automatically generated when we generate the djnago project. In fact, we do not need to make any changes to it.

Open the settings. py file and add:

……ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] 

Start the Apache24/bin/httpd.exe program again

Access through a browser: http: // 127.0.0.1: 8089/

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.