Setup enivornment for new django application

Copying this entire config into an ssh window on a linux host will create all the necessary scaffolding to run a django 1.4 site on apache2 using wsgi and create the necessary database and user.

akonkol
May 11, 2012






#linux commands


cd /var/www
mkdir %{fqdn}%

cd %{fqdn}%
mkdir logs

django-admin.py startproject %{project_name}%
cd %{project_name}%
python manage.py startapp %{app_name}%

mkdir media
mkdir admin-media
mkdir static


cd /etc/apache2/sites-available/

echo "
<VirtualHost *:80>
        ServerAdmin %{admin_email}%
        ServerName  %{fqdn}%
        ServerAlias %{fqdn}%

        # Indexes + Directory Root.
        DocumentRoot /var/www/%{fqdn}%/%{project_name}%/

        ErrorLog  /var/www/%{fqdn}%/logs/error.log
        CustomLog /var/www/%{fqdn}%/logs/access.log combined

Alias /robots.txt /var/www/%{fqdn}%/hatch/media/robots.txt
Alias /media/ /var/www/%{fqdn}%/hatch/media/
Alias /admin-media/ /var/www/%{fqdn}%/%{project_name}%/admin-media/


WSGIScriptAlias / /var/www/%{fqdn}%/%{project_name}%/%{fqdn}%.wsgi
WSGIDaemonProcess %{project_name}% user=www-data group=www-data processes=1 threads=10
WSGIProcessGroup %{project_name}%

</VirtualHost>

" > %{fqdn}%

echo "
import sys
import os

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
os.environ['DJANGO_SETTINGS_MODULE'] = '%{project_name}%.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()


" > /var/www/%{fqdn}%/%{project_name}%/%{fqdn}%.wsgi

a2ensite %{fqdn}%
/etc/init.d/apache2 reload


#create mysql db and user
mysql --user="root" -p'%{database_root_password}%'
CREATE DATABASE %{project_name}%_db;
CREATE USER '%{project_name}%_app'@'localhost' IDENTIFIED BY '%{db_password_for_new_db_user}%';
GRANT ALL ON %{project_name}%_db.* TO '%{project_name}%_app'@'localhost';
exit