Tuesday, November 06, 2012

Stackato

wget http://downloads.activestate.com/stackato/vm/v2.4.3/stackato-vm-vbox-v2.4.3.zip
unzip stackato-vm-vbox-v2.4.3.zip
cd Stackato-VM
VBoxManage import Stackato-v2.4.3.ovf
VBoxManage modifyvm Stackato-v2.4.3 --nic1 bridged --bridgeadapter1 eth0
VBoxManage startvm Stackato-v2.4.3 --type headless
To figure out the ip
# scan port 22
nmap -p 22 --open -sV 192.168.X.0/24
VBoxManage showvminfo Stackato-v2.4.3 | grep MAC
# OUTPUT IS: NIC 1:           MAC: 080027656420, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny
arp -an | grep -i 08:00:27:65:64:20 
Install stackato client
wget http://downloads.activestate.com/stackato/client/v1.5/stackato-1.5-linux-glibc2.3-x86_64.zip
unzip stackato-1.5-linux-glibc2.3-x86_64.zip 
cd stackato-1.5-linux-glibc2.3-x86_64/
sudo mv stackato /usr/local/bin/.
stackato

Saturday, March 31, 2012

ISPConfig 3.0.4.3 with Django 1.4, Virtualenv and WSGI on Debian Squeeze

I recently go a killer deal on a VPS at http://chicagovps.net/ so I am moving all my stuff from my Webfaction and Linode to my own VPS. I want something to easily manage my apache configs, dns and mail still and have used ISPConfig in the past and found it pretty good for a free open source program. I actually like it better than cPanel or DirectAdmin which I find too restrictive.

Moving my Django projects from Webfaction will take a bit of work. ISPConfig has some nice options in the GUI for PHP but the Python option uses mod_python :(.

This will not be a complete guide but as usual some documentation for myself. It assumes that ISPConfig is already setup and working, there is an decent setup guide in docs/INSTALL_DEBIAN_6.0_courier_mydns.txt and some older but still useable docs here http://www.howtoforge.com/perfect-server-debian-lenny-ispconfig3.

First you need to install some additional packages
apt-get install python-setuptools libapache2-mod-wsgi python-dev -y
easy_install pip
pip install virtualenv

Then you need to setup your site in ISPConfig and copy your Django project to it or start a new one. For simplicity we will just create a new one here
cd /var/www/mysite.com/
virtualenv myproject-env
. /myproject-env/bin/activate
pip install mysql-python
pip install PIL
pip install django
django startproject myproject
This will create a wsgi.py file in myproject/myproject/wsgi.py

Then in your ISPConfig Site go to Sites > Website > mysite.com > Options and in the Apache Directive add the following. Make sure to change the path to the correct absolute path.
Alias /media/ /var/www/clients/client0/web1/myproject/myproject/media/
Alias /static/ /var/www/clients/client0/web1/myproject/myproject/static/

Alias /robots.txt /var/www/clients/client0/web1/myproject/myproject/static/robots.txt
Alias /favicon.ico /var/www/clients/client0/web1/myproject/myproject/static/images/favicon.ico
 

WSGIDaemonProcess mysite.com user=web1 group=client0 python-path=/var/www/clients/client0/web1:/var/www/clients/client0/web1/myproject-env/lib/python2.6/site-packages
WSGIProcessGroup mysite.com
WSGIScriptAlias / /var/www/clients/client0/web1/myproject/myproject/wsgi.py
<Directory /var/www/clients/client0/web1/myproject>
Order deny,allow
Allow from all
</Directory>
<Directory /var/www/clients/client0/web1/myproject>
Order deny,allow
Allow from all
</Directory>

<Directory /var/www/clients/client0/web1/myproject>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
This assumes that STATIC_URL STATIC_ROOT MEDIA_URL and MEDIA_ROOT are set to /static/ and /media/ in myproject/myproject
# Django settings for myproject project.
import os

# Add this near the top
PROJECT_DIR = os.path.abspath(os.path. dirname(__file__))

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = PROJECT_DIR + '/media'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = PROJECT_DIR + '/static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

That should be it.  Make sure that user web1 and group client0 are the owners of the correct directories and files and have exec permission.