My setup of a python3 django environment in Ubuntu 14.04

First setup a few essentail packages that is needed:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential apache2 python3-dev mysql-server
sudo apt-get install python-pip libapache2-mod-wsgi-py3
sudo pip install virtualenv
sudo pip install virtualenvwrapper

login to mysql server and

CREATE DATABASE django;

To make virtualenvwrapper starts automatically, add

source /usr/local/bin/virtualenvwrapper.sh

to .bashrc;
Make django virtual environment:

mkvirtualenv --python=/usr/bin/python3 django
workon django
pip install django
pip install mysqlclient
django-admin startproject django

create folder static and media under the project folder;
Modify settings.py to add STATIC_ROOT=os.path.join(BASE_DIR, ‘static’);
change the database settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django',
        'USER': 'root',
        'PASSWORD': 'passwd',
        'HOST': 'localhost',
    }
}

migrate the admin static file:

./manage.py collectstatic

modify the apache conf:

vi /etc/apache2/sites-enabled/000-default.conf

make it looks like:

<VirtualHost *:80>
    ServerName www.example.com
    WSGIDaemonProcess django python-path=/home/zhouanbo/django/:/home/zhouanbo/.virtualenvs/django/lib/python3.4/site-packages
    WSGIProcessGroup django
    WSGIScriptAlias / /home/zhouanbo/django/django/wsgi.py
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    Alias /robots.txt /home/zhouanbo/django/static/robots.txt
    Alias /favicon.ico /home/zhouanbo/django/static/favicon.ico
    Alias /media/ /home/zhouanbo/django/media/
    Alias /static/ /home/zhouanbo/django/static/
    <Directory /home/zhouanbo/django/static>
        Require all granted
    </Directory>
    <Directory /home/zhouanbo/django/media>
        Require all granted
    </Directory>
    <Directory /home/zhouanbo/django/ideas>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

restart the apache service:

service apache2 restart

and django should be good to go.



Leave a Reply

Your email address will not be published. Required fields are marked *