1. install apache2 and libapache2-mod-wsgisudoapt-getinstallapache2libapache2-mod-wsgi2. install Django by downloading it from the official website, decompress it, and install it. This is very easy. it is best not to place the created Project in the default directory of apache when creating a Django project. Here we create a new folder named cdhome in the user folder under the home Directory.
1. Install apache2 and libapache2-mod-wsgi
Sudo apt-get install apache2 libapache2-mod-wsgi
2. Install Django
Download the package from the official website, decompress the package, and install it. This is easy.
3. Create a Django Project
It is best not to place the created Project in the default directory of apache. Here we create a folder under the user folder in the home directory.
Cd home
Cd sh3llc0der
Mkdir work
Then, create a project in the work directory.
Django-admin.py createproject hello
After the creation is successful, a hello project file will be generated, which contains another hello folder and manage. you can use manage. py to run Django's test server, but here we aim to access it through Apache.
4. Configure wsgi
Note that the configuration file after apache installation is located in the "/etc/apache2/sites-available/" directory. The above information is httpd. conf: It's really a pitfall. No one has a try. copy it and copy it. It's just what you mean.
Create a wsgi file:
Sudo nano/home/sh3llc0oder/work/hello/apache/django. wsgi
Write the following content:
Import OS
Import sys
Path = '/home/sh3llc0der/work/hello'
If path not in sys. path:
Sys. path. insert (0, '/home/sh3llc0der/work/hello ')
OS. environ ['django _ SETTINGS_MODULE '] = 'hello. setting'
Import django. core. handlers. wsgi
Application = django. core. handlers. wsgi. WSGIHandler ()
First, modify the host file and point the domain name testmydjango.com to 127.0.0.1.
Now we need to create our own site:
Sudo nano/etc/apache2/sites-available/hello. conf
Write the following content:
ServerName hello. djangoserver
DocumentRoot/home/sh3llc0der/work/hello
/Home/sh3llc0der/work/hello>
Order allow, deny
Allow from all
WSGIDaemonProcess testdjango.com processes = 2 threads = 15 display-name =%{ GROUP}
WSGIProcessGroup testdjango.com
WSGIScriptAlias // home/sh3llc0der/work/hello/apache/django. wsgi
Note that WSGIDaemonProcess and WSGIProcessGroup are our domain names.
Then we activate the created site:
Sudoa2ensitehello
Sudo/etc/init. d/apache2reload
Restart apache
Sudo/etc/init. d/apache2restart
Access testdjango.com
If you encounter a server 403 error, it may be that your "/" directory is disabled (default)
Modify the apache2.conf file (in/etc/apache2 /)
Change Require all denied to Allow from all.
Django details: Click here
Django's: Click here
Recommended reading:
Install Nginx + uWSGI + Django environment http://www.linuxidc.com/Linux/2012-05/60639.htm on Ubuntu Server 12.04
Django practical tutorial http://www.linuxidc.com/Linux/2013-09/90277.htm
Django Python MySQL Linux development environment build http://www.linuxidc.com/Linux/2013-09/90638.htm