Install Django on Apache with mod_wsgi on linux

--> sudo apt-get install python-mysqldb

--> install django

--> sudo apt-get install mysql-server

root/root123

--> sudo apt-get install apache2

--> sudo apt-get install libapache2-mod-wsgi

--> mkdir ~/Documents/sandbox/djcode

--> vim firstweb.wsgi

import os
import sys
sys.path = [‘/var/www/firstweb‘] + sys.path
os.environ[‘DJANGO_SETTINGS_MODULE‘] = ‘firstweb.settings‘
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

--> sudo apt-get install vim

--> cd /etc/apache2/sites-available/

--> sudo -s

--> vim firstweb.conf

<VirtualHost *:80>
WSGIScriptAlias / /home/plex/firstweb.wsgi

ServerName firstweb.com
Alias /static /var/www/firstweb/static/

<Directory /var/www/firstweb/>

Order allow,deny
Allow from all
</Directory>
</VirtualHost>

--> a2ensite firstweb.conf
a2dissite

--> cd /var/www

--> django-admin.py startproject firstweb

--> apachectl restart
or /etc/init.d/apache2 restart
service apache2 reload

--> vi /etc/hosts

--> mysql -u root -p
show databases;
create database firstweb;

--> vim settings.py
DATABASES = {
‘default‘: {
‘ENGINE‘: ‘django.db.backends.mysql‘,
‘NAME‘: ‘firstweb‘,
‘USER‘: ‘root‘,
‘PASSWORD‘: ‘root123‘,
‘HOST‘: ‘‘,
}
}

--> python manage.py syncdb
username: root
password: root123

--> apachectl restart

--> cp -r /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/ /var/www/firstweb/

--> chown -R www-data apc_project_test/

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。